PDA

Click to See Complete Forum and Search --> : problem with new version


Brandito
Jan 31st, 2003, 10:48 PM
My server guy updated to php 4.3.0.
It has done some bad things...

This is my problem...

I am using this to request url variable data:
$myLink = $_REQUEST[myLink];
$myFriendly = $_REQUEST[friendly];

Error:
Notice: Use of undefined constant myLink - assumed 'myLink' in d:\wwwroot\brandito\website\Site.php on line 8

Notice: Use of undefined constant friendly - assumed 'friendly' in d:\wwwroot\brandito\website\Site.php on line 9

Notice: Undefined index: friendly in d:\wwwroot\brandito\website\Site.php on line 9

If it 'assumes' that.. why the heck does it have to say so. The php code works.. it just adds these comments at the top! Bad design if you ask me. How does one go about fixing this?

Thanks alot for your support,
Brandito

da_silvy
Feb 1st, 2003, 08:34 AM
print $array[foo];

PHP looks for a constant named foo first, if it does not exist then
it'll shout an error of level E_NOTICE and then look for the key foo
(which is what you wanted) ...

error_reporting can be set about anywhere, including php.ini, .htaccess
and the error_reporting() function. And some code:

define('a', 'b');
$arr = array('a' => 'apple', 'b' => 'banana');
print $arr[a]; // banana
print $arr['a']; // apple

Moral of the story is you should always surround your array keys with
quotes! ;)

A little searching goes a long way :p

The Hobo
Feb 1st, 2003, 12:48 PM
Originally posted by da_silvy
Moral of the story is you should always surround your array keys with quotes!

I thought this was a common coding practice?

da_silvy
Feb 1st, 2003, 08:08 PM
That's the way i do it :p

Rick Bull
Feb 2nd, 2003, 05:54 AM
Notice: Undefined index: friendly in d:\wwwroot\brandito\website\Site.php on line 9

That one is because "friendly" hasn't been passed into the $_REQUEST variable either. You can either get round it like $myFriendly = (isset($_REQUEST['friendly'])) $_REQUEST['friendly'] : ''; or you can turn the notice warnings off can't you with error_reporting()

phpman
Feb 2nd, 2003, 11:54 AM
The FIX and it also started in 4.1 is to uncomment the error lines that read as follows,
error_reporting = E_ALL & ~E_NOTICE

if you don't have access to the ini file you can do it in code as well

you can insert this into your script at the very top

error_reporting (E_ALL ^ E_NOTICE);