php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80716 bad regular expression for float format
Submitted: 2021-02-06 06:15 UTC Modified: -
From: jonathan dot poelen+php at gmail dot com Assigned:
Status: Open Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-02-06 06:15 UTC] jonathan dot poelen+php at gmail dot com
Description:
------------
---
From manual page: https://php.net/language.types.float
---

The bnf is:

LNUM          [0-9]+(_[0-9]+)*
DNUM          ([0-9]*(_[0-9]+)*[\.]{LNUM}) | ({LNUM}[\.][0-9]*(_[0-9]+)*)
EXPONENT_DNUM (({LNUM} | {DNUM}) [eE][+-]? {LNUM})

Unfortunately, these accept _123.45 or 123._45 as float. DNUM should be

DNUM          ({LNUM}?[\.]{LNUM}) | ({LNUM}[\.])

I think there is a missing float rule that combines DNUM and EXPONENT_DNUM.

float         {EXPONENT_DNUM} | {DNUM}

Finally, it seems strange to me to have [\.] instead of \. or [.] and the format used is not the same as on the integer page: https://www.php.net/manual/en/language.types.integer.php


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-02-23 16:36 UTC] php at yopmail dot com
If that can help: from https://github.com/php/php-src/blob/php-7.4.0/Zend/zend_language_scanner.l (still same in https://github.com/php/php-src/blob/php-8.0.2/Zend/zend_language_scanner.l ):

LNUM	[0-9]+(_[0-9]+)*
DNUM	({LNUM}?"."{LNUM})|({LNUM}"."{LNUM}?)
EXPONENT_DNUM	(({LNUM}|{DNUM})[eE][+-]?{LNUM})

and:

<ST_IN_SCRIPTING>{DNUM}|{EXPONENT_DNUM} {
	/* snip */
	RETURN_TOKEN_WITH_VAL(T_DNUMBER);
}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 09:01:29 2024 UTC