Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions language/control-structures/foreach.xml
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,12 @@ foreach ($array as [, , $c]) {
</para>

<para>
A notice will be generated if there aren't enough array elements to fill
the <function>list</function>:
A warning will be generated if there aren't enough array elements to fill
the <function>list</function>.
Prior to PHP 8.0.0 a notice was generated instead:
Comment on lines +224 to +226

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A warning will be generated if there aren't enough array elements to fill
the <function>list</function>.
Prior to PHP 8.0.0 a notice was generated instead:
If there are not enough array elements to populate the variables,
a warning is emitted; prior to PHP 8.0.0, a notice was emitted instead:


<informalexample>
<programlisting role="php">
<programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
$array = [
Expand All @@ -238,13 +239,23 @@ foreach ($array as [$a, $b, $c]) {
}
]]>
</programlisting>
&example.outputs;
&example.outputs.71;
<screen>
<![CDATA[
Notice: Undefined offset: 2 in script on line 7
A: 1; B: 2; C:

Notice: Undefined offset: 2 in script on line 7
A: 3; B: 4; C:
]]>
</screen>
&example.outputs.8;
<screen>
<![CDATA[
Notice: Undefined offset: 2 in example.php on line 7
Warning: Undefined array key 2 in script on line 7
A: 1; B: 2; C:

Notice: Undefined offset: 2 in example.php on line 7
Warning: Undefined array key 2 in script on line 7
A: 3; B: 4; C:
]]>
</screen>
Expand Down
13 changes: 7 additions & 6 deletions language/oop5/anonymous.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ var_dump(new class(10) extends SomeClass implements SomeInterface {
&example.outputs;
<screen>
<![CDATA[
object(class@anonymous)#1 (1) {
["Command line code0x104c5b612":"class@anonymous":private]=>
object(SomeClass@anonymous)#1 (1) {
["num":"SomeClass@anonymous":private]=>
Comment on lines +66 to +67

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, I am not actually sure what's changed. I can see that PHP 8 uses the parent class name, but is this important? Is this intentional or just an implementation detail?

int(10)
}
]]>
Expand Down Expand Up @@ -153,11 +153,12 @@ same class
</informalexample>

<note>
<para>
<simpara>
Note that anonymous classes are assigned a name by the engine, as
demonstrated in the following example. This name has to be regarded an
implementation detail, which should not be relied upon.
</para>
implementation detail, which should not be relied upon. The generated name
contains a NUL byte, which is not visible in the output below.
Comment on lines +159 to +160

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the NUL byte? Is it always there? What's the significance of it?

</simpara>
<informalexample>
<programlisting role="php">
<![CDATA[
Expand All @@ -168,7 +169,7 @@ echo get_class(new class {});
&example.outputs.similar;
<screen>
<![CDATA[
class@anonymous/in/oNi1A0x7f8636ad2021
class@anonymousscript:2$0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference? Isn't it the same thing?

]]>
</screen>
</informalexample>
Expand Down
19 changes: 17 additions & 2 deletions language/oop5/magic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ Array
</para>
<example>
<title>Using <link linkend="object.set-state">__set_state()</link></title>
<programlisting role="php">
<programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php

Expand Down Expand Up @@ -524,7 +524,7 @@ var_dump($c);
?>
]]>
</programlisting>
&example.outputs;
&example.outputs.81;
<screen>
<![CDATA[
string(60) "A::__set_state(array(
Expand All @@ -537,6 +537,21 @@ object(A)#2 (2) {
["var2"]=>
string(3) "foo"
}
]]>
</screen>
&example.outputs.82;
<screen>
<![CDATA[
string(61) "\A::__set_state(array(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't even remember what this change was. Is this something that we document or is this an implementation detail?

'var1' => 5,
'var2' => 'foo',
))"
object(A)#2 (2) {
["var1"]=>
int(5)
["var2"]=>
string(3) "foo"
}
]]>
</screen>
</example>
Expand Down
55 changes: 28 additions & 27 deletions language/operators/precedence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -371,32 +371,6 @@ $array[$i] = $i++; // may set either index 1 or 2
]]>
</programlisting>
</example>
<example>
<title><literal>+</literal>, <literal>-</literal> and <literal>.</literal> precedence</title>
<programlisting role="php">
<![CDATA[
<?php
$x = 4;
// this line might result in unexpected output:
echo "x minus one equals " . $x-1 . ", or so I hope\n";

// the desired precedence can be enforced by using parentheses:
echo "x minus one equals " . ($x-1) . ", or so I hope\n";

// this is not allowed, and throws a TypeError:
echo (("x minus one equals " . $x) - 1) . ", or so I hope\n";
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
-1, or so I hope
-1, or so I hope
Fatal error: Uncaught TypeError: Unsupported operand types: string - int
]]>
</screen>
</example>
<example>
<title>Prior to PHP 8, <literal>+</literal>, <literal>-</literal> and <literal>.</literal> had the same precedence</title>
<programlisting role="php" annotations="non-interactive">
Expand All @@ -414,16 +388,43 @@ echo "x minus one equals " . ($x-1) . ", or so I hope\n";
?>
]]>
</programlisting>
&example.outputs;
&example.outputs.71;
<screen>
<![CDATA[
Warning: A non-numeric value encountered in script on line 4
-1, or so I hope

Warning: A non-numeric value encountered in script on line 7
-1, or so I hope
x minus one equals 3, or so I hope
]]>
</screen>
&example.outputs.8;
<screen>
<![CDATA[
x minus one equals 3, or so I hope

Fatal error: Uncaught TypeError: Unsupported operand types: string - int in script:7
Stack trace:
#0 {main}
thrown in script on line 7
]]>
</screen>
</example>
</para>
<simpara>
As of PHP 7.4.0 the first line also emits
<literal>Deprecated: The behavior of unparenthesized expressions containing
both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher
precedence</literal>.
</simpara>
<simpara>
As of PHP 8.0.0 the pitfall is gone, because <literal>-</literal> now binds
tighter than <literal>.</literal>.
The second line, which spells out the grouping that used to apply, throws a
<exceptionname>TypeError</exceptionname> instead, so the third line never
runs.
</simpara>
<note>
<para>
Although <literal>=</literal> has a lower precedence than
Expand Down
5 changes: 4 additions & 1 deletion language/operators/type.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ $c = fopen('/tmp/', 'r');
var_dump($a instanceof stdClass); // $a is an integer
var_dump($b instanceof stdClass); // $b is NULL
var_dump($c instanceof stdClass); // $c is a resource

// Prior to PHP 7.3.0 this was a compile-time error, so nothing above ran:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Prior to PHP 7.3.0 this was a compile-time error, so nothing above ran:
// Prior to PHP 7.3.0, using a constant would trigger a compile-time fatal error with the following message:

// instanceof expects an object instance, constant given
var_dump(FALSE instanceof stdClass);
?>
]]>
Expand All @@ -188,7 +191,7 @@ var_dump(FALSE instanceof stdClass);
bool(false)
bool(false)
bool(false)
PHP Fatal error: instanceof expects an object instance, constant given
bool(false)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but we need to retain the error message. Perhaps split it into two outputs per version? Or just add a code comment on var_dump(FALSE instanceof stdClass); saying it would throw with this error message?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took the code comment. A split would mislead here: prior to 7.3 this is a compile-time error, so 7.2 prints the fatal line and nothing else — none of the three bool(false) above it ever run. The screen that was here, three bools followed by the fatal error, was never any version's output.

That's why the comment says "so nothing above ran". The 7.3 boundary itself is already covered by the example directly below, which uses &example.outputs.73;.

]]>
</screen>
</example>
Expand Down
6 changes: 5 additions & 1 deletion language/predefined/backedenum/from.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ $b = Suit::from('B');
<![CDATA[
enum(Suit::Hearts)
Fatal error: Uncaught ValueError: "B" is not a valid backing value for enum "Suit" in /file.php:15
Fatal error: Uncaught ValueError: "B" is not a valid backing value for enum Suit in script:14
Stack trace:
#0 script(14): Suit::from('B')
#1 {main}
thrown in script on line 14
Comment on lines +74 to +78

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just like before, I don't think we should be documenting these stack traces. Just keep the first line and use &example.outputs.similar;

]]>
</screen>
</example>
Expand Down
29 changes: 24 additions & 5 deletions reference/mbstring/functions/mb-detect-encoding.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<para>
<example>
<title><function>mb_detect_encoding</function> example</title>
<programlisting role="php">
<programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php

Expand All @@ -158,7 +158,16 @@ var_dump(mb_detect_encoding($str, $encodings));
?>
]]>
</programlisting>
&example.outputs;
&example.outputs.82;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 8.2? What changed in 8.2 that we document the difference in output? I can see no related information on this page that would explain this.

I would lean towards rejecting this change. Unless we have a basis to add the split example, we should only document the current behaviour. For all I know, the change in behaviour came from a bug fix or some internal refactoring.

<screen>
<![CDATA[
bool(false)
bool(false)
string(8) "SJIS-win"
bool(false)
]]>
</screen>
&example.outputs.83;
<screen>
<![CDATA[
string(5) "ASCII"
Expand All @@ -172,13 +181,14 @@ string(5) "ASCII"
<para>
<example>
<title>Effect of <parameter>strict</parameter> parameter</title>
<programlisting role="php">
<programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
// 'áéóú' encoded in ISO-8859-1
$str = "\xE1\xE9\xF3\xFA";

// The string is not valid ASCII or UTF-8, but UTF-8 is considered a closer match
// The string is valid in neither encoding: non-strict reports the closest
// match, strict returns false
var_dump(mb_detect_encoding($str, ['ASCII', 'UTF-8'], false));
var_dump(mb_detect_encoding($str, ['ASCII', 'UTF-8'], true));

Expand All @@ -188,13 +198,22 @@ var_dump(mb_detect_encoding($str, ['ASCII', 'UTF-8', 'ISO-8859-1'], true));
?>
]]>
</programlisting>
&example.outputs;
&example.outputs.82;
<screen>
<![CDATA[
string(5) "UTF-8"
bool(false)
string(10) "ISO-8859-1"
string(10) "ISO-8859-1"
]]>
</screen>
&example.outputs.83;
<screen>
<![CDATA[
string(5) "ASCII"
bool(false)
string(10) "ISO-8859-1"
string(10) "ISO-8859-1"
]]>
</screen>
</example>
Expand Down
Loading