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: Verified Package: Variables related
PHP Version: Irrelevant OS: all
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Oct 25 06:01:24 2020 UTC