> -----Original Message-----
> From: Chris Hayes [mailto:[EMAIL PROTECTED]
> Sent: 25 June 2003 12:02
> 
> At 10:08 25-6-03, you wrote:
> 
> >Harry Wiens wrote:
> >>What would be the correct syntax?
> >>1. $_SESSION[test]
> >
> >in this case "test" is a constant and must be defined
> >by calling define("test", some_integer_value) before
> 
> But PHP is extremely tolerant and if it cannot find a defined 
> constant 
> called test, or if the array is between double quotes, PHP 
> will read thsi 
> as if it is $_SESSION['test'];
> 
> example: echo " bla    $_SESSION[test]   bla ";

In a double-quoted string, PHP does *not* look for a constant called "test"
in this situation.

Outside strings, it does -- and whilst it's true that if the constant is
undefined PHP will substitute the equivalent string, this is bad practice on
two counts: (1) what if you forget you've done it and at a later date add a
define for a constant called 'test' with some other value? (2) your script
will run fractionally slower because PHP is doing the extra, unnecessary,
constant lookup (may be only tiny per lookup, but if you have many of them
per script, it could add up).

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

Reply via email to