> -----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