1

I'm cleaning up a Drupal 7 site and currently its spitting out a bunch of PHP syntax errors pointing to some block that is causing it. It doesn't say which block but only says php_eval() error. So I'm assuming its in a block somewhere.

How would one find the culprit of which block it is that is causing this php error?

https://i.sstatic.net/WSJXM.png

enter image description here

4

2 Answers 2

1

It appears to be an error in the php code in some of the blocks. There in no direct way to find out which block is causing the error. But you can find the ids of the blocks inside that page which contains php code by adding the following patch inside modules/block/block.module, just for debugging.

diff --git a/modules/block/block.module b/modules/block/block.module
index 48c80d7..d25a497 100644
--- a/modules/block/block.module
+++ b/modules/block/block.module
@@ -243,6 +243,9 @@ function block_block_view($delta = '') {
   $block = db_query('SELECT body, format FROM {block_custom} WHERE bid = :bid',
   $data['subject'] = NULL;
   $data['content'] = check_markup($block->body, $block->format, '', TRUE);
+  if (strpos($block->format, 'php')) {
+    echo "<pre>"; print_r($delta, TRUE); echo "</pre>";
+  }
   return $data;
 }

EDIT: Please note, the above code is just for debugging purpose and not meant to be commited. As Molot said on comment, Never Hack Core

4
  • Never hack core
    – Mołot
    Commented Sep 3, 2015 at 9:07
  • @Mołot It is just for debugging purpose. Commented Sep 3, 2015 at 10:33
  • There always are excuses for bad practices. This doesn't make them any better. Neither does it help future maintainers...
    – Mołot
    Commented Sep 3, 2015 at 10:43
  • @Mołot, you got me wrong. The above code was not meant to be committed. It is just for debugging current situation. I have edited my answer. Can you please check? Commented Sep 3, 2015 at 11:02
3

The most probable cause of the error is a missing or a mismatched parenthesis in the PHP code you are using in your custom blocks or functions. To solve the missing parenthesis error in PHP blocks or in other areas, the code has to be checked from the beginning to search for it. But it's really hard to check all PHP code. One way to avoid errors is to use proper indentation in the code. Once all the parentheses in the code have been set correctly, parse error: syntax error, unexpected $end will be fixed.

What causes this error?

In fact, this error means that PHP has finished analyzing your code, but you forgot to close a symbol somewhere in your page or in those that were included. There could be a number of causes:

  1. This issue could happen when someone used <? instead of <?php somewhere, but your server's php.ini disables short open tags. Check this line in your php.ini - "short_open_tag = On".
  2. You forgot to close a quote, so PHP is continuing to analyze your code until it finds the closing quotation mark.
  3. You forgot to close a bracket, so from the last opening, PHP considers all the code that follows as part of a block that never ends.
  4. You forgot to close a parenthesis, so from the last open parenthesis, PHP considers all the code that follows as part of a specific block (condition, arguments of functions etc) that does not end.
  5. You forgot a comma, so for PHP there is an instruction in your code that has no end.

NOTE: This means that the problem may not be on the line mentioned in the error message, as the missing symbol could be anywhere after that point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.