Re: PHP_SELF defined or not
| From: | Philip Olson | Date: | Wed, 07 May 2003 19:09:14 +0000 |
| Subject: | Re: PHP_SELF defined or not | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-146722@lists.php.net to get a copy of this message | ||
On Wed, 7 May 2003, caspar kennerdale wrote:
> I have a form in a switch case, the form is to be posted to
> $_SERVER['PHP_SELF']
>
> the results will be processed in another switch case.
>
> However I get the following message
>
> Undefined index: 'PHP_SELF'
>
> I thought that $_SERVER['PHP_SELF'] was predefined and related to the
> current file. $_SERVER being a master array of global info.
Congratulations! You just found yourself confused by an
annoying PHP bug in PHP 4.3.0 and 4.3.1. :)
The following is improper syntax in any PHP version:
echo "I am bad $_SERVER['PHP_SELF'] okay?";
This is bad because of the way it's being used inside
a string. The above code will give an error which is:
4.2.3 and below : Parse Error (E_PARSE)
4.3.0-1 : Bogus E_NOTICE (you are seeing this)
4.3.2 : Parse Error (E_PARSE)
Of course you can still use array elements inside strings
in all PHP versions but must follow proper syntax. This
syntax is described (and includes many examples) here:
http://www.php.net/types.string
Which shows methods to rewrite our bad code above, example:
echo "I am good {$_SERVER['PHP_SELF']} okay?";
echo "I am good " . $_SERVER['PHP_SELF'] . " okay?";
And of course this applies to all arrays in strings.
Regards,
Philip