Phantom php functions like in javascript

Original question

Since anonymous functions are added in the latest php version, is there any way to extend the functions? in javascript i would do:

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

Result

Starting with 5.3, PHP has anonymous first-class functions.
However, a few points to keep in mind (will fill it up more when I argue with him.):

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

Examples

Example 1:

$foo = "bar";
$fooBar = function() use ($foo){
  echo $foo;
}
$fooBar(); //bar
+3
source share
2 answers

PHP 5.3 supports this link

+3
source
0

Source: https://habr.com/ru/post/1760632/


All Articles