在Zend的快速入门指南这里http://framework.zend.com/manual/en/learning.quickstart.create-model.html我们可以看到:Php __get和__set魔术方法 - 为什么我们需要这些?
class Application_Model_Guestbook
{
protected $_comment;
protected $_created;
protected $_email;
protected $_id;
public function __set($name, $value);
public function __get($name);
public function setComment($text);
public function getComment();
...
我通常创建我的getter和setter方法没有任何魔术方法。我在快速指南中看到了这一点,我不明白为什么我们需要这个。
任何人都可以帮我吗?
非常感谢
它减少了打字。而已。 – 2011-04-25 16:17:53
因此,我通常在同一个地方:$ object-> setComment('hello'),我可以改为:__set($ _ comment,'hello'); ?我相信这不是你所指的,因为我不会减少打字。再次感谢。 – MEM 2011-04-25 16:20:56
你不直接调用'__get'和'__set'。你只要做到这一点:'$ object - > _ comment ='hello';' – 2011-04-25 16:23:28