-2

I.e. instead of:

const MY_CONST = 0;

he writes:

public static function MY_CONST() { return 0 }; 

My former colleagues, front-end developers, doing so in JavaScript, because there are no constants, but to do so in PHP? In my opinion, if the language have a constants, you should use them.

I want to send him a link to this question, as my arguments.

Geobits
  • 22,218
  • 6
  • 59
  • 103

2 Answers2

2

Writing method to return always same value is senseless. Of course it is better pratice to use constans. Even when you look at perfomace it's faster when you declare something that you know won't change as constant.

I agree with hakre don't argue with idiots they will bring you to their level and beat with experience.

I read somewhere that in PHP constans are not so fast. You should read this article.

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

Robert
  • 19,800
  • 5
  • 55
  • 85
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.

hakre
  • 193,403
  • 52
  • 435
  • 836