8000 Fix type juggling notes for list() and array destructuring by tgr · Pull Request #3680 · php/doc-en · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix type juggling notes for list() and array destructuring #3680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy state 8000 ment. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
5 changes: 1 addition & 4 deletions language/types/array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,7 @@ $secondElement = getArray()[1];
</note>
<note>
<para>
Array dereferencing a scalar value which is not a <type>string</type>
yields &null;. Prior to PHP 7.4.0, that did not issue an error message.
As of PHP 7.4.0, this issues <constant>E_NOTICE</constant>;
as of PHP 8.0.0, this issues <constant>E_WARNING</constant>.
Copy link
Contributor

Choose a reason for hiding this comment

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

This was about array dereferencing ($a = 42; $a[0]) not destructuring ([$a] = 42;), and I think it was correct. Only destructuring weirdly yields null with no warning.

10000
Dereferencing a scalar value ields &null;.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Dereferencing a scalar value ields &null;.
Dereferencing a scalar value yields &null;.

</para>
</note>
</sect3>
Expand Down
14 changes: 14 additions & 0 deletions reference/array/functions/list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@
the numerical indices start at 0.
</para>
</note>
<note>
<para>
Attempting to access an array key which has not been defined is
the same as accessing any other undefined variable:
an <constant>E_WARNING</constant>-level error message
(<constant>E_NOTICE</constant>-level prior to PHP 8.0.0) will be
issued, and the result will be &null;.
</para>
</note>
<note>
<para>
Attempting to access element of a scalar value yields &null;.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would say: "Attempting to unpack a scalar value assigns null to all variables." to be consistent with the existing wording.

There's also already a note above: "Strings can not be unpacked" which should probably say "Only arrays and objects that implement ArrayAccess can be unpacked".

And an example below, where the comment could be clarified:

// list() doesn't work with strings
list($bar) = "abcde";
var_dump($bar); // NULL

</para>
</note>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
Expand Down
0