Types are not hints in PHP. (#1003)

As they are checked at run-time, type checking is enforced in PHP and not 'hinted'.

Co-authored-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Danack 2021-10-09 14:43:01 +01:00 committed by GitHub
parent 21129de174
commit b95e76e41d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 38 additions and 41 deletions

View file

@ -502,7 +502,7 @@ echo add(...$a);
It is also possible to add a
<link linkend="language.types.declarations">type declaration</link> before the
<literal>...</literal> token. If this is present, then all arguments
captured by <literal>...</literal> must be objects of the hinted class.
captured by <literal>...</literal> must match that parameter type.
<example>
<title>Type declared variable arguments</title>

View file

@ -1186,7 +1186,7 @@ $a = new stdClass;
namespace foo;
$a = new \stdClass;
function test(\ArrayObject $typehintexample = null) {}
function test(\ArrayObject $parameter_type_example = null) {}
$a = \DirectoryIterator::CURRENT_AS_FILEINFO;
@ -1213,10 +1213,10 @@ namespace foo;
class MyClass {}
// using a class from the current namespace as a type hint
function test(MyClass $typehintexample = null) {}
// another way to use a class from the current namespace as a type hint
function test(\foo\MyClass $typehintexample = null) {}
// using a class from the current namespace as a parameter type
function test(MyClass $parameter_type_example = null) {}
// another way to use a class from the current namespace as a parameter type
function test(\foo\MyClass $parameter_type_example = null) {}
// extending a class from the current namespace
class Extended extends MyClass {}

View file

@ -12,9 +12,11 @@
<section xml:id="datetimeinterface.intro">
&reftitle.intro;
<para>
DateTimeInterface is meant so that both DateTime and DateTimeImmutable can
be type hinted for. It is not possible to implement this interface with
userland classes.
<interfacename>DateTimeInterface</interfacename> was created
so that parameter, return, or property type declarations may accept either
<classname>DateTime</classname> or <classname>DateTimeImmutable</classname>
as a value. It is not possible to
implement this interface with userland classes.
</para>
</section>
<!-- }}} -->

View file

@ -55,13 +55,6 @@
<para>
&null; may be passed instead, to reset this handler to its default state.
</para>
<caution>
<para>
Note that providing an explicit <classname>Exception</classname> type
hint for the <parameter>ex</parameter> parameter in your callback will
cause issues with the changed exception hierarchy in PHP 7.
</para>
</caution>
</listitem>
</varlistentry>
</variablelist>

View file

@ -11,7 +11,7 @@
&reftitle.intro;
<para>
This interface is implemented by <classname>MongoDB\BSON\Binary</classname>
but may also be used for type-hinting and userland classes.
to be used as a parameter, return, or property type in userland classes.
</para>
</section>

View file

@ -11,8 +11,8 @@
&reftitle.intro;
<para>
This interface is implemented by
<classname>MongoDB\BSON\Decimal128</classname> but may also be used for
type-hinting and userland classes.
<classname>MongoDB\BSON\Decimal128</classname> to be used as a parameter,
return, or property type in userland classes.
</para>
</section>

View file

@ -11,8 +11,8 @@
&reftitle.intro;
<para>
This interface is implemented by
<classname>MongoDB\BSON\Javascript</classname> but may also be used for
type-hinting and userland classes.
<classname>MongoDB\BSON\Javascript</classname> to be used as a parameter,
return, or property type in userland classes.
</para>
</section>

View file

@ -11,7 +11,7 @@
&reftitle.intro;
<para>
This interface is implemented by <classname>MongoDB\BSON\MaxKey</classname>
but may also be used for type-hinting and userland classes.
to be used as a parameter, return, or property type in userland classes.
</para>
</section>

View file

@ -11,7 +11,7 @@
&reftitle.intro;
<para>
This interface is implemented by <classname>MongoDB\BSON\MinKey</classname>
but may also be used for type-hinting and userland classes.
to be used as a parameter, return, or property type in userland classes.
</para>
</section>

View file

@ -11,8 +11,8 @@
&reftitle.intro;
<para>
This interface is implemented by
<classname>MongoDB\BSON\ObjectId</classname> but may also be used for
type-hinting and userland classes.
<classname>MongoDB\BSON\ObjectId</classname> to be used as a parameter,
return, or property type in userland classes.
</para>
</section>

View file

@ -11,7 +11,7 @@
&reftitle.intro;
<para>
This interface is implemented by <classname>MongoDB\BSON\Regex</classname>
but may also be used for type-hinting and userland classes.
to be used as a parameter, return, or property type in userland classes.
</para>
</section>

View file

@ -11,8 +11,8 @@
&reftitle.intro;
<para>
This interface is implemented by
<classname>MongoDB\BSON\Timestamp</classname> but may also be used for
type-hinting and userland classes.
<classname>MongoDB\BSON\Timestamp</classname> to be used as a
parameter, return, or property type in userland classes.
</para>
</section>

View file

@ -11,8 +11,8 @@
&reftitle.intro;
<para>
This interface is implemented by
<classname>MongoDB\BSON\UTCDateTime</classname> but may also be used for
type-hinting and userland classes.
<classname>MongoDB\BSON\UTCDateTime</classname> to be used as a
parameter, return, or property type in userland classes.
</para>
</section>

View file

@ -13,8 +13,8 @@
&reftitle.intro;
<para>
This interface is implemented by
<classname>MongoDB\Driver\Cursor</classname> but may also be used for
type-hinting and userland classes.
<classname>MongoDB\Driver\Cursor</classname> to be used as
a parameter, return, or property type in userland classes.
</para>
</section>
<!-- }}} -->

View file

@ -12,7 +12,7 @@
<section xml:id="mongodb-driver-monitoring-subscriber.intro">
&reftitle.intro;
<para>
Base interface for event subscribers. This is used for type-hinting
Base interface for event subscribers. This is used as a parameter type in the functions
<function>MongoDB\Driver\Monitoring\addSubscriber</function> and
<function>MongoDB\Driver\Monitoring\removeSubscriber</function> and should
not be implemented directly.

View file

@ -60,7 +60,9 @@
<term><parameter>type</parameter></term>
<listitem>
<para>
Provides a data type hint for drivers that have alternate quoting styles.
Provides a hint to the type of data for drivers that have alternate quoting
styles. For example <constant>PDO_PARAM_LOB</constant> will tell the driver to
escape binary data.
</para>
</listitem>
</varlistentry>

View file

@ -4,7 +4,7 @@
<refentry xml:id="reflectionnamedtype.getname" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>ReflectionNamedType::getName</refname>
<refpurpose>Get the text of the type hint</refpurpose>
<refpurpose>Get the name of the type as a string</refpurpose>
</refnamediv>
<refsect1 role="description">
@ -23,7 +23,7 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the text of the type hint.
Returns the name of the type being reflected.
</para>
</refsect1>

View file

@ -3,7 +3,7 @@
<refentry xml:id="reflectionparameter.getclass" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>ReflectionParameter::getClass</refname>
<refpurpose>Get the type hinted class</refpurpose>
<refpurpose>Get a <classname>ReflectionClass</classname> object for the parameter being reflected or &null;</refpurpose>
</refnamediv>
<refsynopsisdiv>
@ -17,7 +17,7 @@
<void/>
</methodsynopsis>
<para>
Gets the class type hinted for the parameter as a <classname>ReflectionClass</classname> object.
Gets a <classname>ReflectionClass</classname> object for the parameter being reflected or &null;.
</para>
<para>
As of PHP 8.0.0 this function is deprecated and not recommended. Instead, use

View file

@ -35,7 +35,7 @@
</row>
<row>
<entry>SNMP_VALUE_PLAIN</entry>
<entry>The return values will be the plain value without the SNMP type hint.</entry>
<entry>The return values will be the plain value without the SNMP type information.</entry>
</row>
<row>
<entry>SNMP_VALUE_OBJECT</entry>

View file

@ -189,7 +189,7 @@
<tgroup cols="2">
<tbody>
<row><entry><constant>SNMP_VALUE_LIBRARY</constant></entry><entry>The return values will be as returned by the Net-SNMP library.</entry></row>
<row><entry><constant>SNMP_VALUE_PLAIN</constant></entry><entry>The return values will be the plain value without the SNMP type hint.</entry></row>
<row><entry><constant>SNMP_VALUE_PLAIN</constant></entry><entry>The return values will be the plain value without the SNMP type information.</entry></row>
<row>
<entry><constant>SNMP_VALUE_OBJECT</constant></entry><entry>
The return values will be objects with the properties "value" and "type", where the latter

View file

@ -27,7 +27,7 @@
&reftitle.returnvalues;
<para>
The <type>array</type> of SOAP function prototypes, detailing the return type,
the function name and type-hinted parameters.
the function name and parameter types.
</para>
</refsect1>