[PHP] foo[bar] _or_ foo['bar'] ?

2001-02-13 Thread Matthias Krehl

Hi there!

I'd really appreciate a clear statement whether to use better

$foo = array('bar' = 'boing');
doWhatSoEver($foo[bar]);

or

$foo = array('bar' = 'boing');
doWhatSoEver($foo['bar']);

Someone to know that?

bye Matthias


Matthias Krehl
[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] foo[bar] _or_ foo['bar'] ?

2001-02-13 Thread Phil Driscoll

This is the correct format:
doWhatSoEver($foo['bar']);

If your error reporting level is set high enough, php will complain about
$foo[bar] unless you have defined bar as a constant elsewhere.
--
Phil Driscoll
Dial Solutions
+44 (0)113 294 5112
http://www.dialsolutions.com
http://www.dtonline.org




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] foo[bar] _or_ foo['bar'] ?

2001-02-13 Thread Derek Sivers


I'd really appreciate a clear statement whether to use better
$foo = array('bar' = 'boing');
 doWhatSoEver($foo[bar]);
or
$foo = array('bar' = 'boing');
 doWhatSoEver($foo['bar']);


I had heard someone on the list say that it's always best to use quotes, 
for the same reason as XHTML, where every value MUST have quotes.

But honestly I've been using only NO-quotes all year and find it much 
easier to read.  And NEVER any problem!

Also makes it easier when you need to use an array variable inside a quoted 
string:

print "Hello there $client[name]";



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] foo[bar] _or_ foo['bar'] ?

2001-02-13 Thread Phil Driscoll

Bad practice alert!!!

Derek Sivers wrote:
I had heard someone on the list say that it's always best to use quotes,
for the same reason as XHTML, where every value MUST have quotes.

But honestly I've been using only NO-quotes all year and find it much
easier to read.  And NEVER any problem!

Also makes it easier when you need to use an array variable inside a quoted
string:

print "Hello there $client[name]";

If your php error reporting level is set to show warnings (which it should
be on your development machines) then referring to
$foo[bar]
will give
Warning: Use of undefined constant bar - assumed 'bar' in
whatever/yourscript.php on line n

So php only works in this case because it couldn't find bar in it's list of
constants, and guessed at the mistake you made. This just slows things down.

I can't see any advantage at all to missing the quotes out.

Your example could be written

print "Hello there {$client['name']}";

Sorry to sound stroppy :)

Cheers
--
Phil Driscoll
Dial Solutions
+44 (0)113 294 5112
http://www.dialsolutions.com
http://www.dtonline.org


-Original Message-
From: Derek Sivers [EMAIL PROTECTED]
To: Matthias Krehl [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED] [EMAIL PROTECTED]
Date: Tuesday, February 13, 2001 5:34 PM
Subject: Re: [PHP] foo[bar] _or_ foo['bar'] ?



I'd really appreciate a clear statement whether to use better
$foo = array('bar' = 'boing');
 doWhatSoEver($foo[bar]);
or
$foo = array('bar' = 'boing');
 doWhatSoEver($foo['bar']);





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] foo[bar] _or_ foo['bar'] ?

2001-02-13 Thread php3

Addressed to: Derek Sivers [EMAIL PROTECTED]
  "Matthias Krehl" [EMAIL PROTECTED]
  [EMAIL PROTECTED]

** Reply to note from Derek Sivers [EMAIL PROTECTED] Tue, 13 Feb 2001 09:31:29 -0800


 I'd really appreciate a clear statement whether to use better
 $foo = array('bar' = 'boing');
  doWhatSoEver($foo[bar]);
 or
 $foo = array('bar' = 'boing');
  doWhatSoEver($foo['bar']);


 I had heard someone on the list say that it's always best to use quotes,
 for the same reason as XHTML, where every value MUST have quotes.

 But honestly I've been using only NO-quotes all year and find it much
 easier to read.  And NEVER any problem!

 Also makes it easier when you need to use an array variable inside a quoted
 string:

 print "Hello there $client[name]";

Several people have mentioned that this is a bad practice, but no one
has mentioned why...

There are two gotchas you have to look out for, that quotes will
prevent.  First, if you are using some_word as an array index and
someone decides that it would be a good name for a built in function,
constant, or statement all of a sudden all of your programs will break.

Second, take one of your programs that uses some_word all over it, and
add:

define( 'some_word', 'something_else' );

into one of your include files, now life gets very interesting:


$X[ 'some_word' ] = 'foo';
$X[ 'something_else' ] = 'bar';

echo $X[ some_word ];  // prints  bar

echo $X[ 'some_word' ];  // always works as expected.




Rick Widmer
Internet Marketing Specialists
http://www.developersdesk.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] foo[bar] _or_ foo['bar'] ?

2001-02-13 Thread Andi Gutmans

$foo[bar] only works for backwards compatibility. In fact writing bar 
without '' means that it's a constant and if that constant value is defined 
it will be substituted instead of the bar. If it's not defined it defaults 
to the string 'bar'.
So if you want to do it right (and faster) do $foo['bar']

Andi

At 05:48 PM 2/13/2001 +, Phil Driscoll wrote:
Bad practice alert!!!

Derek Sivers wrote:
 I had heard someone on the list say that it's always best to use quotes,
 for the same reason as XHTML, where every value MUST have quotes.
 
 But honestly I've been using only NO-quotes all year and find it much
 easier to read.  And NEVER any problem!
 
 Also makes it easier when you need to use an array variable inside a quoted
 string:
 
 print "Hello there $client[name]";

If your php error reporting level is set to show warnings (which it should
be on your development machines) then referring to
$foo[bar]
will give
Warning: Use of undefined constant bar - assumed 'bar' in
whatever/yourscript.php on line n

So php only works in this case because it couldn't find bar in it's list of
constants, and guessed at the mistake you made. This just slows things down.

I can't see any advantage at all to missing the quotes out.

Your example could be written

print "Hello there {$client['name']}";

Sorry to sound stroppy :)

Cheers
--
Phil Driscoll
Dial Solutions
+44 (0)113 294 5112
http://www.dialsolutions.com
http://www.dtonline.org


-Original Message-
From: Derek Sivers [EMAIL PROTECTED]
To: Matthias Krehl [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED] [EMAIL PROTECTED]
Date: Tuesday, February 13, 2001 5:34 PM
Subject: Re: [PHP] foo[bar] _or_ foo['bar'] ?


 
 I'd really appreciate a clear statement whether to use better
 $foo = array('bar' = 'boing');
  doWhatSoEver($foo[bar]);
 or
 $foo = array('bar' = 'boing');
  doWhatSoEver($foo['bar']);
 
 
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 
 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]