note 116800 added to language.oop5
| From: | 0x174 | Date: | Mon, 02 Mar 2015 14:58:18 +0000 |
| Subject: | note 116800 added to language.oop5 | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201837@lists.php.net to get a copy of this message | ||
A little trick for create an anonymous object (exactly an half-anonymous object :D aka
"_") who can handle methods.
<?php
class _
{
public function __construct( array $cfg){
foreach($cfg as $k=>$v){
$this->{$k}=$v;
}
}
public function __call( $fn, array $args){
if(isset($this->{$fn})){
array_unshift($args, $this);
call_user_func_array( $this->{$fn}, $args);
}
}
}
$o = new _(array(
"color"=>"red",
"run"=>function($this){
echo "My color is : ".$this->color;
}
));
$o->run();
?>
----
Server IP: 72.52.91.14
Probable Submitter: 79.174.228.19
----
Manual Page -- http://php.net/manual/en/language.oop5.php
Edit -- https://master.php.net/note/edit/116800
Del: integrated -- https://master.php.net/note/delete/116800/integrated
Del: useless -- https://master.php.net/note/delete/116800/useless
Del: bad code -- https://master.php.net/note/delete/116800/bad+code
Del: spam -- https://master.php.net/note/delete/116800/spam
Del: non-english -- https://master.php.net/note/delete/116800/non-english
Del: in docs -- https://master.php.net/note/delete/116800/in+docs
Del: other reasons-- https://master.php.net/note/delete/116800
Reject -- https://master.php.net/note/reject/116800
Search -- https://master.php.net/manage/user-notes.php