Req #81456 [Com]: chr(48) is falsy
Edit report at https://bugs.php.net/bug.php?id=81456&edit=1
ID: 81456
Comment by: a at b dot c dot de
Reported by: gib-o-master at mail dot ru
Summary: chr(48) is falsy
Status: Not a bug
Type: Feature/Change Request
Package: *General Issues
PHP Version: 8.0.10
Block user comment: N
Private report: N
New Comment:
chr(48) evaluates to the string "0". This is defined and documented as falsy and always
has been; you're complaining about "giving" it "special powers" when what
you're actually asking for is taking away properties that it has always had. It is something
that PHP newbies are frequently surprised by and frequently complain about, but really turns out not
to be a big deal if you pay attention to what you're doing.
This is also not JavaScript nor Python. Apologies if this means that programming in three languages
means more mental work for you than programming in two.
Previous Comments:
------------------------------------------------------------------------
[2021-09-18 06:19:28] gib-o-master at mail dot ru
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
}
------------------------------------------------------------------------
[2021-09-18 06:03:18] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
------------------------------------------------------------------------
[2021-09-18 05:26:58] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81456&edit=1
Thread (9 messages)