Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the meaning of the reverse entry (null === $value) when checking the value of the variable? [duplicate]

Possible Duplicate:
PHP - reversed order in if statement
Checking for null - what order?

Examining Zend Framework found that they do all the variable checkings reverse way:

public function setBootstrap($path, $class = null) {

   if (null === $class) {    // instead of if($class === null)
      $class = 'Bootstrap';
   }

What's the reason of doing this?

Is this also suitable for Java and C++ programming?

like image 812
Green Avatar asked Dec 05 '22 16:12

Green


1 Answers

some people believe it helps them in avoiding to write a single = (an assignment instead of a comparison for equality)

I believe that the advantage of doing so is much less than the loss of readability (and therefore maintainability!)

People who don't test their code may rely on this sort of trick. And to answer your question, yes, it is suitable for most languages who derive their syntax from C - I mean suitable, not recommended.

like image 117
Walter Tross Avatar answered Apr 27 '23 05:04

Walter Tross