-2

即代替:

const MY_CONST = 0;

他写:

public static function MY_CONST() { return 0 }; 

我以前的同事,前端开发人员,在 JavaScript 中这样做,因为没有常量,但在 PHP 中这样做?在我看来,如果语言有常量,你应该使用它们。

我想向他发送这个问题的链接,作为我的论点。

4

2 回答 2

2

编写始终返回相同值的方法是毫无意义的。当然,使用常量是更好的做法。即使您查看性能,当您声明某些您知道不会更改为常数的东西时,它也会更快。

我同意 hakre 不要与白痴争论,他们会让你达到他们的水平并用经验击败。

我在某处读到 PHP 中的常量不是那么快。你应该阅读这篇文章。

http://planetozh.com/blog/2006/06/php-variables-vs-constants/

于 2013-04-18T08:12:07.553 回答
1

In my opinion, if the language have a constants, you should use them.

Sure, that's why they are in. Otherwise it is not a constant. Did he said he needs a constant? If so, tell him there is a PHP manual explaining it in case the language is new to him.

The URLs are http://php.net/const and http://php.net/constants .

Apart from these fundamental and bare things, do not argue with idiots. They live - by the original meaning of the word - in their own world. So you can not get through to them.

于 2013-04-18T07:56:46.697 回答