note 11434 modified in function.create-function by danbrown

From: Date: Sat, 19 Jul 2008 21:29:55 +0000
Subject: note 11434 modified in function.create-function by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141758@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 : <?php 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://php.net/manual/en/function.create-function.php

« previous php.notes (#141758) next »