note 107848 added to closure.bindto
| From: | safakozpinaratgmaildotcom | Date: | Fri, 09 Mar 2012 13:35:04 +0000 |
| Subject: | note 107848 added to closure.bindto | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186563@lists.php.net to get a copy of this message | ||
Private/protected members are accessible if you set the "newscope" argument (as the manual
says).
<?php
$fn = function(){
return ++$this->foo; // increase the value
};
class Bar{
private $foo = 1; // initial value
}
$bar = new Bar();
$fn1 = $fn->bindTo($bar, 'Bar'); // specify class name
$fn2 = $fn->bindTo($bar, $bar); // or object
echo $fn1(); // 2
echo $fn2(); // 3
----
Server IP: 69.147.83.197
Probable Submitter: 78.173.54.123
----
Manual Page -- http://www.php.net/manual/en/closure.bindto.php
Edit -- https://master.php.net/note/edit/107848
Del: integrated -- https://master.php.net/note/delete/107848/integrated
Del: useless -- https://master.php.net/note/delete/107848/useless
Del: bad code -- https://master.php.net/note/delete/107848/bad+code
Del: spam -- https://master.php.net/note/delete/107848/spam
Del: non-english -- https://master.php.net/note/delete/107848/non-english
Del: in docs -- https://master.php.net/note/delete/107848/in+docs
Del: other reasons-- https://master.php.net/note/delete/107848
Reject -- https://master.php.net/note/reject/107848
Search -- https://master.php.net/manage/user-notes.php