Req #49100 [Opn->Wfx]: Reference of native function in variable (function pointers)

From: Date: Thu, 21 Oct 2021 12:02:55 +0000
Subject: Req #49100 [Opn->Wfx]: Reference of native function in variable (function pointers)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237319@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=49100&edit=1 ID: 49100 Updated by: cmb@php.net Reported by: tom at r dot je Summary: Reference of native function in variable (function pointers) -Status: Open +Status: Wont fix Type: Feature/Change Request Package: Scripting Engine problem Operating System: * PHP Version: * -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: You can already do this with uopz[1] and runkit7[2], and it is highly unlikely that such functionality will ever make it into the core. > It's really useful for debugging, as a function can be > substituted easily. I suggest to use a debugger. [1] <https://pecl.php.net/package/uopz> [2] <https://pecl.php.net/package/runkit7> Previous Comments: ------------------------------------------------------------------------ [2009-07-29 14:58:35] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=49100&edit=1

« previous php.bugs (#237319) next »