[8.0] Document remaining core changes

* document changes to `new` in php 8.0

* document php 8.0 changes for `instanceof`

* document php 8.0 change to `define`

Co-authored-by: Peter Cowburn <petercowburn@gmail.com>

Closes GH-1155.
This commit is contained in:
Dan 2021-12-14 12:34:40 -05:00 committed by GitHub
parent 5dfba3d91f
commit c36ce0b514
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 93 additions and 0 deletions

View file

@ -165,6 +165,53 @@ $instance = new $className(); // new SimpleClass()
]]>
</programlisting>
</example>
<para>
As of PHP 8.0.0, using <literal>new</literal> with arbitrary expressions
is supported. This allows more complex instantiation if the expression
produces a <type>string</type>. The expressions must be wrapped in parentheses.
</para>
<example>
<title>Creating an instance using an arbitrary expression</title>
<para>
In the given example we show multiple examples of valid arbitrary expressions that produce a class name.
This shows a call to a function, string concatenation, and the <constant>::class</constant> constant.
</para>
<programlisting role="php">
<![CDATA[
<?php
class ClassA extends \stdClass {}
class ClassB extends \stdClass {}
class ClassC extends ClassB {}
class ClassD extends ClassA {}
function getSomeClass(): string
{
return 'ClassA';
}
var_dump(new (getSomeClass()));
var_dump(new ('Class' . 'B'));
var_dump(new ('Class' . 'C'));
var_dump(new (ClassD::class));
?>
]]>
</programlisting>
&example.outputs.8;
<screen>
<![CDATA[
object(ClassA)#1 (0) {
}
object(ClassB)#1 (0) {
}
object(ClassC)#1 (0) {
}
object(ClassD)#1 (0) {
}
]]>
</screen>
</example>
<para>
In the class context, it is possible to create a new object by
<literal>new self</literal> and <literal>new parent</literal>.

View file

@ -2717,6 +2717,44 @@ var_dump(FALSE instanceof stdClass);
<screen>
<![CDATA[
bool(false)
]]>
</screen>
</example>
</para>
<para>
As of PHP 8.0.0, <literal>instanceof</literal> can now be used with arbitrary expressions.
The expression must be wrapped in parentheses and produce a <type>string</type>.
<!-- RFC: https://wiki.php.net/rfc/variable_syntax_tweaks -->
<example>
<title>Using <literal>instanceof</literal> with an arbitrary expression</title>
<programlisting role="php">
<![CDATA[
<?php
class ClassA extends \stdClass {}
class ClassB extends \stdClass {}
class ClassC extends ClassB {}
class ClassD extends ClassA {}
function getSomeClass(): string
{
return ClassA::class;
}
var_dump(new ClassA instanceof ('std' . 'Class'));
var_dump(new ClassB instanceof ('Class' . 'B'));
var_dump(new ClassC instanceof ('Class' . 'A'));
var_dump(new ClassD instanceof (getSomeClass()));
?>
]]>
</programlisting>
&example.outputs.8;
<screen>
<![CDATA[
bool(true)
bool(true)
bool(false)
bool(true)
]]>
</screen>
</example>

View file

@ -67,6 +67,8 @@
<warning>
<simpara>
Defining case-insensitive constants is deprecated as of PHP 7.3.0.
As of PHP 8.0.0, only <literal>false</literal> is an acceptable value, passing
<literal>true</literal> will produce a warning.
</simpara>
</warning>
<note>
@ -99,6 +101,12 @@
</row>
</thead>
<tbody>
<row>
<entry>8.0.0</entry>
<entry>
Passing &true; to <parameter>case_insensitive</parameter> now emits an <constant>E_WARNING</constant>. Passing &false; is still allowed.
</entry>
</row>
<row>
<entry>7.3.0</entry>
<entry>