php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70455 Missing constant: IntlChar::NO_NUMERIC_VALUE
Submitted: 2015-09-07 23:10 UTC Modified: 2015-09-08 00:23 UTC
From: colinodell@php.net Assigned:
Status: Closed Package: intl (PECL)
PHP Version: 7.0.0RC2 OS:
Private report: No CVE-ID: None
 [2015-09-07 23:10 UTC] colinodell@php.net
Description:
------------
IntlChar::getNumericValue() will return a "magic number" of float(-123456789) if no numeric value exists for the given code point.  This behavior is correct and consistent with both the underlying library and HHVM's implementation.

However, the ICU library defines a constant for this magic number called U_NO_NUMERIC_VALUE, which we'd map to IntlChar::NO_NUMERIC_VALUE.  However, PHP does not expose this constant.  I believe this is a bug because both ICU and HHVM refer to a constant for this value, but we don't. (And magic numbers are bad.)

I would therefore request that this constant be added/exposed as IntlChar::NO_NUMERIC_VALUE.  This name will match the current naming conventions as well as the name used by HHVM.

(HHVM references this constant in the source but doesn't expose it - I've submitted a corresponding report here: https://github.com/facebook/hhvm/issues/6209)

If you disagree with my assessment that this is a bug, then I respectfully request this be changed to a Feature/Change Request.

Test script:
---------------
See https://3v4l.org/48Bnh or run this yourself:

<?php

$value = IntlChar::getNumericValue("x");
var_dump($value);
var_dump($value === IntlChar::NO_NUMERIC_VALUE);

Expected result:
----------------
float(-123456789)
bool(true)

Actual result:
--------------
float(-123456789)

Fatal error: Uncaught Error: Undefined class constant 'NO_NUMERIC_VALUE' in /in/48Bnh:5
Stack trace:
#0 {main}
  thrown in /in/48Bnh on line 5

Process exited with code 255.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-08 00:04 UTC] cmb@php.net
An alternative might be to return FALSE instead, which seems to
be a common pattern to indicate failure in PHP.
 [2015-09-08 00:23 UTC] colinodell@php.net
> An alternative might be to return FALSE instead, which seems to
> be a common pattern to indicate failure in PHP.

While this does seem perfectly reasonable, it would deviate from the underlying library's behavior (which the RFC says should be adhered to) and HHVM's implementation.

I'm not necessarily against your idea, I'm just hesitant to jump on that implementation without considering these points first.
 [2016-04-08 08:03 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=93f8eaf3b8c9400f230dc904d52508882f83ee5f
Log: Fixed bug #70455 Missing constant: IntlChar::NO_NUMERIC_VALUE
 [2016-04-08 08:03 UTC] ab@php.net
-Status: Open +Status: Closed
 [2016-07-20 11:32 UTC] davey@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=93f8eaf3b8c9400f230dc904d52508882f83ee5f
Log: Fixed bug #70455 Missing constant: IntlChar::NO_NUMERIC_VALUE
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:29 2024 UTC