Req #79762 [Com]: ord should throw ValueError exception on empty string
| From: | raincomplain at outlook dot com | Date: | Wed, 01 Jul 2020 01:32:12 +0000 |
| Subject: | Req #79762 [Com]: ord should throw ValueError exception on empty string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227751@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79762&edit=1
ID: 79762
Comment by: raincomplain at outlook dot com
Reported by: raincomplain at outlook dot com
Summary: ord should throw ValueError exception on empty
string
Status: Feedback
Type: Feature/Change Request
Package: Strings related
PHP Version: 8.0.0alpha1
Block user comment: N
Private report: N
New Comment:
ord will return non-Boolean value which evaluates to FALSE
ord("\u{0000}") // 0
This makes returning false sub-optimal, anyhow mb_ord already throws ValueError so I think it would
be proper for ord to throw an exception just like mb_ord.
Previous Comments:
------------------------------------------------------------------------
[2020-07-01 01:13:02] requinix@php.net
Throwing an exception seems rather extreme. Is there a problem with returning false like many other
functions already do?
------------------------------------------------------------------------
[2020-07-01 00:21:49] raincomplain at outlook dot com
Description:
------------
Empty string in PHP doesn't equal U+0000 which is why mb_ord will not return 0 when passing
empty string. On the other hand, ord will not complain about passing empty string. I know ord is not
aware of any string encoding but this behavior however leads to a wrong assumption that empty string
=== U+0000 which in turn leads to bugs like https://bugs.php.net/bug.php?id=69162
So one might think if
var_dump(ord('') === 0); // true
And
var_dump(ord("\u{0000}") === 0); // true
Then the following must be true
var_dump("\u{0000}" === ''); // false
Test script:
---------------
var_dump(ord(''));
Expected result:
----------------
Fatal error: Uncaught ValueError: ord(): Argument #1 ($str) must not be empty
Actual result:
--------------
int(0)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79762&edit=1