SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    USA
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP & WinNT server problem - Error mess: "Notice: Undefined variable:"

    Hello !

    I am using WinNT server. Below is my very simple PHP script

    PHP Code:
    <?php

    print "$temp Hello";

    ?>
    Can you tell me why I got error message below:
    Notice: Undefined variable: temp in D:\user\kevi\php\test.php on line 3
    Hello
    If I run the script on linux server I got no problem. How to tell my hosting company to fix it ?

    Thanks!
    Kev

  2. #2
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The reason is because you're using a variable which has not yet been given a value (has not been defined). You can test first like;

    PHP Code:
    <?php
    if ( isset($test) ) {
        print 
    "$temp Hello";
    }
    ?>
    Many PHP installations have the checking for undefined variables switched off. This is handled in php.ini - the error_reporting value. See here for more on error levels in PHP. You can probably switch it off in your scripts, by putting this at the top;

    PHP Code:
    error_reporting('E_ALL ^ E_NOTICE'); 
    Technically it's a good thing to have this level of error reporting switched on. See this discussion for more info.

    Also - probably not really an "advanced PHP" topic.

  3. #3
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Used PHP a lot on NT2000 Pro w/out any problems what so ever, so proberly is an ini setting

    On Harry's point, I now have E_ALL on all my pages - development - and remove them for production, just to be sure.

    Didn't really bother before though, until recently.

  4. #4

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Widow Maker
    Used PHP a lot on NT2000 Pro w/out any problems what so ever, so proberly is an ini setting
    Definitely.

    Quote Originally Posted by Widow Maker
    On Harry's point, I now have E_ALL on all my pages - development - and remove them for production, just to be sure.
    Good decision, however I actually do not even worry too much about this message because IMHO it isnt that much of a problem as long as the command flow does not use undefined variables. If you just output it it will come out as empty string which is in most cases what you want, because otherwise you would have actually assigned it a value before.

  5. #5
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At the moment in some cases I have a NOTICE error and all scripts breakdown as there is not a variable in the URL for $_REQUEST to fetch.

    Without E_ALL I wouldn't have known this, then distributing software with this bug would at the very least, make me look incompetent, or worse, give me a bad rep amonghst my (currently) happy customers

    So I'm glad I'm now using it.

  6. #6
    SitePoint Evangelist ghurtado's Avatar
    Join Date
    Sep 2003
    Location
    Wixom, Michigan
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is about as basic a PHP question as they come. Please move.

  7. #7
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    to where ? another city ?

  8. #8
    SitePoint Evangelist ghurtado's Avatar
    Join Date
    Sep 2003
    Location
    Wixom, Michigan
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To the proper forum

  9. #9
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    USA
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot !

    This

    error_reporting('E_ALL ^ E_NOTICE');

    solve my problem.

    Thanks again!

    Kev

  10. #10
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your welcome, glad we could help in fact

  11. #11
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This doesn't really solve it, it hides it till is stabs you in the back. Like Window Maker recommend, use E_ALL for development so that you cach such notices which can be quite important.


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
  •