note 102074 added to language.oop5.overloading

From: Date: Wed, 26 Jan 2011 10:45:29 +0000
Subject: note 102074 added to language.oop5.overloading
Groups: php.notes 
Request: Send a blank email to php-notes+get-176321@lists.php.net to get a copy of this message
Previous example can be easily modificated to access $this: <?php class Object { // generic class allowing dynamic addition of methods public $methods = array(); // list of all custom added methods function __call($fnc, $args) { array_unshift($args, $this); return call_user_func_array($this->methods[$fnc], $args); } } // Example adding a new custom method $test = new Object; $test->b = "sample text"; $test->methods['do_something'] = function ($self, $var1, $var2) { echo "custom method called with $var1, $var2 and using $self->b\n"; }; $test->do_something('asdf', 'test1'); ?> Naw you can use anon function with reference to $this. ---- Server IP: 193.219.81.76 Probable Submitter: 195.14.188.77 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php Edit -- https://master.php.net/note/edit/102074 Del: integrated -- https://master.php.net/note/delete/102074/integrated Del: useless -- https://master.php.net/note/delete/102074/useless Del: bad code -- https://master.php.net/note/delete/102074/bad+code Del: spam -- https://master.php.net/note/delete/102074/spam Del: non-english -- https://master.php.net/note/delete/102074/non-english Del: in docs -- https://master.php.net/note/delete/102074/in+docs Del: other reasons-- https://master.php.net/note/delete/102074 Reject -- https://master.php.net/note/reject/102074 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#176321) next »