php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36370 __FUNCTION__ doesn't persist into include files
Submitted: 2006-02-12 04:03 UTC Modified: 2006-02-12 21:49 UTC
From: rbro at hotmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.1.2 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: rbro at hotmail dot com
New email:
PHP Version: OS:

 

 [2006-02-12 04:03 UTC] rbro at hotmail dot com
Description:
------------
If you include a file within a function, the constant __FUNCTION__ is not available from that include file.


Reproduce code:
---------------
<?php
function test()
{
    echo "1. Function is: ".__FUNCTION__."\n";
    require('b.php');
}

test();
?>

-------

File b.php contains:

<?php
echo "2. Function is: ".__FUNCTION__."\n";
?>


Expected result:
----------------
1. Function is: test
2. Function is: test


Actual result:
--------------
1. Function is: test
2. Function is:


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-12 14:22 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

. 
 [2006-02-12 16:51 UTC] rbro at hotmail dot com
Thanks for the update, but why is this not a bug?  I did look at the documentation before submitting this bug and http://us3.php.net/include states the following:

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

which then contradicts the Actual Result that I'm getting because if I move my included code into the main file, then the output is different:

1. Function is: test
2. Function is: test
 [2006-02-12 21:32 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

__FUNCTION__ is something handled by the parser, and not the executor. This means that it has no knowlegde where it was included from and as the __FUNCTION__ appears outside of a function declaration it ofcourse returns NULL.
 [2006-02-12 21:49 UTC] rbro at hotmail dot com
Thanks for the explanation.  I'm thinking that maybe the documentation for include() should be updated since right now it states "all of the code contained in the called file will behave as though it had been defined inside that function" which is not true if you use __FUNCTION__ inside your included file which is the exact issue I ran into in my code.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 13 21:01:31 2024 UTC