svn: /phpdoc/en/trunk/appendices/migration70/ new-features.xml
| From: | Adam Harvey | Date: | Sun, 09 Aug 2015 01:16:59 +0000 |
| Subject: | svn: /phpdoc/en/trunk/appendices/migration70/ new-features.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-13549@lists.php.net to get a copy of this message | ||
aharvey Sun, 09 Aug 2015 01:16:59 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=337366
Log:
Cut down the migration guide scalar type declaration section.
All of the variations and examples defined there are shown in the reworked type
declaration reference, so let's not duplicate this unnecessarily.
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:55 UTC (rev 337365)
+++ phpdoc/en/trunk/appendices/migration70/new-features.xml 2015-08-09 01:16:59 UTC (rev 337366)
@@ -5,16 +5,17 @@
<title>New features</title>
<sect2 xml:id="migration70.new-features.scalar-type-declarations">
- <title>Scalar Type Declarations</title>
+ <title>Scalar type declarations</title>
<para>
- Scalar type declarations come in two flavours: coercive (default) and
- strict. The following types for parameters can now be enforced (either
- coercively or strictly): strings (<type>string</type>), integers
- (<literal>int</literal>), floating-point numbers (<type>float</type>),
- and booleans (<literal>bool</literal>). They augment the other types
- introduced in the PHP 5.x versions: class names, interfaces,
- <type>array</type> and <type>callable</type>.
+ Scalar
+ <link linkend="functions.arguments.type-declarations">type
declarations</link>
+ come in two flavours: coercive (default) and strict. The following types
+ for parameters can now be enforced (either coercively or strictly): strings
+ (<type>string</type>), integers (<literal>int</literal>),
floating-point
+ numbers (<type>float</type>), and booleans (<literal>bool</literal>).
They
+ augment the other types introduced in PHP 5: class names, interfaces,
+ <type>array</type> and <type>callable</type>.
</para>
<informalexample>
@@ -48,49 +49,11 @@
</para>
<para>
- If the type-check fails, then a
TypeError exception is thrown. The only
- leniency present in strict typing is the automatic conversion of integers to
- floats (but not vice-versa) when an integer is provided in a float context.
+ Full documentation and examples of scalar type declarations can be found in
+ the
+ <link linkend="functions.arguments.type-declarations">type
declaration</link>
+ reference.
</para>
-
- <informalexample>
- <programlisting role="php">
-<![CDATA[
-<?php
-
-declare(strict_types=1);
-
-function multiply(float $x, float $y)
-{
- return $x * $y;
-}
-
-function add(int $x, int $y)
-{
- return $x + $y;
-}
-
-var_dump(multiply(2, 3.5));
-var_dump(add('2', 3));
-]]>
- </programlisting>
- &example.outputs;
- <screen>
-<![CDATA[
-float(7)
-Fatal error: Uncaught TypeError: Argument 1 passed to add() must be of the type integer, string
given...
-]]>
- </screen>
- </informalexample>
-
- <para>
- Note that only the invocation context applies when the type-checking is
- performed. This means that the strict typing applies only to function or method
- calls, and not to the function or method definitions. In the above example, the
- two functions could have been declared in either a strict or coercive file, but
- so long as they're being called in a strict file, then the strict typing rules
- will apply.
- </para>
</sect2>
<sect2 xml:id="migration70.new-features.return-type-declarations">