1<?PHP2 3 /**4 * reference:http://www.php.net/manual/en/reflectionmethod.getclosure.php5 * Learn this and you'll know how to peer through what's a horse is thinking!6 *7 * Class Client8 */9 classpeopleTen { One Private $heartWords= "How beautiful the horse is! I want to ride it! "; A - Public functionHook () - { the $who=Get_class($this); - Echo Ucfirst($who). "says:".$this->heartwords. "\ n"; - } - + Public functionPeer () - { + return function(){ A $this-Hook (); at }; - } - } - - classHorse - { in Private $heartWords= "How silly the guy is! A Big ass! "; - } to + $people=Newpeople (); - $horse=NewHorse (); the * Try{ $ $reflection=NewReflectionclass (Get_class($people));Panax Notoginseng } - Catch(reflectionexception$e) the { + Echo $e->getmessage (). " \ n "; A return; the } + - $closure=$reflection->getmethod (' Hook ')->getclosure ($people); $ $truth=$closure->bindto ($horse,$horse); $ - $truth();//Horse says:how Silly the guy is! A Big ass!
Note: I solemnly declare that this analogy is only to deepen the understanding of the example, without discrediting human meaning.
PHP uses closures to spy on horses ' thoughts on humans