note 106912 added to closure.bindto
| From: | amica at php-resource dot de | Date: | Mon, 19 Dec 2011 00:23:48 +0000 |
| Subject: | note 106912 added to closure.bindto | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185120@lists.php.net to get a copy of this message | ||
With rebindable $this at hand it's possible to do evil stuff:
<?php
class A {
private $a = 12;
private function getA () {
return $this->a;
}
}
class B {
private $b = 34;
private function getB () {
return $this->b;
}
}
$a = new A();
$b = new B();
$c = function () {
if (property_exists($this, "a") && method_exists($this, "getA")) {
$this->a++;
return $this->getA();
}
if (property_exists($this, "b") && method_exists($this, "getB")) {
$this->b++;
return $this->getB();
}
};
$ca = $c->bindTo($a, $a);
$cb = $c->bindTo($b, $b);
echo $ca(), "\n"; // => 13
echo $cb(), "\n"; // => 35
?>
----
Server IP: 212.124.37.9
Probable Submitter: 77.5.251.188
----
Manual Page -- http://www.php.net/manual/en/closure.bindto.php
Edit -- https://master.php.net/note/edit/106912
Del: integrated -- https://master.php.net/note/delete/106912/integrated
Del: useless -- https://master.php.net/note/delete/106912/useless
Del: bad code -- https://master.php.net/note/delete/106912/bad+code
Del: spam -- https://master.php.net/note/delete/106912/spam
Del: non-english -- https://master.php.net/note/delete/106912/non-english
Del: in docs -- https://master.php.net/note/delete/106912/in+docs
Del: other reasons-- https://master.php.net/note/delete/106912
Reject -- https://master.php.net/note/reject/106912
Search -- https://master.php.net/manage/user-notes.php