php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #41487 Clarification of _FUNCTION_ behaviour inside an include
Submitted: 2007-05-24 10:42 UTC Modified: 2007-08-17 08:10 UTC
From: tayloj1 at uk dot ibm dot com Assigned: ezyang (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tayloj1 at uk dot ibm dot com
New email:
PHP Version: OS:

 

 [2007-05-24 10:42 UTC] tayloj1 at uk dot ibm dot com
Description:
------------
Occurrences of __FUNCTION__ inside an include inside a function declaration do not behave as documented.

The statement: 
    "If the include occurs inside a function within the calling file, then all of the code contained in the called file will behave as though it had been defined inside that function."

is not accurate if the "the code contained in the called file" involves occurrences of __FUNCTION__  .

Additional text should be added : 

   "An exception to this is the _FUNCTION_ magic constant, which is evaluated before the include occurs."

For more details see http://bugs.php.net/bug.php?id=36370, where this was raised as a functional issue but was closed as bogus.
As the raiser states, at least the documentation should be fixed.



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-24 13:44 UTC] tayloj1 at uk dot ibm dot com
The doc text which needs clarification is in the description of include(), after the first example box (example 16.5) 

     http://uk.php.net/include/
 [2007-05-26 13:25 UTC] ezyang@php.net
I've generalized the issue to note that it applies to all magic constants, not just __FUNCTION__ (although, in practice, people will get confused about __FUNCTION__)

Patch:

Index: en/language/control-structures.xml
===================================================================
RCS file: /repository/phpdoc/en/language/control-structures.xml,v
retrieving revision 1.138
diff -u -r1.138 control-structures.xml
--- en/language/control-structures.xml	7 May 2007 09:33:54 -0000	1.138
+++ en/language/control-structures.xml	26 May 2007 13:23:26 -0000
@@ -1350,7 +1350,9 @@
      If the include occurs inside a function within the calling file,
      then all of the code contained in the called file will behave as
      though it had been defined inside that function.  So, it will follow
-     the variable scope of that function.
+     the variable scope of that function. An exception to this rule is the 
+     magic constant (especially _FUNCTION_), which are evaluated by the
+     parser before the include occurs.
    </simpara>
    <para>
      <example>

 [2007-08-17 08:10 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"An exception to this rule are magic constants which are evaluated by the parser before the include occurs."
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Nov 19 01:00:01 2025 UTC