php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #79111 is_numeric documentation utterly incomplete
Submitted: 2020-01-13 16:07 UTC Modified: 2020-01-13 17:17 UTC
From: php4fan at gmail dot com Assigned:
Status: Closed Package: Variables related
PHP Version: Irrelevant OS: all
Private report: No CVE-ID: None
 [2020-01-13 16:07 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-13 17:16 UTC] cmb@php.net
-Package: Documentation problem +Package: Variables related
 [2020-01-13 17:17 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2021-08-22 17:41 UTC] deleugyn+php at gmail dot com
https://github.com/php/doc-en/pull/870
 [2021-12-02 17:56 UTC] git@php.net
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
 [2021-12-02 17:56 UTC] git@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Jan 27 02:05:53 2023 UTC