Voting

Please answer this simple SPAM challenge: six minus zero?
(Example: nine)

The Note You're Voting On

0x174[d0t]14[at]gmail[d0t]com
2 years ago
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();

?>

<< Back to user notes page

To Top