PHP:评论标准 [英] PHP: Commenting standards

查看:135
本文介绍了PHP:评论标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在只有少数文件中评论大量的信息,当我看看Google和SO这里,我继续找到匹配编码标准的结果 ,当我需要评论标准。

I need to comment massive amounts of information in only a handful of files, and when I look around Google and here at SO, I continue to find results matching coding standards, when I need commenting standards. My coding matches most coding standards except not when it comes to commenting.

有人可以提供以下例子吗?

Could someone please provide examples for the following?

<?

    // beginning of file comments

    require( 'filename.php' ); // require or include, with filename

    public class Test { } // class without constructor

    public class Test // class with constructor, if different from above
    {
        public function __constructor() { } // constructor, no parameters

        public function __constructor(var1, var2) { } constructor, with parameters

        public function func1() { } // function, no parameters

        public function func2($var1, $var2) { } // function, with parameters

        public function func3( $optional = '' ) { } // function, optional parameters

        private function func4() { } // private function, if different from above

        public static staticfunc1() { } // public static function, if different from above

        public function returnfunc1(var1, var2) // function, with return value
        {
            return var1 + var2; // return statement, dynamic
        }

        public function returnfunc2() // function, with unchanging return value, if different from above
        {
            return 1; // return statement, unchanging, if different from above
        }

        public function fullfunc1() // declaration, calling and assignment, in function
        {
            $var1; // variable declaration

            $arr1 = array(); // array declaration, if different from above

            $var2 = dirname( __FILE__ ) . '/file.ext'; // variable assignment

            $this->var1 = $path . '_'; // class variable assignment

            ob_start(); // function call

            $this->func1(); // class function call

            ob_end_clean();

            foreach($arr as $key => $val) { } // foreach and for loops
        }

        public $var1; // public variable

        private $var2; // private variable, if different from above
    }

    // ending of file comments?

?>

了解正确的风格很重要。

Knowing proper style is important. It helps other individuals understand how your code works, and how to use it in the future if you are not there to explain it.

推荐答案


  1. phpDocumentor样式

  2. Zend框架样式

  3. 梨风格

  1. phpDocumentor style
  2. Zend Framework style
  3. Pear style

但是一般来说, ...你可能不想对代码中的每一行进行注释。相反,尽量让你的代码可读 1 (当然)。当你真正需要别人来理解你的代码在做什么时,注释(大多数)。

But in general, something to remember about commenting is... you probably don't want to comment every line in your code. Instead, try to make your code readable1 (as is.) And comment (mostly,) when you really need someone else to understand what your code is doing.

1 http:// www。 encodehorror.com/blog/2008/07/coding-without-comments.html

这篇关于PHP:评论标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆