php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37915 __FUNCTION__ does not work inside create_function
Submitted: 2006-06-26 11:56 UTC Modified: 2006-06-26 12:07 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: jexus at jexus dot net Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 5.1.4 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-06-26 11:56 UTC] jexus at jexus dot net
Description:
------------
I was trying to create a recursive function with create_function, but I found a weird problem. When I used the magic constant __FUNCTION__, it returned 'lambda_func', instead of 'lambda_1', the actual result create_function returned.

Reproduce code:
---------------
<?php
$func = create_function (
    '$a',
    'return is_array ($a)' . "\n" .
    '    ? array_map (__FUNCTION__, $a)' . "\n" .
    '    : (is_object ($a)' . "\n" .
    '       ? (object) array_map (__FUNCTION__, (array) $object)' . "\n" .
    '       : (is_string ($a)' . "\n" .
    '           ? htmlspecialchars (str_replace ("\n", \'\n\', $a))' . "\n" .
    '           : $a));'
);

var_dump ($func ('string_var', array ('array_var', 'another_var')));
?>


Expected result:
----------------
array(2) {
  [0]=>
  string(9) "array_var"
  [1]=>
  string(11) "another_var"
}

Actual result:
--------------
Warning: array_map(): The first argument, '__lambda_func', should be either NULL or a valid callback in /home/jexus/public_html/test/test.php(22) : runtime-created function on line 2
NULL 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-26 12:07 UTC] tony2001@php.net
Constant __FUNCTION__ is resolved during compile time, while lambda functions are created in runtime, so the constant value is correct.
I don't think anybody is going to change it ever.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 06:01:29 2024 UTC