svn: /phpdoc/en/trunk/language/types/ array.xml pseudo-types.xml

From: Date: Mon, 12 Mar 2012 05:06:15 +0000
Subject: svn: /phpdoc/en/trunk/language/types/ array.xml pseudo-types.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-9860@lists.php.net to get a copy of this message
vrana Mon, 12 Mar 2012 05:06:15 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=324121 Log: Omissions and best practices Changed paths: U phpdoc/en/trunk/language/types/array.xml U phpdoc/en/trunk/language/types/pseudo-types.xml Modified: phpdoc/en/trunk/language/types/array.xml =================================================================== --- phpdoc/en/trunk/language/types/array.xml 2012-03-11 23:41:48 UTC (rev 324120) +++ phpdoc/en/trunk/language/types/array.xml 2012-03-12 05:06:15 UTC (rev 324121) @@ -42,6 +42,13 @@ <!-- Do not fix the whitespace for the synopsis end element. A limitation of PhD prevents proper trimming --> <para> + It is possible to write a comma after last element or omit it. Result is + the same, <literal>array(1, 2) === array(1, 2,)</literal>. Writing comma + after last element is useful mainly when formatting array definition on + multiple lines (see next example). + </para> + + <para> As of PHP 5.4 you can also use the short array syntax, which replaces <literal>array()</literal> with <literal>[]</literal>. </para> @@ -53,13 +60,13 @@ <?php $array = array( "foo" => "bar", - "bar" => "foo" + "bar" => "foo", ); // as of PHP 5.4 $array = [ "foo" => "bar", - "bar" => "foo" + "bar" => "foo", ]; ?> ]]> @@ -356,7 +363,17 @@ <para> If <varname>$arr</varname> doesn't exist yet, it will be created, so this is - also an alternative way to create an <type>array</type>. To change a certain + also an alternative way to create an <type>array</type>. This practice is + however discouraged because if <varname>$arr</varname> already contains + some value (e.g. <type>string</type> from request variable) then this + value will stay in the place and <literal>[]</literal> may actually stand + for <link linkend="language.types.string.substr">string access + operator</link>. It is always better to initialize variable by a direct + assignment. + </para> + + <para> + To change a certain value, assign a new value to that element using its key. To remove a key/value pair, call the <function>unset</function> function on it. </para> @@ -385,7 +402,7 @@ <para> As mentioned above, if no key is specified, the maximum of the existing <type>integer</type> indices is taken, and the new key will be that maximum - value plus 1. If no <type>integer</type> indices exist yet, the key will + value plus 1 (but at least 0). If no <type>integer</type> indices exist yet, the key will be <literal>0</literal> (zero). </para> Modified: phpdoc/en/trunk/language/types/pseudo-types.xml =================================================================== --- phpdoc/en/trunk/language/types/pseudo-types.xml 2012-03-11 23:41:48 UTC (rev 324120) +++ phpdoc/en/trunk/language/types/pseudo-types.xml 2012-03-12 05:06:15 UTC (rev 324121) @@ -59,6 +59,8 @@ Static class methods can also be passed without instantiating an <type>object</type> of that class by passing the class name instead of an <type>object</type> at index 0. + As of PHP 5.2.3, it is also possible to pass + <literal>'ClassName::methodName'</literal>. </para> <para>

« previous php.doc.cvs (#9860) next »