dth62818 2010-03-23 18:55
浏览 41
已采纳

记录PHP,如果我扩展一个类,我应该复制/粘贴吗?

I have a PHP class with a method. In the base class (it's more like a prototype, but I'm not using prototypes because we have to be backwards compatible), I document the parameters and description of the method.

Now I extend that class. In this new method (the implementation) should I re-document the parameters and description, should I leave it blank, or should I only leave relevant notes that apply to that particular implementation?

My goal is to have readable API docs produced by PhpDoc, and to follow conventions.

  • 写回答

2条回答 默认 最新

  • douguai7291 2010-03-23 19:29
    关注

    Looking at a couple of examples in Zend Framework, it seems the comments are mostly copy-pasted -- and this sometimes leads to different comments.

    The first example I'll take is Zend_Http_Client_Adapter_Interface::connect, which is declared as :

    /**
     * Connect to the remote server
     *
     * @param string  $host
     * @param int     $port
     * @param boolean $secure
     */
    public function connect($host, $port = 80, $secure = false);
    

    And, if you take a look at a class that implements this interface, like Zend_Http_Client_Adapter_Curl, you'll see :

    /**
     * Initialize curl
     *
     * @param  string  $host
     * @param  int     $port
     * @param  boolean $secure
     * @return void
     * @throws Zend_Http_Client_Adapter_Exception if unable to connect
     */
    public function connect($host, $port = 80, $secure = false)
    

    So, copy-paste of the parameters ; and more informations in the implementation.


    Another example would be Zend_Log_Writer_Abstract::_write :

    /**
     * Write a message to the log.
     *
     * @param  array  $event  log data event
     * @return void
     */
    abstract protected function _write($event);
    

    And, in a child class, like Zend_Log_Writer_Db :

    /**
     * Write a message to the log.
     *
     * @param  array  $event  event data
     * @return void
     */
    protected function _write($event)
    

    Here, again, copy-paste ; and a small modification in the parent class, that has not been re-created in the child class.


    Now, what do I generally do ?

    • I generally consider that developpers don't write comments often enough
    • And generally forget to update them
    • So, I try to make their life easier, and don't duplicate comments
    • Unless the comment in the child class has to be different from the one in the parent class.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题