RE: [PHP-DEV] PHP parser behavior.
| From: | Chris Newbill | Date: | Wed, 21 Mar 2001 04:18:27 +0000 |
| Subject: | RE: [PHP-DEV] PHP parser behavior. | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-49585@lists.php.net to get a copy of this message | ||
As far as I know this is expected behavior.
Multiple dimensional arrays will cause a parse error no matter how you do
them if encapsulated inside a string. You would have to concatenate the
values like so.
$str = "This is a test, the value is " . $array["field"][0] . ". I repeat
this is a test.";
My general rule of thumb, is if it is a single dimension array I put it
inside the string without quotes, outside of the array single or not, I
always use quotes. Otherwise if I had a constant called "field" I would not
get what I was expecting.
-Chris
-----Original Message-----
From: Yasuo Ohgaki [mailto:yohgaki@hotmial.com]
Sent: Tuesday, 20 March, 2001 8-17 pM
To: php-dev@lists.php.net
Subject: [PHP-DEV] PHP parser behavior.
I didn't get responses for post in php-general, php-lang.....
I noticed that PHP4.0.4pl1 under Linux/Apache DSO and PHP4.0.5-RC1 under
W2K/IIS5 CGI accepts and does not raise error (notice messages) for
following
code.
$arr = array('first' => 'one');
$str = "This is first element of array: $arr[first]"; // Without quotations
Question: Is this expected behavior that PHP parse w/o errors?
If this is NOT a expected behavior or subject to change.. I would like to
know,
since I'll handle all error messages for production system including notice
messages.
Thank you.
PS:
$str = "This is first element of array: $arr['first']"; // I prefer this
syntax,
but this line cause parse error.
Using {} may be the best way to work with assoc arrays in strings, but
$arr[first] is a bit easier to read than {$arr['first']}.
--
Yasuo Ohgaki
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net
For additional commands, e-mail: php-dev-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net