php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69557 Unexpected error message using "use" operator before the "namespace" keyword
Submitted: 2015-05-01 04:49 UTC Modified: 2015-05-01 06:51 UTC
From: me at paulofreitas dot me Assigned:
Status: Not a bug Package: PHP Language Specification
PHP Version: 5.6.8 OS: N/A
Private report: No CVE-ID: None
 [2015-05-01 04:49 UTC] me at paulofreitas dot me
Description:
------------
As stated, if you try to use the "use" operator to import something before declaring the file namespace, you'll get an unexpected error message which doesn't actually explain the real issue.

Test script:
---------------
To reproduce the bug: http://3v4l.org/Qc9UO

Expected result: http://3v4l.org/XOGsn (you get the idea...)

Expected result:
----------------
Fatal error: Namespace declaration statement has to be the very first statement in the script in test.php on line 5

Actual result:
--------------
Fatal error: Class 'Foo\Bar' not found in test.php on line 7

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-05-01 06:09 UTC] stas@php.net
-Status: Open +Status: Not a bug
 [2015-05-01 06:09 UTC] stas@php.net
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


 [2015-05-01 06:33 UTC] me at paulofreitas dot me
Citing "How to Report a Bug" page...

"Don't report an error message you don't understand as a bug. There are a lot of places you can ask for help in understanding what is going on before you can claim that an error message you do not understand is a bug."

That's not the case.

"(Now, once you've understood the error message, and have a good suggestion for a way to make the error message more clear, you might consider reporting it as a feature request.)"

Neither that.

It's clearly an unexpected and undocumented behavior per namespaces docs:

"Namespaces are declared using the namespace keyword. A file containing a namespace must declare the namespace at the top of the file before any other code - with one exception: the declare keyword."

(from http://php.net/manual/en/language.namespaces.definition.php)
 [2015-05-01 06:51 UTC] stas@php.net
This is not a bug in PHP language specification. This also doesn't seem to be a bug in general, as use declarations do not produce any code and as such do not really matter for namespace declaration. If you want to discuss it more, you are welcome to raise the topic on the internals list.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Sep 20 03:03:36 2021 UTC