#37776 [Opn]: position of define() in source matters

From: Date: Sat, 10 Jun 2006 23:27:17 +0000
Subject: #37776 [Opn]: position of define() in source matters
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969373252@lists.php.net to get a copy of this message
ID: 37776 Updated by: brianlmoon@php.net Reported By: karibu at gmx dot net Status: Open Bug Type: Documentation problem Operating System: MacOS X, MorphOS PHP Version: Irrelevant New Comment: Would you expect this to work different somehow? <?php printfoobar(); exit; $FOO = 'bar'); function printfoobar() { echo $GLOBALS["FOO"]; } ?> I would not. Not only did you call the function before the define, but you exit() before the define. There is no way that is getting defined. Previous Comments: ------------------------------------------------------------------------ [2006-06-10 23:12:17] karibu at gmx dot net Description: ------------ When I *call* a function which uses a define before this define is actually defined in the source it appears in the function to be undefined. I didn't found this behavoir documented (not in the english or german section) but it would probably very useful as it quickly can lead to unexpected problems w/o instantly possible to detect why (in a script of mine it caused busylooping f.ex.). Reproduce code: --------------- <?php printfoobar(); exit; define(FOO, 'bar'); function printfoobar() { echo FOO; } ?> Expected result: ---------------- bar Actual result: -------------- FOO ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=37776&edit=1

« previous php.doc (#969373252) next »