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: 2025-04-25 08:39 UTC
From: jonathan dot poelen+php at gmail dot com Assigned: vrana (profile)
Status: Closed Package: *General Issues
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [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

Pull Requests

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);
}
 [2025-04-25 08:39 UTC] vrana@php.net
-Status: Open +Status: Closed -Package: Documentation problem +Package: *General Issues -Assigned To: +Assigned To: vrana
 [2025-04-25 08:39 UTC] vrana@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at
http://www.php.net/downloads.php

Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at
http://www.php.net/downloads.php
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 03:01:30 2025 UTC