PHP saying I have an undefined variable?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bissatch@yahoo.co.uk

    PHP saying I have an undefined variable?

    Hi,

    I get the following error:


    Notice: Undefined variable: end_while in C:\Program
    Files\Apache\Ap ache2\htdocs\cs p\inc\xmlmenu.p hp on line 102


    This is a script that works on the server at work but it has difficulty
    with me running on my home desktop. The variable, $end_while, is just a
    basic variable. Is this a configuration problem where you can allow
    undefined variables? Ive never had to define variables in the past.

    Cheers

    Burnsy

  • Daniel Tryba

    #2
    Re: PHP saying I have an undefined variable?

    bissatch@yahoo. co.uk wrote:[color=blue]
    > Notice: Undefined variable: end_while in C:\Program
    > Files\Apache\Ap ache2\htdocs\cs p\inc\xmlmenu.p hp on line 102
    >
    >
    > This is a script that works on the server at work but it has difficulty
    > with me running on my home desktop. The variable, $end_while, is just a
    > basic variable. Is this a configuration problem where you can allow
    > undefined variables? Ive never had to define variables in the past.[/color]

    See: http://php.net/error_reporting

    Example 1 shows how to turn it off. _BUT_ you shouldn't do that, fix the
    code instead.

    Comment

    • ECRIA Public Mail Buffer

      #3
      Re: PHP saying I have an undefined variable?

      Note that this is not an error but a notice - there's a difference. Errors
      will stop execution of your script, while warnings and notices are there to
      inform you of possible faulty code. Depending on your error_reporting
      setting in php.ini, you may or may not see warnings and notices. Your script
      has an undefined variable on your server but your server is just not telling
      you, because error_reporting is set to off or warn (not all).

      It is likely that you are using $end_while in a conditional statement before
      you have defined it, leading to the notice. You should set it to a default
      value at the beginning of your script, or before you use it.

      ECRIA



      Comment

      • FrobinRobin

        #4
        Re: PHP saying I have an undefined variable?

        If you dont want to define the variable first - you can always use a
        conditional to act if it doesnt exist:
        if(!isset($varn ame))
        {
        do something
        }
        Or to supress the notices you can set the PHP error level reporting at
        runtime using:
        error_reporting (E_ALL ^ E_NOTICE);
        That is; if you dont have access to your PHP.ini!

        Regards
        - FrobinRobin

        ECRIA Public Mail Buffer wrote:[color=blue]
        > Note that this is not an error but a notice - there's a difference. Errors
        > will stop execution of your script, while warnings and notices are there to
        > inform you of possible faulty code. Depending on your error_reporting
        > setting in php.ini, you may or may not see warnings and notices. Your script
        > has an undefined variable on your server but your server is just not telling
        > you, because error_reporting is set to off or warn (not all).
        >
        > It is likely that you are using $end_while in a conditional statement before
        > you have defined it, leading to the notice. You should set it to a default
        > value at the beginning of your script, or before you use it.
        >
        > ECRIA
        > http://www.ecria.com[/color]

        Comment

        Working...