参考: http://us.php.net/manual/en/closure.bind.php
有如下测试:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?php class A { private static $sfoo = 1; private $ifoo = 2; } $cl1 = static function() { return A::$sfoo; }; $cl2 = function() { return $this->ifoo; }; $bcl1 = Closure::bind($cl1, null, 'A'); $bcl2 = Closure::bind($cl2, new A(), 'A'); echo $bcl1(), "\n"; echo $bcl2(), "\n"; |
上述代码说明: 通过Closure的bind方法是可以访问一个对象的private属性的;这个是不是有悖于程序设计原则?