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:

<?php
$array('default' => '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

Reply via email to