php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31822 __FUNCTION__ magic constant doesn't work in eval()
Submitted: 2005-02-03 00:35 UTC Modified: 2005-02-03 18:46 UTC
From: clewis at myfonts dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.3 OS: RedHat Enterprise 3
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: clewis at myfonts dot com
New email:
PHP Version: OS:

 

 [2005-02-03 00:35 UTC] clewis at myfonts dot com
Description:
------------
The __FUNCTION__ magic constant returns nothing when used in eval()'d code.  __FILE__ and __LINE__ work as expected.

Reproduce code:
---------------
<?php 

function whatFunctionAmI()
{
	eval("print 'the function is: ' . __FUNCTION__;");
}

whatFunctionAmI();

?>

Expected result:
----------------
the function is: whatFunctionAmI

Actual result:
--------------
the function is: 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-03 17:21 UTC] helly@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

In your example there is no function in your eval\'d code.
 [2005-02-03 18:46 UTC] clewis at myfonts dot com
I see.  I thought the eval() was run in the current 
context, but in fact it runs in its own completely 
separate PHP context?  But that doesn't make sense since 
you can make variable assignments etc within the eval().  
It seems if one can make use of pre-existing variables 
within the eval, it should also know it's inside a 
function.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 20:01:34 2025 UTC