SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Evangelist winterheat's Avatar
    Join Date
    Aug 2007
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    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.

  2. #2
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Turn your error reporting level up.

    It should bawk about an undefined constant, and then interpret it as a string.

    All in easy to spot error messages.
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  3. #3
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    To add what was said, PHP produces an E_NOTICE which by default in most configs is filtered out.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  4. #4
    SitePoint Evangelist winterheat's Avatar
    Join Date
    Aug 2007
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    To add what was said, PHP produces an E_NOTICE which by default in most configs is filtered out.
    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); )

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    easier to just use E_ALL

    btw - you can set this in .htaccess or php.ini so you don't need to manually set it in every script
    http://www.php.net/configuration.changes

  6. #6
    SitePoint Evangelist winterheat's Avatar
    Join Date
    Aug 2007
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crmalibu View Post
    easier to just use E_ALL

    btw - you can set this in .htaccess or php.ini so you don't need to manually set it in every script
    http://www.php.net/configuration.changes
    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.

    Code PHP:
    $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\");");    
    }

  7. #7
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Yup can review the chart for E_ALL, contains all except for E_STRICT in versions less then 6.0
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  8. #8
    SitePoint Evangelist winterheat's Avatar
    Join Date
    Aug 2007
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    Yup can review the chart for E_ALL, contains all except for E_STRICT in versions less then 6.0
    oh i see... the statement there

    "All errors and warnings, as supported, except of level E_STRICT in PHP < 6."

    i wasn't sure whether E_NOTICE is part of the "errors and warnings" because it is a notice, not warning. but thanks for the tip. so it actually means "EVERYTHING" (except E_STRICT).


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •