On 4/12/12 11:25 AM, Laruence wrote:
Now you can not use $this
class foo {
public function bar() {
return function() use ($this) { // PHP Fatal error:
Cannot use $this as lexical variable
}
}
}
so you have to write:
class foo {
public function bar() {
$obj = $this;
return function() use ($obj) {
}
}
}
thanks
Correct me if I am wrong, but this is possible in 5.4 with the
Closure::bindTo() API, as well as the implied binding of $this.
Working in my code:
class ServiceLocator
{
protected $services = array();
public function __construct()
{
$this->services['DbAdapter'] = function () {
return new DbAdapter(
$this->get('Configuration')['db']
);
};
$this->services['UserTable'] = function () {
return new TableGateway(
'user',
$this->get('DbAdapter')
);
};
}
public function get($name) {
...
-ralph
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php