Forum Moderators: coopster

Message Too Old, No Replies

Function placement

         

Sarah Atkinson

3:03 pm on May 24, 2005 (gmt 0)

10+ Year Member



Do defined functions have to be placed at the top of the page or just before the point they are called from?

cputek2k

3:22 pm on May 24, 2005 (gmt 0)

10+ Year Member



I have placed functions at after the call and it worked fine...

DaiWelsh

4:25 pm on May 24, 2005 (gmt 0)

10+ Year Member



Neither, PHP interprets the full script before it runs it so it will cope quite happily if the function call is at the top and the function definition at the bottom.

jatar_k

4:34 pm on May 24, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld DaiWelsh

coopster

10:25 pm on May 26, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes, welcome, but be cautious there...

In PHP 3, functions must be defined before they are referenced. No such requirement exists since PHP 4. Except when a function is conditionally defined [...] When a function is defined in a conditional manner [...] Its definition must be processed prior to being called.

[us2.php.net...]