PHP Classes

Unnecessary booleans

Recommend this page to a friend!

      PHP Dependency Injection Container  >  PHP Dependency Injection Container package blog  >  Improving Your PHP Pr...  >  All threads  >  Unnecessary booleans  >  (Un) Subscribe thread alerts  
Subject:Unnecessary booleans
Summary:Use of "condition ? false : true"
Author:Per Persson
Date:2015-11-10 20:53:31

  1. Unnecessary booleans   Reply   Report abuse  
Picture of Per Persson Per Persson - 2015-11-10 20:53:31
I don't understand programmers who write things like

return (count($param) < 1) ? false: true;

when it could be written just

return count($param) >= 1;

  2. Re: Unnecessary booleans   Reply   Report abuse  
Picture of Dave Smith Dave Smith - 2015-11-11 21:59:31 - In reply to message 1 from Per Persson
Could be that we expect a bool type instead of int type

Not the case in that particular example, so...

Could be that it makes the code easier to read, which is not a bad goal with open source.

Could be that we are preparing for type hinting which is on its way.


For more information send a message to info at phpclasses dot org.