#49060 [NEW]: require_last - for terminating code that must be executed after all includes.

From: Date: Sun, 26 Jul 2009 01:19:07 +0000
Subject: #49060 [NEW]: require_last - for terminating code that must be executed after all includes.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-140255@lists.php.net to get a copy of this message
From: mccarre at uwindsor dot ca Operating system: Mac OS X PHP version: 5.2.10 PHP Bug Type: Feature/Change Request Bug description: require_last - for terminating code that must be executed after all includes. Description: ------------ Because files are included at run time where the instruction is located, it may not ever be evaluated. This is to be expected. However, this creates a problem with code that may call a function that is in one of the preceding included files. You generally want to call that function LAST, only after you've included all other files. (This is for nested include relations) The only scenario I have found this relevant thus far is calling php functions using AJAX. Reproduce code: --------------- --- From manual page: function.include-once --- I'll provide a simple example, because the one I came upon is too large. Imagine you have fileA.php: <?php include_once "fileB.php"; include_once "fileC.php"; include_once "callA.php"; //when fileB.php includes callA.php and callA calls fncA and it tries to call fncC, although fncC is in this files includes list, that line has yet to be executed, therefor it will not be able to find the function. If you could include_last "callA.php", then the first include_last "callA.php" in fileB.php would be ignored, and the callA.php in fileA.php would be included after fileC.php is included. =) function fncA() { fncC(); } ?> You normally wouldn't do the following, but if there was generic code to call an AJAX function here it would do this. fileB.php: <?php //reminder that include_once "fileC.php"; hasn't been executed yet. include_once "callA.php"; ?> fileC.php: <?php fncC(){ print "hello"; } ?> callA.php: <?php fncA(); ?> I posted another example in the comments of include_once. Expected result: ---------------- function not found. Actual result: -------------- with include_last, the function will be called and "hello" would be printed. -- Edit bug report at http://bugs.php.net/?id=49060&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49060&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49060&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49060&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=49060&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49060&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=49060&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=49060&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=49060&r=needscript Try newer version: http://bugs.php.net/fix.php?id=49060&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=49060&r=support Expected behavior: http://bugs.php.net/fix.php?id=49060&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=49060&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=49060&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=49060&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49060&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=49060&r=dst IIS Stability: http://bugs.php.net/fix.php?id=49060&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=49060&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=49060&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=49060&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=49060&r=mysqlcfg

« previous php.bugs (#140255) next »