Additions:
public static function add_method()
$args = func_get_args();
$method = array_shift( $args );
$callback = str_replace( '$this', '$self', array_pop( $args ) );
array_push( $args, '$self' );
$args = implode( ',', $args);
self::$prototype_methods[$method] = create_function( $args, $callback );
public function __construct()
if ( self::$prototype_properties ) {
$this->prototype_obj_properties = array_combine(
self::$prototype_properties,
array_fill( 0, count(self::$prototype_properties), null )
);
}
array_push( $args, $this );
return call_user_func_array( self::$prototype_methods[$method], $args );
public function __isset( $name )
return isset( $this->prototype_obj_properties[$name] );
public function __unset( $name )
unset( $this->prototype_obj_properties[$name] );
public $foobar;
Foo::add_method( 'faz', 'echo "faz()\n";' );
Foo::add_method( 'raz', 'echo $this->bar(), $this->faz(), $this->taz;' );
// taz is not set, so it is null.
$args = func_get_args();
$method = array_shift( $args );
$callback = str_replace( '$this', '$self', array_pop( $args ) );
array_push( $args, '$self' );
$args = implode( ',', $args);
self::$prototype_methods[$method] = create_function( $args, $callback );
public function __construct()
if ( self::$prototype_properties ) {
$this->prototype_obj_properties = array_combine(
self::$prototype_properties,
array_fill( 0, count(self::$prototype_properties), null )
);
}
array_push( $args, $this );
return call_user_func_array( self::$prototype_methods[$method], $args );
public function __isset( $name )
return isset( $this->prototype_obj_properties[$name] );
public function __unset( $name )
unset( $this->prototype_obj_properties[$name] );
public $foobar;
Foo::add_method( 'faz', 'echo "faz()\n";' );
Foo::add_method( 'raz', 'echo $this->bar(), $this->faz(), $this->taz;' );
// taz is not set, so it is null.
Deletions:
self::$prototype_methods[$method] = $callback;
array_unshift( $args, $this );
call_user_func_array( self::$prototype_methods[$method], $args );
Foo::add_method( 'faz', create_function( '$self', 'echo "faz()\n";' ) );
Foo::add_method( 'raz', create_function( '$self', 'echo $self->bar(), $self->faz(), $self->taz;' ) );
// taz is not set, so it it null.
Additions:
$baz->bar():
> 'bar()'
$baz->faz():
> 'faz()'
echo $baz->taz:
> 'taz'
$baz->raz():
> 'bar()'
> 'faz()'
> 'taz'
$a->raz():
> 'bar()'
> 'faz()'
>
var_dump( $a->taz ):
> NULL
> 'bar()'
$baz->faz():
> 'faz()'
echo $baz->taz:
> 'taz'
$baz->raz():
> 'bar()'
> 'faz()'
> 'taz'
$a->raz():
> 'bar()'
> 'faz()'
>
var_dump( $a->taz ):
> NULL
Deletions:
$baz->faz() > 'faz()'
echo $baz->taz > 'taz'
$baz->raz() > 'bar()'
> 'faz()'
> 'taz'
$a->raz() > 'bar()'
> 'faz()'
>
var_dump( $a->taz ) > NULL
Additions:
>
Additions:
$baz->bar() > 'bar()'
$baz->faz() > 'faz()'
echo $baz->taz > 'taz'
$baz->raz() > 'bar()'
> 'faz()'
> 'taz'
$a->raz() > 'bar()'
> 'faz()'
$baz->faz() > 'faz()'
echo $baz->taz > 'taz'
$baz->raz() > 'bar()'
> 'faz()'
> 'taz'
$a->raz() > 'bar()'
> 'faz()'
Deletions:
$baz->faz() > faz()
echo $baz->taz > taz
$baz->raz() > bar()
> faz()
> taz
$a->raz() > bar()
> faz()
Additions:
$baz->bar() > bar()
$baz->faz() > faz()
echo $baz->taz > taz
$baz->raz() > bar()
> faz()
> taz
$a->raz() > bar()
> faz()
var_dump( $a->taz ) > NULL
$baz->faz() > faz()
echo $baz->taz > taz
$baz->raz() > bar()
> faz()
> taz
$a->raz() > bar()
> faz()
var_dump( $a->taz ) > NULL
Deletions:
faz()
taz
bar()
faz()
taz
bar()
faz()
NULL
Additions:
=====Prototype in PHP=====