note 112335 deleted from functions.anonymous by cmb
| From: | cmb@php.net | Date: | Sun, 08 Dec 2019 11:28:47 +0000 |
| Subject: | note 112335 deleted from functions.anonymous by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213464@lists.php.net to get a copy of this message | ||
Note Submitter: mrdaniel619 at gmail dot com
----
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