Php bind variable to function's scope in older PHP?

You can use a global variable, but you should always avoid globals variables whereever possible. As a suggestion, without knowing, what you are trying to solve with this class Xy ( { private $test; public function __construct ($test) { $this->test = $test; } public function call ($el) { return $el * $this->test; } } print_r(array_map(array(new Xy(2), 'call'), array(3)) Also possible are the good old lambdas $test = 2; $a = create_function ('$el', 'return $el * ' . $test .';'); print_r (array_map($a, array(3))).

You can use a global variable, but you should always avoid globals variables whereever possible. As a suggestion, without knowing, what you are trying to solve with this class Xy ( { private $test; public function __construct ($test) { $this->test = $test; } public function call ($el) { return $el * $this->test; } } print_r(array_map(array(new Xy(2), 'call'), array(3)); Also possible are the good old lambdas $test = 2; $a = create_function ('$el', 'return $el * ' . $test .';'); print_r (array_map($a, array(3))).

Normally through globals, seriously. Although hacks could be used to mimic the functionality, like partial functions in php. Extracted from article: function partial() { if(!class_exists('partial')) { class partial{ var $values = array(); var $func; function partial($func, $args) { $this->values = $args; $this->func = $func; } function method() { $args = func_get_args(); return call_user_func_array($this->func, array_merge($args, $this->values)); } } } //assume $0 is funcname, $1-$x is partial values $args = func_get_args(); $func = $args0; $p = new partial($func, array_slice($args,1)); return array($p, 'method'); } And only after that could you have something like.

Function multiply_by($base, $value) { return $base * $value; } // ... $res = array_map(partial("multiply_by", $test), array(3)); Not... worth... it.

PHP supports the concept of variable functions. To, and will attempt to execute it. Be used to implement callbacks, function tables, and so forth.

Require and the like. Use of any of these constructs as variable functions. Object methods can also be called with the variable functions syntax.

Variable variables and function_exists().

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions