Closed (won't fix)
Project:
Content Construction Kit (CCK)
Version:
4.7.x-1.x-dev
Component:
content.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
31 Jul 2006 at 18:37 UTC
Updated:
21 Dec 2006 at 10:26 UTC
Jump to comment: Most recent file
Comments
Comment #1
jonathan_hunt commentedUsing // $Id: content.module,v 1.56.2.5 2006/08/04 13:47:50 JonBob Exp $
I just tested this by adding the hello_world function to a CCK content type but I get a fatal error:
Fatal error: Cannot redeclare hello_world() (previously declared in /home/jonathan/public_html/drupal47/includes/common.inc(1150) : eval()'d code:4) in /home/jonathan/public_html/drupal47/includes/common.inc(1150) : eval()'d code on line 6
Comment #2
jonathan_hunt commented@jredding: Note that '-' is not a valid character for PHP function names (refer http://nz.php.net/manual/en/language.functions.php ). But I still get a fatal error when the function is named correctly... (see previous comment).
Comment #3
killes@www.drop.org commentedcan confirm this. Probably the code gets evaluated twice.
Comment #4
jredding commentedSorry about my sloppy example I was just typing up something quick. Like you said even if named correctly the bug is still present.
Any ideas? When I get some spare time I'll try to track this down..
Any suggestions on where to look?
Comment #5
jredding commentedwhoops, didn't mean to change the title.. my fault.
Comment #6
johnalbinThis may be a core bug. I don't have CCK installed, but when I enable nodewords and put a function in a "page" content, I get the same error as you are describing.
I don't know what API is causing drupal_eval() to being called twice, but here's screenshots of the PHP stack during the two calls. Hopefully it will help someone.
Comment #7
RayZ commentedChanging title back.
Comment #8
nevets commentedThis is likely do to the fact that the node gets processed twice, once for the teaser and once for the body. I get around it by setting the teaser to a text message.
Comment #9
karens commentedI ran into this and reported it somewhere else, but I've lost track of where. It's because each field is evaluated at least twice, once by the field module and once by the content module. This is because the content module has to have a crack at the field info, too, so I don't think the fact that the field is massaged twice is a bug exactly. And it's possible that it gets massaged more than twice (the widget may have a shot at it too, maybe others).
My immediate workaround was to wrap any functions with if (!function_exists('myfunction'). The only other way to fix it is somehow to figure out exactly which pass through the field should trigger the eval, instead of evaling on every pass, but I'm not sure which would be the right time to do that. It might be easier just to check for function_exists.
Comment #10
joeguru commentedThis isn't just happening with the CCK, and it's taking recently-upgraded sites pretty much down if they embed php code. I'm following up on the teaser re-eval theory.
Comment #11
dopry commentedI'm setting this to won't fix.... You have to be careful when declaring functions in nodes... I would even go so far as to say you should never do that... You should also be careful that you paste bug free code into nodes.
Comment #12
dman commentedthis is not a bug, just a result of the PHP language scoping.
PHP would always do that if you included the same library more than once.
It's been a side-effect of all versions of Drupal that allow multiple evaluations of embedded code that are odd enough to try and declare functions inside an eval() context.
try not to do that, or if you must, protect yourself with
But really, seriously, don't try making code that way.