Edit report at http://bugs.php.net/bug.php?id=49060&edit=1

 ID:                 49060
 Updated by:         [email protected]
 Reported by:        mccarre at uwindsor dot ca
 Summary:            require_last - for terminating code that must be
                     executed after all includes.
-Status:             Open
+Status:             Bogus
 Type:               Feature/Change Request
-Package:            Feature/Change Request
+Package:            *General Issues
 Operating System:   Mac OS X
 PHP Version:        5.2.10
 Block user comment: N
 Private report:     N

 New Comment:

As requester himself figured out, not implementable.


Previous Comments:
------------------------------------------------------------------------
[2009-07-26 01:37:31] mccarre at uwindsor dot ca

Hmmm on further through PHP could never achieve this with the way it
works. It wouldn't make sense with an iterative scripting language.



The only possible generic function solution would require two functions.
One to tell the function to ignore all other requests for the file, and
then another to finally include the file. If you didn't have that second
function you would have no idea when to include the file!



I saw a bug when I was posting this about symbolic includes. What I
implied from that bug was an included file that didn't execute the code
it had. If that was introduced, then people could use those for all
files they didn't care about executing code with, then use include for
code they wanted to be executed. That is the most elegant solution I can
think of right now.



I suppose in that case my feature request would be to have an include
that doesn't execute code, and is evaluated first before any other
code.



(on further inspection that guys bug was about symbolically loading the
functions of a file on include. According to everyone's comments PHP
already does this. What I want is for that pesky loose code not to be
executed if I tell it not to, by including it in a special way. This
special way would could be called import perhaps.))

------------------------------------------------------------------------
[2009-07-26 01:23:03] mccarre at uwindsor dot ca

"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.)

------------------------------------------------------------------------
[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/bug.php?id=49060&edit=1

Reply via email to