|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2021-09-18 05:26 UTC] gib-o-master at mail dot ru
Description:
------------
previous was marked as spam. this is a language problem, not spam.
Test script:
---------------
if (chr(48)) {
echo 'never happen';
}
if (chr(0)) {
echo 'always happen';
}
Expected result:
----------------
never happen
always happen
Actual result:
--------------
always happen
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 19 15:00:01 2025 UTC |
i doubt that '0' or chr(48) should be given special powers, it's not intuitive for JS/Python folks that rely on common behavior. if ($string) {# '0' will not pass here } $x = $string ?: 'default';# '0' will not be selected as $x if ([0]) {# will not look into array but string will }another inconvenience i encounter with '0' is when i need to check for mixed empty values returned (falsy checks) function func(): string|array|int {...} if (!($a = func()) # '0' will enter which is not intended {...} if (!($a = func()) && $a !== '0') # this is correct variant {...} so it's always have to be double checks if there is a string.