PHP 5.4.31 Released

aggregate_methods

(PHP 4 >= 4.2.0)

aggregate_methods Dynamic class and object aggregation of methods

Descripción

void aggregate_methods ( object $object , string $class_name )

Aggregates all methods defined in a class to an existing object, except for the class constructor, or methods whose names start with an underscore character (_) which are considered private to the aggregated class.

Parámetros

object

class_name

Valores devueltos

No devuelve ningún valor.

Ver también

add a note add a note

User Contributed Notes 1 note

up
0
a at antialize dot dk
9 years ago
You can use this to dynamicily add methods to a class

class foo {
  function addMethod(  $code ) {
    $cname = uniqid("class");
    eval( "class ${cname} { ${code} }" );       
    aggregate_methods( $this , $cname );
  }

  function bar() {
    $this->addMethod( "function baz() { echo 'sha'; }" );
  }
}

$bang = new foo();
$bang->bar();
$bang->baz();
To Top