By monkeythug on
Does drupal evaluate PHP nodes, even when they are not being viewed?
I have an issue where I'm defining the same function name in a class on two different nodes, but I get a "function already defined" error popping up. It doesn't happen all the time, I was able to get in and disable one of the nodes.
Anybody else seen this, is it expected behaviour?
Cheers,
Dave.
Comments
I ran into a problem where I
I ran into a problem where I pretty much always got that error when defining a function in a node because a node is loaded twice (once to process the teaser, once to display the node). Back then when I asked, I was told there was no way to avoid this. I've put most of my functions in files I include with a require_once statement instead. I don't know if that's related to your problem or not.
You may want to (1) give your functions different names or (2) if they are the same function, create the function in a included file instead.
But On Different Nodes?
Hi,
Yes, I agree - it's not too difficult to get around the problem. However I'm more interested in just what Drupal is doing and why it is doing it.
The duplicate function defs seem to have exposed a behavior in Drupal which I don't understand (in that it sometimes seems to read and eval a node different to the one I am viewing). It might be related to my configuration as I've tried to reproduce it on a vanilla Drupal install, but have been unsuccessful so far.
Since no one seems to immediately recognise this as expected behaviour or anything like that, I'll keep plugging away at it for a bit and see what I can dig up.
Cheers,
Dave.
If more than one node is displayed you may have that problem
If more than one node is displayed, such as when displaying a list of nodes, if more than one of them defines the function you can expect to get an error about function redefined. In general, defining functions in a node is not a wise idea.
Feeling a bit Thick
Dammit I'm feeling a bit thick now - lists of nodes, of course - just like the og group home page on my site :-(
Oh well, missing the obvious has always been a favourite pastime of mine ;-)
Thanks for your help,
Dave.