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

From: Date: Wed, 12 Nov 2014 12:52:18 +0000
Subject: Bug #68410 [Opn->Nab]: new \NumberFormatter does not work in namespace
References: 1  Groups: php.standards 
Request: Send a blank email to standards-+get-559@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68410&edit=1 ID: 68410 Updated by: daverandom@php.net 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

« previous php.standards (#559) next »