Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ghosting PHP functions like in Javascript

Tags:

javascript

php

Original Question

Since a recent version of php added anonymous functions, is there a way to extend functions? in Javascript I'd do:

var temp = immaFunction;
immaFunction = function(){
  //do some random stuff
  temp.apply(this, arguments);
}

Result

As of 5.3, PHP has first class anonymous functions.
A few points to consider however(will be filling this with more as I mess around with it.):

  • You must import any external variables you want to use. (Example 1)

Examples

Example 1:

$foo = "bar";
$fooBar = function() use ($foo){
  echo $foo;
}
$fooBar(); //bar
like image 954
Rixius Avatar asked Feb 13 '26 23:02

Rixius


1 Answers

PHP 5.3 supports that link

like image 192
Iznogood Avatar answered Feb 15 '26 13:02

Iznogood



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!