if (!$foo && !bar) actually won't gave error when $bar is typed as bar

Discussion in 'PHP' started by winterheat, Feb 13, 2009.

  1. #1
    the statement

    if (!$foo && !$bar) { echo 'hi'; }

    is typed as

    if (!$foo && !bar) { echo 'hi'; }

    (with the '$bar' mistyped as 'bar')

    and i just found that PHP won't give error... is it true that the word bar is taken as a string literal... it seems a bit weird and sometimes it can give hard to catch error. many thanks.
     
    winterheat, Feb 13, 2009 IP
  2. Agent_Smith

    Agent_Smith Well-Known Member

    Messages:
    890
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    145
    #2
    error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
    PHP:
    :)
     
    Agent_Smith, Feb 13, 2009 IP
  3. winterheat

    winterheat Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ah i see... so with error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

    it will say bar is undefined constant and will treat it as a string literal
    (like if i do a var_dump(bar); )
     
    winterheat, Feb 13, 2009 IP
  4. winterheat

    winterheat Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Someone suggested using

    error_reporting(E_ALL);

    I have some code to tell what E_ALL includes... if someone knows of better ways of doing it and like to share could you post here. thanks.

    $arrayErrorLevelName = array(
    	'E_ERROR',
    	'E_WARNING',
    	'E_PARSE', 
    	'E_NOTICE', 
    	'E_CORE_ERROR',
    	'E_CORE_WARNING', 
    	'E_COMPILE_ERROR', 
    	'E_COMPILE_WARNING', 
    	'E_USER_ERROR', 
    	'E_USER_WARNING', 
    	'E_USER_NOTICE',
    	'E_STRICT',
    	'E_RECOVERABLE_ERROR',
    	'E_DEPRECATED',
    	'E_USER_DEPRECATED'
    );
    	
    echo "<pre>On PHP " . phpversion() . "\nE_ALL includes\n--------------\n";
    foreach ($arrayErrorLevelName as $errorLevelName) {
        eval("if ($errorLevelName & E_ALL) echo(\"$errorLevelName\n\");");    
    }
    
    PHP:
     
    winterheat, Feb 13, 2009 IP