RE: [PHP] PHP_SELF Undefined
On Tue, 2002-02-19 at 05:14, Ford, Mike [LSS] wrote: > > -Original Message- > > From: Matt [mailto:[EMAIL PROTECTED]] > > Sent: 18 February 2002 23:30 > > To: Lars Torben Wilson > > > > > $foo = "This page is $_SERVER[PHP_SELF]"; [snip] > > Can you expand on why the first option isn't generally > > acceptable? > > Another reason, as I understand it (and I'm sure Torben will correct > me if I'm wrong!), is that in the version without quotes, PHP_SELF is taken as the name of a constant -- which, as it happens to be undefined, PHP very kindly assumes you intended to be the equivalent string 'PHP_SELF'. This is bad for two reasons: (1) the PHP compiler is doing avoidable extra work to get the desired result; (2) if you just happen, at a later date, to define a constant of that name, your result will suddenly be wrong (unlikely with PHP_SELF, I admit, but less so with something like, say, MAX_SIZE). Even though this is only a theoretical danger of low probability, the principles of good defensive programming would suggest that you nonetheless avoid it with a vengeance!! > > Cheers! > > Mike You're very right, but even worse than constant collisions are the keyword collisions, as far as WTF factor goes: 'Select an option', 'option1' => 'First option', 'option2' => 'Second option'); echo $array[default]; // Parse error. ?> This one has come up a number of times. -- Torben Wilson <[EMAIL PROTECTED]> http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP_SELF Undefined
> -Original Message- > From: Matt [mailto:[EMAIL PROTECTED]] > Sent: 18 February 2002 23:30 > To: Lars Torben Wilson > > > $foo = "This page is $_SERVER[PHP_SELF]"; > > > > Or, better: > > > > $foo = "This page is {$_SERVER['PHP_SELF']}"; > > > > You do have to concat to do this in single-quoted (noninterpolated) > > strings, though. > > > > > http://www.php.net/manual/en/language.types.string.php#languag > e.types.string > .parsing > > Can you expand on why the first option isn't generally > acceptable? Another reason, as I understand it (and I'm sure Torben will correct me if I'm wrong!), is that in the version without quotes, PHP_SELF is taken as the name of a constant -- which, as it happens to be undefined, PHP very kindly assumes you intended to be the equivalent string 'PHP_SELF'. This is bad for two reasons: (1) the PHP compiler is doing avoidable extra work to get the desired result; (2) if you just happen, at a later date, to define a constant of that name, your result will suddenly be wrong (unlikely with PHP_SELF, I admit, but less so with something like, say, MAX_SIZE). Even though this is only a theoretical danger of low probability, the principles of good defensive programming would suggest that you nonetheless avoid it with a vengeance!! Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP_SELF Undefined
On Tue, 19 Feb 2002 09:50, Narvaez, Teresa did align ASCII characters thusly: > When I execute the code below, why is PHP_SELF undefined? I will appretiate > any help on this. I can get its value by: > echo $_SERVER["PHP_SELF"];Thanks in advance! -Teresa > > > > > Feedback > > > $form_block = " > > Your Name: > > > Your E-Mail Address: > > > Your Message: > > > > > > > > "; > > ?> I don't know whether this is of any help to you or not, but this works perfectly on my system. I suspected it would as I saw nothing wrong, per se, with the code. Cheers, Brad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] PHP_SELF Undefined
I had this problem while running PHP under windows. I solved (well, rounded :) the problem with $SCRIPT_NAME (if I remember it right) which gives the very same result. Niklas -Original Message- From: Greg Donald [mailto:[EMAIL PROTECTED]] Sent: 19. helmikuuta 2002 8:05 To: [EMAIL PROTECTED] Subject: Re: [PHP] PHP_SELF Undefined > When I execute the code below, why is PHP_SELF undefined? I will appretiate > any help on this. I can get its value by: > echo $_SERVER["PHP_SELF"];Thanks in advance! -Teresa Is your PHP install >= version 4.1.0 ? You can test with a call to phpinfo(); If your version is less than 4.1.0, try the global variable $PHP_SELF instead. Greg Donald - http://destiney.com/ http://phprated.com/ | http://phplinks.org/ | http://phptopsites.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP_SELF Undefined
> When I execute the code below, why is PHP_SELF undefined? I will appretiate > any help on this. I can get its value by: > echo $_SERVER["PHP_SELF"];Thanks in advance! -Teresa Is your PHP install >= version 4.1.0 ? You can test with a call to phpinfo(); If your version is less than 4.1.0, try the global variable $PHP_SELF instead. Greg Donald - http://destiney.com/ http://phprated.com/ | http://phplinks.org/ | http://phptopsites.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP_SELF Undefined
> The other reason is that the parser needs help resolving ambiguity with > more complex expressions inside strings. If you use this syntax all the > time, you won't get bitten in the butt later. I've used the ${$var} to resolve the ambiguity of variable variables, but I wasn't aware that if could solve the problem with arrays within strings. I've always broke out of the string for the array part, and concatenated the rest of the string after that. I thought that was ugly, so of late I had been using the unquoted index inside strings. Thanks, Lars, for setting me straight on this. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP_SELF Undefined
On Monday, February 18, 2002, at 06:14 PM, Lars Torben Wilson wrote: > Sorry, but I do have to correct you here--this isn't true. ;) In double- > quoted strings and heredocs, you can do the following: > > $foo = "This page is $_SERVER[PHP_SELF]"; > > Or, better: > > $foo = "This page is {$_SERVER['PHP_SELF']}"; > > You do have to concat to do this in single-quoted (noninterpolated) > strings, though. Ah, I had forgotten about that. I stay away from the first version, and completely forgot about the second version. Ironic, because IIRC it is the answer to one of the first questions I posted on this list. (I was trying to include mysql_fetch_array elements in print statements and didn't want to transfer the value to a scalar beforehand, or something! :) Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP_SELF Undefined
On Mon, 2002-02-18 at 15:29, Matt wrote: > > $foo = "This page is $_SERVER[PHP_SELF]"; > > > > Or, better: > > > > $foo = "This page is {$_SERVER['PHP_SELF']}"; > > > > You do have to concat to do this in single-quoted (noninterpolated) > > strings, though. > > > > > http://www.php.net/manual/en/language.types.string.php#language.types.string > .parsing > > Can you expand on why the first option isn't generally acceptable? I can > understand there being an issue with spaces in an index, but is there some > other reason that the latter is prefered? A couple of reasons. For one, it's just inconsistent in that string indices should always be quoted--but then not in strings. So people tend to think that since "$_SERVER[PHP_SELF]" is OK, that $_SERVER[PHP_SELF] would be OK too--when it's not. It's more of an issue when giving examples and writing docs than for coding, really--but it doesn't hurt. The other reason is that the parser needs help resolving ambiguity with more complex expressions inside strings. If you use this syntax all the time, you won't get bitten in the butt later. Check this out: array('bar' => 'baz')); echo "My Baz is $array[foo][bar]\n"; echo "My Baz is {$array['foo']['bar']}\n"; ?> Many times I've had to explain why the output is: My Baz is Array[bar] My Baz is baz -- Torben Wilson <[EMAIL PROTECTED]> http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP_SELF Undefined
> $foo = "This page is $_SERVER[PHP_SELF]"; > > Or, better: > > $foo = "This page is {$_SERVER['PHP_SELF']}"; > > You do have to concat to do this in single-quoted (noninterpolated) > strings, though. > > http://www.php.net/manual/en/language.types.string.php#language.types.string .parsing Can you expand on why the first option isn't generally acceptable? I can understand there being an issue with spaces in an index, but is there some other reason that the latter is prefered? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
FW: [PHP] PHP_SELF Undefined
You probably do not have register globals set to on, this is often times set to off for security purposes. Instead you can use $_GET, $_POST, $SERVEr, etc, these are documented on the PHP website. Also instead of echoing all that HTML from PHP you should consider jumping out of PHP and then use PHP just to echo your variable. Example: Feedback Your Name: Your E-Mail Address: Your Message: mailto:[EMAIL PROTECTED]] Sent: Monday, February 18, 2002 3:51 PM To: [EMAIL PROTECTED] Subject: [PHP] PHP_SELF Undefined When I execute the code below, why is PHP_SELF undefined? I will appretiate any help on this. I can get its value by: echo $_SERVER["PHP_SELF"];Thanks in advance! -Teresa Feedback Your Name: Your E-Mail Address: Your Message: "; ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP_SELF Undefined
On Mon, 2002-02-18 at 15:02, Erik Price wrote: > > On Monday, February 18, 2002, at 05:50 PM, Narvaez, Teresa wrote: > > > When I execute the code below, why is PHP_SELF undefined? I will > > appretiate > > any help on this. I can get its value by: > > echo $_SERVER["PHP_SELF"];Thanks in advance! -Teresa > > > > > > > > > > Feedback > > > > > > > $form_block = " > > > ^ > > It hasn't been pulled from the $_SERVER array. It worked for you when > you did it the first way, so try doing it that same way in the code: > > > > Note that I had to "jump out" of the string and concatenate it to the > variable, because PHP doesn't let you just use $_* variables in the > middle of a string. I also made sure to "jump back into" the string to > finish the HTML form tag. Sorry, but I do have to correct you here--this isn't true. ;) In double- quoted strings and heredocs, you can do the following: $foo = "This page is $_SERVER[PHP_SELF]"; Or, better: $foo = "This page is {$_SERVER['PHP_SELF']}"; You do have to concat to do this in single-quoted (noninterpolated) strings, though. http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing Cheers, Torben > If you don't like doing it this way, do something like > > $PHP_SELF = $_SERVER['PHP_SELF']; > $form_block = ""; > > > HTH > > Erik -- Torben Wilson <[EMAIL PROTECTED]> http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP_SELF Undefined
On Monday, February 18, 2002, at 05:50 PM, Narvaez, Teresa wrote: > When I execute the code below, why is PHP_SELF undefined? I will > appretiate > any help on this. I can get its value by: > echo $_SERVER["PHP_SELF"];Thanks in advance! -Teresa > > > > > Feedback > > > $form_block = " > ^ It hasn't been pulled from the $_SERVER array. It worked for you when you did it the first way, so try doing it that same way in the code: Note that I had to "jump out" of the string and concatenate it to the variable, because PHP doesn't let you just use $_* variables in the middle of a string. I also made sure to "jump back into" the string to finish the HTML form tag. If you don't like doing it this way, do something like $PHP_SELF = $_SERVER['PHP_SELF']; $form_block = ""; HTH Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP_SELF Undefined
When I execute the code below, why is PHP_SELF undefined? I will appretiate any help on this. I can get its value by: echo $_SERVER["PHP_SELF"];Thanks in advance! -Teresa Feedback Your Name: Your E-Mail Address: Your Message: "; ?>