Revision [43]

Last edited on 2008-06-12 18:57:40 by MattRead
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.
Deletions:
public static function add_method( $method, $callback )
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.


Revision [42]

Edited on 2008-06-12 16:41:25 by MattRead
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
Deletions:
$baz->bar() > 'bar()'
$baz->faz() > 'faz()'
echo $baz->taz > 'taz'
$baz->raz() > 'bar()'
> 'faz()'
> 'taz'
$a->raz() > 'bar()'
> 'faz()'
>
var_dump( $a->taz ) > NULL


Revision [41]

Edited on 2008-06-12 16:40:20 by MattRead
Additions:
>


Revision [40]

Edited on 2008-06-12 16:29:19 by MattRead
Additions:
$baz->bar() > 'bar()'
$baz->faz() > 'faz()'
echo $baz->taz > 'taz'
$baz->raz() > 'bar()'
> 'faz()'
> 'taz'
$a->raz() > 'bar()'
> 'faz()'
Deletions:
$baz->bar() > bar()
$baz->faz() > faz()
echo $baz->taz > taz
$baz->raz() > bar()
> faz()
> taz
$a->raz() > bar()
> faz()


Revision [39]

Edited on 2008-06-12 16:28:27 by MattRead
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
Deletions:
bar()
faz()
taz
bar()
faz()
taz
bar()
faz()
NULL


Revision [38]

Edited on 2008-06-12 16:23:56 by MattRead
Additions:
=====Prototype in PHP=====


Revision [37]

The oldest known version of this page was created on 2008-06-12 16:20:51 by MattRead
Page was generated in 0.0697 seconds