Doc #79111 [Ver->Csd]: is_numeric documentation utterly incomplete

[email protected] Thu, 02 Dec 2021 17:56:28 +0000
Newsgroups php.doc.bugs
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=79111&edit=1

 ID:                 79111
 Updated by:         [email protected]
 Reported by:        php4fan at gmail dot com
 Summary:            is_numeric documentation utterly incomplete
-Status:             Verified
+Status:             Closed
 Type:               Documentation Problem
 Package:            Variables related
 Operating System:   all
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

Automatic comment on behalf of deleugpn (author) and cmb69 (committer)
Revision: https://github.com/php/doc-en/commit/ff054fcb4e0c795093255f1e71be2cae68fc6284
Log: Fix #79111: is_numeric documentation utterly incomplete


Previous Comments:
------------------------------------------------------------------------
[2021-08-22 17:41:14] deleugyn+php at gmail dot com

https://github.com/php/doc-en/pull/870

------------------------------------------------------------------------
[2020-01-13 17:16:44] [email protected]

See also <https://wiki.php.net/rfc/trailing_whitespace_numerics>.

------------------------------------------------------------------------
[2020-01-13 16:07:00] php4fan at gmail dot com

Description:
------------
---
From manual page: https://php.net/function.is-numeric
---

I found out to my surprise that is_numeric(" 3") returns true, but is_numeric("3 ") returns false. Spaces at the beginning of a string have no effect; spaces at the end do, making the string not numeric.

Assuming that's the expected behavior, that's far from obvious and should be documented.

The docs say:
"Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part."

There's no mention whatsoever of spaces. From that description, taken literally, I'd expect a space at the beginning to ALSO be considered non-numeric. Short of that, I'd expect spaces to be either ignored both at the beginning and end or neither.

Test script:
---------------
echo is_numeric("3")?"Yes\n":"no\n";
echo is_numeric("   3")?"Yes\n":"no\n";
echo is_numeric("3 ")?"Yes\n":"no\n";

Expected result:
----------------
documentation should be exhaustive

Actual result:
--------------
documentation doesn't document the behavior properly.


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=79111&edit=1