-
Notifications
You must be signed in to change notification settings - Fork 804
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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>. | ||||||
Dereferencing a scalar value ields &null;. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
</para> | ||||||
</note> | ||||||
</sect3> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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;. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
|
||
</para> | ||
</note> | ||
</refsect1> | ||
<refsect1 role="parameters"> | ||
&reftitle.parameters; | ||
|
There was a problem hiding this comment.
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.