cvs: phpdoc /en/language types.xml
| From: | Sander Roobol | Date: | Tue, 07 May 2002 09:57:26 +0000 |
| Subject: | cvs: phpdoc /en/language types.xml | ||
| Groups: | php.doc | ||
| Request: | Send a blank email to phpdoc+get-969345330@lists.php.net to get a copy of this message | ||
sander Tue May 7 05:57:26 2002 EDT
Modified files:
/phpdoc/en/language types.xml
Log:
Clearify the array-do's-and-don'ts - thanks to Hugh W Prior (#17065)
Index: phpdoc/en/language/types.xml
diff -u phpdoc/en/language/types.xml:1.76 phpdoc/en/language/types.xml:1.77
--- phpdoc/en/language/types.xml:1.76 Tue Apr 9 05:32:23 2002
+++ phpdoc/en/language/types.xml Tue May 7 05:57:26 2002
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.76 $ -->
+<!-- $Revision: 1.77 $ -->
<chapter id="language.types">
<title>Types</title>
@@ -1204,7 +1204,9 @@
<sect3 id="language.types.array.foo-bar">
<title>Why is <literal>$foo[bar]</literal> wrong?</title>
<para>
- You might have seen the following syntax in old scripts:
+ You should always use quotes around an associative array index.
+ For example, use $foo['bar'] and not $foo[bar]. But why is $foo[bar]
+ wrong? You might have seen the following syntax in old scripts:
<informalexample>
<programlisting role="php">
<![CDATA[
@@ -1214,8 +1216,14 @@
]]>
</programlisting>
</informalexample>
- This is wrong, but it works. Then, why is it wrong? The reason is
- that, as stated in the <link linkend="language.types.array.syntax"
+ This is wrong, but it works. Then, why is it wrong? The reason is that
+ this code has an undefined constant (bar) rather than a string ('bar' -
+ notice the quotes), and PHP may in future define constants which,
+ unfortunately for your code, have the same name. It works, because the
+ undefined constant gets converted to a string of the same name.
+ </para>
+ <para>
+ As stated in the <link linkend="language.types.array.syntax"
>syntax</link> section, there must be an expression between the
square brackets ('<literal>[</literal>' and
'<literal>]</literal>').
That means that you can write things like this: