svn: /phpdoc/en/trunk/appendices/migration70/ new-features.xml

From: Date: Sun, 09 Aug 2015 01:16:46 +0000
Subject: svn: /phpdoc/en/trunk/appendices/migration70/ new-features.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-13546@lists.php.net to get a copy of this message
aharvey Sun, 09 Aug 2015 01:16:46 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=337363 Log: Move scalar and return typing up, since that's probably what people care about. Changed paths: U phpdoc/en/trunk/appendices/migration70/new-features.xml Modified: phpdoc/en/trunk/appendices/migration70/new-features.xml =================================================================== --- phpdoc/en/trunk/appendices/migration70/new-features.xml 2015-08-09 01:16:42 UTC (rev 337362) +++ phpdoc/en/trunk/appendices/migration70/new-features.xml 2015-08-09 01:16:46 UTC (rev 337363) @@ -4,101 +4,6 @@ <sect1 xml:id="migration70.new-features" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>New features</title> - <sect2 xml:id="migration70.new-features.null-coalesce-op"> - <title>Null coalesce operator</title> - - <para> - The null coalesce operator (<literal>??</literal>) has been added as - syntactic sugar for the common case of needing to use a ternary in - conjunction with <function>isset</function>. It returns its first operand - if it exists and is not &null;; otherwise it returns its second operand. - </para> - - <informalexample> - <programlisting role="php"> -<![CDATA[ -<?php -// Fetches the value of $_GET['user'] and returns 'nobody' -// if it does not exist. -$username = $_GET['user'] ?? 'nobody'; -// This is equivalent to: -$username = isset($_GET['user']) ? $_GET['user'] : 'nobody'; - -// Coalesces can be chained: this will return the first -// defined value out of $_GET['user'], $_POST['user'], and -// 'nobody'. -$username = $_GET['user'] ?? $_POST['user'] ?? 'nobody'; -?> -]]> - </programlisting> - </informalexample> - - <!-- TODO: we don't need further details here, but this still has to be - added to the operator precedence table --> - </sect2> - - <sect2 xml:id="migration70.new-features.spaceship-op"> - <title>Spaceship operator</title> - <para> - The spaceship operator is used for comparing two expressions. It returns an - <type>integer</type> less than, equal to, or greater than zero when - <varname>$a</varname> is respectively less than, equal to, or greater than - <varname>$b</varname>. Comparisons are performed according to PHP's usual - <link linkend="types.comparisons">type comparison rules</link>. - </para> - <informalexample> - <programlisting role="php"> -<![CDATA[ -<?php -// Integers -echo 1 <=> 1; // 0 -echo 1 <=> 2; // -1 -echo 2 <=> 1; // 1 - -// Floats -echo 1.5 <=> 1.5; // 0 -echo 1.5 <=> 2.5; // -1 -echo 2.5 <=> 1.5; // 1 - -// Strings -echo "a" <=> "a"; // 0 -echo "a" <=> "b"; // -1 -echo "b" <=> "a"; // 1 -?> -]]> - </programlisting> - </informalexample> - - <!-- TODO: we don't need further details here, but this still has to be - added to the operator precedence table --> - </sect2> - - <sect2 xml:id="migration70.new-features.define-array"> - <title>Constant arrays using <function>define</function></title> - - <para> - <type>Array</type> constants can now be defined with - <function>define</function>. In PHP 5.6, they could only be defined with - &const;. - </para> - - <informalexample> - <programlisting role="php"> -<![CDATA[ -<?php -define('ANIMALS', [ - 'dog', - 'cat', - 'bird' -]); - -echo ANIMALS[1]; // outputs "cat" -?> -]]> - </programlisting> - </informalexample> - </sect2> - <sect2 xml:id="migration70.new-features.scalar-type-declarations"> <title>Scalar Type Declarations</title> @@ -187,6 +92,7 @@ will apply. </para> </sect2> + <sect2 xml:id="migration70.new-features.return-type-declarations"> <title>Return Type Declarations</title> @@ -312,6 +218,101 @@ not a valid return type - only an instance of the class A can be returned. </para> </sect2> + + <sect2 xml:id="migration70.new-features.null-coalesce-op"> + <title>Null coalesce operator</title> + + <para> + The null coalesce operator (<literal>??</literal>) has been added as + syntactic sugar for the common case of needing to use a ternary in + conjunction with <function>isset</function>. It returns its first operand + if it exists and is not &null;; otherwise it returns its second operand. + </para> + + <informalexample> + <programlisting role="php"> +<![CDATA[ +<?php +// Fetches the value of $_GET['user'] and returns 'nobody' +// if it does not exist. +$username = $_GET['user'] ?? 'nobody'; +// This is equivalent to: +$username = isset($_GET['user']) ? $_GET['user'] : 'nobody'; + +// Coalesces can be chained: this will return the first +// defined value out of $_GET['user'], $_POST['user'], and +// 'nobody'. +$username = $_GET['user'] ?? $_POST['user'] ?? 'nobody'; +?> +]]> + </programlisting> + </informalexample> + + <!-- TODO: we don't need further details here, but this still has to be + added to the operator precedence table --> + </sect2> + + <sect2 xml:id="migration70.new-features.spaceship-op"> + <title>Spaceship operator</title> + <para> + The spaceship operator is used for comparing two expressions. It returns an + <type>integer</type> less than, equal to, or greater than zero when + <varname>$a</varname> is respectively less than, equal to, or greater than + <varname>$b</varname>. Comparisons are performed according to PHP's usual + <link linkend="types.comparisons">type comparison rules</link>. + </para> + <informalexample> + <programlisting role="php"> +<![CDATA[ +<?php +// Integers +echo 1 <=> 1; // 0 +echo 1 <=> 2; // -1 +echo 2 <=> 1; // 1 + +// Floats +echo 1.5 <=> 1.5; // 0 +echo 1.5 <=> 2.5; // -1 +echo 2.5 <=> 1.5; // 1 + +// Strings +echo "a" <=> "a"; // 0 +echo "a" <=> "b"; // -1 +echo "b" <=> "a"; // 1 +?> +]]> + </programlisting> + </informalexample> + + <!-- TODO: we don't need further details here, but this still has to be + added to the operator precedence table --> + </sect2> + + <sect2 xml:id="migration70.new-features.define-array"> + <title>Constant arrays using <function>define</function></title> + + <para> + <type>Array</type> constants can now be defined with + <function>define</function>. In PHP 5.6, they could only be defined with + &const;. + </para> + + <informalexample> + <programlisting role="php"> +<![CDATA[ +<?php +define('ANIMALS', [ + 'dog', + 'cat', + 'bird' +]); + +echo ANIMALS[1]; // outputs "cat" +?> +]]> + </programlisting> + </informalexample> + </sect2> <sect2 xml:id="migration70.new-features.anonymous-classes"> <title>Anonymous Classes</title>

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