-
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 statement. 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?
Conversation
Update notes about the handling of missing keys and non-arrays during array destructuring to match the behavior seen on 3v4l.org, which doesn't issue a warning or notice in some cases where the documentation claims it does. Also update list() docs to provide the same information. list(): * missing key: https://3v4l.org/bYBt6 * destructuring an integer: https://3v4l.org/7lNhK * a boolean: https://3v4l.org/p5LDd * a string: https://3v4l.org/KHSAH * null: https://3v4l.org/lk1iu array notation: * missing key: https://3v4l.org/KCiTC * destructuring an integer: https://3v4l.org/louVG * a boolean: https://3v4l.org/SWL5L * a string: https://3v4l.org/aK90L * null: https://3v4l.org/Y8cOY Fixes php#3640.
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>. |
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.
</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 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
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.
Sorry it has taken us so long to review this; thanks for the patch, one small issue (and please rebase)
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Dereferencing a scalar value ields &null;. | |
Dereferencing a scalar value yields &null;. |
Update notes about the handling of missing keys and non-arrays during array destructuring to match the behavior seen on 3v4l.org, which doesn't issue a warning or notice in some cases where the documentation claims it does. Also update list() docs to provide the same information.
list():
array notation:
Fixes #3640.