Re: associative arrays: usage inside double-quoted strings: documentation gap

From: Date: Fri, 09 Mar 2001 23:53:52 +0000
Subject: Re: associative arrays: usage inside double-quoted strings: documentation gap
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-12144@lists.php.net to get a copy of this message
Jeroen van Wolffelaar writes: > Hi there, > > 'note sended succesfully'... though > it does not appear on the website. > (No caching at all, i'm 100% > certain!) I know, I deleted it. :) The replies all got lost in lala-land 'cause I didn't see your 'nospam' in time. This all needs to be updated in the manual--IMHO that whole section needs to be overhauled--but I personally don't have the time. The most important bits you've noted below, with a couple of mistakes: > I think it should be in de real doc. > I'm willing to write it, it will and should be quite short. > > (The (a) variant of writing associatad arrays is totally > undocumenten, but DOES appear is some doc-examples. The > inside-string variant is also very poorly documented) > > Will it then be added? I'm not going > to write something that isn't being added. > > <note section=arrays> > Named indices > > Note that > a) echo "Value of element foo in array arr is " . $arr[foo] a) should be documented as incorrect. It will work, in some cases. However, since the string index is unquoted, PHP will first attempt to match it to a keyword before interpreting it as a string. This will show up if you set error_reporting(E_ALL) in your script. You should always use quotes on your string indices in PHP. > b) echo "Value of element foo in array arr is " . $arr['foo'] > c) echo "Value of element foo in array arr is " . $arr["foo"] > d) echo "Value of element foo in array arr is $arr[foo]" > e) echo "Value of element foo in array arr is $arr['foo']" > f) echo "Value of element foo in array arr is $arr[\"foo\"]" > > a-d are equal, but e and f result in a > parse-error!! > </note> > > This behaviour (the (un)need for quotes with > named indices) is poorly documented. It only appears in some examples, without > any explanation. > > This parse error should be more > explainatory: > Parse error: parse error, expecting `T_STRING' or > T_VARIABLE' or T_NUM_STRING' > > > Greetz, > Jeroen > University of Utrecht > > ========== > Jeroen J.A. van Wolffelaar > Email: Jeroen@A-Eskwadraat.nl > Homepage: http://www.A-Eskwadraat.nl/~jeroen > Icq: 33944357 > EersteCie: http://www.A-Eskwadraat.nl/eerste - Ik zou het niet > op je eerste date vertellen... > IMo mailinglists moderator: imo2000-owner@egroups.com > ========== -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Adcore Finland| |http://www.coastnet.com/~torben http://www.adcore.com| |Ph: 1.604.709.0506 torben@adcore.com| +----------------------------------------------------------------+

« previous php.notes (#12144) next »