note 125693 added to function.call-user-func-array

From: Date: Mon, 18 Jan 2021 21:27:49 +0000
Subject: note 125693 added to function.call-user-func-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-216189@lists.php.net to get a copy of this message
Since PHP 5.6 you can use the spread operator (argument unpacking) instead of call_user_func_array(). public function __call($name, $arguments) { if(method_exists($this->foo, $name)) return call_user_func_array(array($this->foo, $name), $arguments); //calls function from inside $this->foo else throw new BadMethodCallException('Call to undefined method ' . static::class . "::$name()", 0); //the method does not exist on $this->foo } is the same as public function __call($name, $arguments) { if(method_exists($this->foo, $name)) return $this->foo->$name(...$arguments); //calls function from inside $this->foo else throw new BadMethodCallException('Call to undefined method ' . static::class . "::$name()", 0); //the method does not exist on $this->foo } ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.159.166 (proxied: 82.60.22.178) ---- Manual Page -- http://php.net/manual/en/function.call-user-func-array.php Edit -- https://master.php.net/note/edit/125693 Del: integrated -- https://master.php.net/note/delete/125693/integrated Del: useless -- https://master.php.net/note/delete/125693/useless Del: bad code -- https://master.php.net/note/delete/125693/bad+code Del: spam -- https://master.php.net/note/delete/125693/spam Del: non-english -- https://master.php.net/note/delete/125693/non-english Del: in docs -- https://master.php.net/note/delete/125693/in+docs Del: other reasons-- https://master.php.net/note/delete/125693 Reject -- https://master.php.net/note/reject/125693 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#216189) next »