php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #10171 calling function before it is defined only works in same file
Submitted: 2001-04-04 19:05 UTC Modified: 2001-04-05 15:37 UTC
From: aboyd at ssti dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.0.4pl1 OS: Windows NT 4 sp 5 & Solaris 8
Private report: No CVE-ID: None
 [2001-04-04 19:05 UTC] aboyd at ssti dot com
Define a function.  Put a call to that function BEFORE it is defined.  That works, as documented.  Now put the function in an include()'d or require()'d file.  Call the function before the include() or require().  It fails.

Since the code is pre-compiled beforehand, shouldn't the function calls still work?  If this is "as designed" it might be nice to place a caveat in the documentation that states "you can call a function before you define it ONLY if the function isn't buried in an include()."

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-04-05 05:03 UTC] cynic@php.net
problem here is that include()s & require()s are runtime thingies. I got bitten by this just yesterday: if you e. g. redeclare a function in a require()d file, the 'fatal error: function redeclaration...' does appear, but at runtime, not during compilation.

Anyway, this is what Andi told me on the subject:

The main reason [require() was changed to happen at run time rather than at compile time] was that it was supposed to improve performance and it didn't. It actually tended to slow things down.
Removing this also allowed us to reduce the memory usage of PHP scripts (not as important).
(...)
It really sucked and we managed to clean up some code and internals due to taking it out. I wouldn't want to put it back in.

So, this is by design. -> docuprob
 [2001-04-05 15:37 UTC] aboyd at ssti dot com
Thanks for the info from Andi and cynic.  The reason this feature is so nice is because I have a wrapper that pulls in whatever Web page is being viewed.  The wrapper needs to change its headers on the fly, depending on page contents.  I wanted to use the functions as a signal of some sort -- the page content telling the wrapper, "send this header".  I can't do this if I can't call functions in included files.

So if includes and requires don't work out, I hope the gang comes up with some way for different bits of code to message each other.

In any case, I've added a note to the documentation, so I think the documentation end of things is now fixed.  I'll close this bug.  Thanks!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 00:01:28 2024 UTC