note 11434 modified in function.create-function by vrana
| From: | vrana@php.net | Date: | Wed, 10 Dec 2003 18:48:57 +0000 |
| Subject: | note 11434 modified in function.create-function by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-61770@lists.php.net to get a copy of this message | ||
Here is another tricky but usefull techynote, good for adding "plugin" to a existing class
:
<?
class Hoge {
var $lamda;
var $text;
function set($lamda)
{
$this->lamda = $lamda;
}
function callLamda()
{
$func = $this->lamda;
return $func($this);
}
function get()
{
return $this->text;
}
}
$newfunc = create_function('&$class', 'echo $class->get();' );
$h = new Hoge;
$h->text = "Hi there !";
$h->set($newfunc);
$h->callLamda();
?>
--was--
Here is another tricky but usefull techynote, good for adding "plugin" to a existing class
:
<?
class Hoge {
var $lamda;
var $text;
function set($lamda)
{
$this->lamda = $lamda;
}
function callLamda()
{
$func = $this->lamda;
return $func($this);
}
function get()
{
return $this->text;
}
}
$newfunc = create_function('&$class', 'echo $class->get();' );
$h = new Hoge;
$h->text = "Hi there !";
$h->set($newfunc);
$h->callLamda();
?>
http://www.php.net/manual/en/function.create-function.php