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

From: Date: Sun, 26 Jul 2009 01:23:03 +0000
Subject: #49060 [Opn]: require_last - for terminating code that must be executed after all includes.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-140256@lists.php.net to get a copy of this message
ID: 49060 User updated by: mccarre at uwindsor dot ca Reported By: mccarre at uwindsor dot ca Status: Open Bug Type: Feature/Change Request Operating System: Mac OS X PHP Version: 5.2.10 New Comment: "Because files are included at run time where the instruction is located, it may not ever be evaluated." Sorry I could have made this much more understandable by adding to it. Rephrasing I would say: "Because files are included at run time where the instruction is located, it may not ever be evaluated; for example if a function is called that exits the script." That should give a better idea of the complication I find with includes that causes my code road bump, which causes me to make this request. Previous Comments: ------------------------------------------------------------------------ [2009-07-26 01:19:06] mccarre at uwindsor dot ca 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 this bug report at http://bugs.php.net/?id=49060&edit=1

« previous php.bugs (#140256) next »