Bug #68410 [Opn->Nab]: new \NumberFormatter does not work in namespace

[email protected]
Newsgroups php.standards
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=68410&edit=1

 ID:                 68410
 Updated by:         [email protected]
 Reported by:        thomas at nunninger dot info
 Summary:            new \NumberFormatter does not work in namespace
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            PHP Language Specification
 Operating System:   Linux
 PHP Version:        5.6.2
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You are getting this error because you did not fully qualify the class name when you accessed the class constant that is being passed as and argument.

The below should resolve the problem:

<?php

namespace x;

$nf = new \NumberFormatter( 'de_DE', \NumberFormatter::PATTERN_DECIMAL );
var_dump( $nf );


Previous Comments:
------------------------------------------------------------------------
[2014-11-12 12:46:31] thomas at nunninger dot info

Description:
------------
If I have a namespace and call

    new \NumberFormatter(...)

inside the namespace I get

    Fatal error: Class 'x\NumberFormatter' not found in /home/thomas/test.php on line 7

If I add

    use \NumberFormatter;

it works.

BTW: I found this error in a class method. The reproducing script does not use classes.

Test script:
---------------
<?php

namespace x;

# use \NumberFormatter;

$nf = new \NumberFormatter( 'de_DE', NumberFormatter::PATTERN_DECIMAL );
var_dump( $nf );


Expected result:
----------------
object(NumberFormatter)#1 (0) {
}


Actual result:
--------------
Fatal error: Class 'x\NumberFormatter' not found in /home/thomas/test.php on line 7



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=68410&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.