Hi there, Trying to improve PHP, and also its documentation.
I saw something on reddit's /r/lolphp (you can probably guess what it's for...) about the echo() "function". I decided to make a patch that better clarifies that it is not a function, and also doesn't leave the description of ... blank. It is attached.
It would be nice to have SVN access, eventually. :P Thanks. -- Andrew Faulds http://ajf.me/
--- en/reference/strings/functions/echo.xml +++ en/reference/strings/functions/echo.xml @@ -9,21 +9,28 @@ <refsect1 role="description"> &reftitle.description; <methodsynopsis> - <type>void</type><methodname>echo</methodname> + <type>void</type> <methodname>echo</methodname> <methodparam><type>string</type><parameter>arg1</parameter></methodparam> <methodparam choice="opt"><type>string</type><parameter>...</parameter></methodparam> </methodsynopsis> <simpara> - Outputs all parameters. + Outputs all parameters with no spaces inbetween. </simpara> <para> - <literal>echo</literal> is not actually a function (it is a - language construct), so you are not required to use parentheses - with it. <literal>echo</literal> (unlike some other language - constructs) does not behave like a function, so it cannot - always be used in the context of a function. Additionally, if you want to - pass more than one parameter to <literal>echo</literal>, the parameters - must not be enclosed within parentheses. + <literal>echo</literal> is not a function, it is a + language construct, and so it does not use parentheses round arguments. Be warned, looks can be deceptive: + <informalexample> + <programlisting role="php"> +<![CDATA[ +// works, equivalent to: echo "test"; +echo("test"); +// doesn't work +echo("john", " ", "smith"); +// works +echo "john", " ", "smith"; +]]> + </programlisting> + </informalexample> </para> <para> <literal>echo</literal> also has a shortcut syntax, where you can @@ -49,7 +56,7 @@ <term><parameter>arg1</parameter></term> <listitem> <para> - The parameter to output. + Parameter to output. </para> </listitem> </varlistentry> @@ -57,6 +64,7 @@ <term><parameter>...</parameter></term> <listitem> <para> + Other parameters to output. </para> </listitem> </varlistentry> @@ -111,6 +119,9 @@ echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', chr(10); echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . "\n"; +// However, beware that echo is not a function, this is a syntax error: +echo ('This ', 'statement ', 'will ', 'not ', 'work.'); + echo <<<END This uses the "here document" syntax to output multiple lines with $variable interpolation. Note