Click to See Complete Forum and Search --> : Notice: Undefined variable


field4000
10-08-2004, 08:15 AM
I am sorry if this has been asked before.

I am having a great deal of difficulty with the Notice: Undefined variable error message.

I have the global_register turned on. But the problem still occurs.

I am using a tried and tested script: phphoo3.

I read somewhere that one needs to put the files in a HTdocs directory???

I also read something about supressing the error messages. I would rather it work without errors and get no error message.

I am running XP, Apache and PHP 4.3.8.

Thank you in advance.

ShrineDesigns
10-08-2004, 01:46 PM
<?php
// if $foo is not defined elsewhere (prior) it will produce an error notice
$foo .= "some thing";

// this won't
$bar = "";
$bar .= "some text";

// same here no notice
$var = "";

for($i; $i < 10; $i++)
{
$var .= "blah\n";
}
?>

dreamcatcher
10-08-2004, 04:48 PM
For a quick fix, change your error reporting:

error_reporting (E_ALL ^ E_NOTICE);

or

error_reporting(0);

The undefined variable error is PHP being a little over sensitive.

Jona
10-08-2004, 07:36 PM
I would suggest this as your error reporting settings:


E_STRICT | E_ALL


The reason for this is so that you force yourself to learn to write efficient code, rather than sloppy, buggy, and unportable code.