Click to See Complete Forum and Search --> : Undefined variable
When i try to execute the php scripts on a pws/win98 platform which has been downloaded from the hotscripts.com
I am getting lot of errors like :
Undefined variable <variablename>
or
Use of undefined constant <variablename>
whereas the same scripts is working fine on a linux/apache platform.
Can anybody help what could be the problem.
vincente
09-10-2001, 07:08 AM
The script wasn't working fine on the linux machine, you just disn't see the errors.
In PHP you can define which errors should be reported and which should be hidden. Check the php.ini and read the manual about error_reporting().
Note: it is NEVER a good idea to set the error-reporting lower.
Each and every warning you get should be fixed, especially the 'undefined variable' warnings. They basically mean that you are using a variable without first putting a value in them, which is dangerous.
ccgorman
09-10-2001, 07:10 AM
It is always good coding practice to define variables at the top of your code. I often
assign a value to them, or use:
if (!isset($var)) {
$var=1;
}
if there may already be a value. In saying that it would be good to turn those error messages off occasionally, but when wring your own code it is good to declare your variables.
-David
I have the same problem.
All scripts that I have downloaded, except one, have the same problem running on windows. I have read all about the error handling, but my conclusion was that the programmers must not be declaring their variables properly.
This included sites like PHP Nuke.
Why are they doing this, why aren't they correcting this and why are they turning error handling of on Apache???
vincente
09-11-2001, 04:22 AM
Because they are lazy :)
Turning off the error_reporting() doesn't change anything.
There's no need to declare the variable, it's the PHP power! Check the manual, it's on the first few page "no need to declare variable in PHP".... I think problems comes from Apache or the configuration of the PHP module on the server. I'm investigating that now, I will post that back here.
Ok, it seems this is due to missing modules on the server or a misconfiguration on the server (Apache or whatever).
If you have such errors, please re-install PHP and all the module from the RPM files.
Hi Chris,
what was the result of your investigation, because i've got the same problem. Also Win98. I am able to access a variable with $HTTP_GET_VARS["name"], but not with $name. Hopping you are able to help me - best greatings Agnes
PHP Builder
Copyright WebMediaBrands Inc. All Rights Reserved.