note 112335 added to functions.anonymous
| From: | mrdaniel619 at gmail dot com | Date: | Mon, 03 Jun 2013 06:54:10 +0000 |
| Subject: | note 112335 added to functions.anonymous | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195034@lists.php.net to get a copy of this message | ||
just in case you ever want to change a member function run time
<?php
class t
{
var $num;
var $dynamic_function;
public function dynamic_function()
{
$func = $this->dynamic_function;
$func($this);
}
}
$p = new t();
$p->num = 5;
$p->dynamic_function = function($this_ref) // param cannot be named $this
{
echo $this_ref->num++.'<br />';
};
$p->dynamic_function(); // CALL YOUR DYNAMIC FUNCTION
$p->dynamic_function = function($this_ref) // NEW DYNAMIC fUNCRION
{
echo $this_ref->num.'<br />';
$this_ref->num *= 3;
};
$p->dynamic_function(); // CALL DYNAMIC FUNCTION
echo $p->num; // display number
exit;
?>
output:
5
6
18
----
Server IP: 69.147.83.199
Probable Submitter: 98.176.50.73
----
Manual Page -- http://php.net/manual/en/functions.anonymous.php
Edit -- https://master.php.net/note/edit/112335
Del: integrated -- https://master.php.net/note/delete/112335/integrated
Del: useless -- https://master.php.net/note/delete/112335/useless
Del: bad code -- https://master.php.net/note/delete/112335/bad+code
Del: spam -- https://master.php.net/note/delete/112335/spam
Del: non-english -- https://master.php.net/note/delete/112335/non-english
Del: in docs -- https://master.php.net/note/delete/112335/in+docs
Del: other reasons-- https://master.php.net/note/delete/112335
Reject -- https://master.php.net/note/reject/112335
Search -- https://master.php.net/manage/user-notes.php