php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #49100 Reference of native function in variable (function pointers)
Submitted: 2009-07-29 14:58 UTC Modified: 2011-01-01 22:50 UTC
Votes:4
Avg. Score:2.0 ± 1.7
Reproduced:2 of 3 (66.7%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: tom at r dot je Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: * OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-07-29 14:58 UTC] tom at r dot je
Description:
------------
With the intorduction of closures it would be nice to be able to have some control over native functions for example:


$foo = function() { 
echo 'bar';
}

$foo();

Works fine. 


It would be nice to be able to do something like

function foo() {
echo 'bar';
}

$foo = &foo;
$foo();

And ultimately, override the defined function:

function foo() {
echo 'bar';
}

$oldFoo = &foo;
foo = function() use ($oldFoo) {
   $oldFoo();
   echo 'bar';
}


foo(); // will print 'foobar';

There are several uses for this, just look at the way closures are commonly used in javascript. It's really useful for debugging, as a function can be substituted easily.

Though this probably isn't possible due to the clear distinction php makes between functions and variables. 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-01 22:50 UTC] jani@php.net
-Summary: Reference Native Function in variable (function pointers) +Summary: Reference of native function in variable (function pointers) -Package: Feature/Change Request +Package: Scripting Engine problem -Operating System: Windows Vista +Operating System: * -PHP Version: 5.3.0 +PHP Version: *
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Dec 14 18:01:24 2019 UTC