note 51133 deleted from function.aggregate-methods by sobak

From: Date: Sun, 04 Dec 2016 07:38:13 +0000
Subject: note 51133 deleted from function.aggregate-methods by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208136@lists.php.net to get a copy of this message
Note Submitter: a at antialize dot dk ---- 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();

« previous php.notes (#208136) next »