Search code examples
phpoperatorslogical-operators

PHP - not operator, any other aliases?


if(!($whatever && what()) do_stuff...

Can this be replaced with something more intuitive like:

if(not($whatever && what()) do_stuff...

?


Solution

  • function not($OriginalCheck)
    {
        return !$OriginalCheck;
    }
    
    function is($OriginalCheck)
    {
        return !!$OriginalCheck;
    }
    

    should do exactly that :)

    There are several ways to write checks:

    • if(!($whatever && what()) do_stuff...
    • if(!$whatever || !what()) do_stuff...
    • if(($whatever && what()) === false) do_stuff...
    • if((!$whatever || !what()) === true) do_stuff...
    • if($whatever === false || what() === false) === true) do_stuff...

    all these ways are intuitive and known through out the programming world.