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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jonathan dot poelen+php at gmail dot com
New email:
PHP Version: OS:

 

 [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-2021 The PHP Group
All rights reserved.
Last updated: Wed Apr 14 17:01:23 2021 UTC