can't use php functions in body of nodes
| Project: | Meta tags |
| Version: | 4.7.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Robrecht Jacques |
| Status: | active |
Jump to:
See: http://drupal.org/node/76437
For example, make a node with a php filtered body as:
<?php
function hello_world() {
return 'Hello world!';
}
?>
<div><?php print hello_world(); ?></div>When submitting this node or viewing it, you get the error:
Fatal error: Cannot redeclare hello_world() (previously declared in /var/www/drupal/47/drupal/includes/common.inc(1175) : eval()'d code:3) in /var/www/drupal/47/drupal/includes/common.inc(1175) : eval()'d code on line 2
This possibly has to do with the fact that nodewords calls node_prepare($node, TRUE) to get the teaser of a node if "use teaser if description is empty" is set. Somewhere this is already evaluated, giving the "can't redeclare hello_world() function" error.
Not sure if we can avoid it. Maybe it is even a core bug. But I should look into it.

#1
Fixed in 4.7.
Well, not fixed, it's a quick hack: we don't output (or generate) a DESCRIPTION meta tag for nodes that have a non-cachable input format (which is probably a PHP enabled input format). This will eliminate the error, but also eliminate the output obviously.
If someone has better ideas?
Probably this needs to be fixed in core somewhere. Core doesn't have the problem because it doesn't display trimmed down versions for PHP posts. If it would, it would see the same problem as we do.
#2
Setting it as "fixed".
If you think this is not the case, please reopen it.
#3
This is popping up all over the place in various php modules including cron.php. No included php seems to run after an upgrade from 4.6 to 4.7. I'm not sure if it is a module conflict or not. Just trying to get my site back up.
#4
Well, this is a crufty hack but it's a work-around. Wrap your functions thusly:
if (!function_exists('hello_world') {
function hello_world....
}
Also, all the scripts that are affected seem to be flexinodes.