Bug #68075 [NEW]: Functions defined in closures may not be called before definition
| From: | fieryprophet at yahoo dot com | Date: | Mon, 22 Sep 2014 17:26:48 +0000 |
| Subject: | Bug #68075 [NEW]: Functions defined in closures may not be called before definition | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-187662@lists.php.net to get a copy of this message | ||
From: fieryprophet at yahoo dot com
Operating system: All
PHP version: Irrelevant
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Functions defined in closures may not be called before definition
Description:
------------
PHP allows calls to functions that have not yet been defined as long as
they are defined at some point in the script.
However, this behavior is not consistent when applied to Closures, as
function calls within a closure will fail if they are not defined before
they are made even if the function definition is contained within the
same closure.
If the function in question is defined outside of a closure but after
the closure is created, the script will also proceed as expected.
Test script:
---------------
test();
function test(){
echo "Test works\r\n";
}
//output: Test works
$closure = function(){
closure_test();
function closure_test(){
echo "Closure test works\r\n";
}
};
$closure();
//expected output: Closure test works
//actual output: Fatal error: Call to undefined function closure_test()
Expected result:
----------------
Test works
Closure test works
Actual result:
--------------
Test works
Fatal error: Call to undefined function closure_test()
--
Edit bug report at https://bugs.php.net/bug.php?id=68075&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68075&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68075&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68075&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68075&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68075&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68075&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68075&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68075&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68075&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68075&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68075&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68075&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68075&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68075&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68075&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68075&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68075&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68075&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68075&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68075&r=mysqlcfg