note 21149 deleted from language.functions by felipe

From: Date: Tue, 22 Jul 2008 19:07:53 +0000
Subject: note 21149 deleted from language.functions by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142551@lists.php.net to get a copy of this message
Note Submitter: bishop ---- The documentation statement: "In PHP 3, functions must be defined before they are referenced. No such requirement exists in PHP 4." is not entirely accurate (or at least misleading). Consider: function a() { function b() { echo 'I am b'; } echo 'I am a'; } You MUST call a() before you can even think about using b(). Why? The parser hasn't touched the scope inside function a (for efficiency reasons), so b has yet to be defined or even *declared*. The documentation (I believe) refers to this behaviour: a(); function a() { echo 'I am a'; } which is perfectly valid and runs as you probably expect. However, the following does not work as expected (or documented): function a() { b(); function b() { echo 'I am b'; } echo 'I am a'; } a(); Rather than getting "I am b" followed by "I am a" you get a parse error ("Call to undefined function b()"). So, the bottom line: Gewaehrleistungsausschluss

« previous php.notes (#142551) next »