Edit report at https://pear.php.net/bugs/bug.php?id=19695&edit=1

ID: 19695
Comment by: njh@aelius.com
Reported By: rjt at zygous dot co dot uk
Summary: PSR-1 Namespace sniff - false positive for PHP5.2
style namespacing
Status: Bogus
Type: Bug
Package: PHP_CodeSniffer
Operating System: Linux
Package Version: SVN
PHP Version: 5_4 SVN-2012-11-07
Assigned To: squiz
Roadmap Versions:
New Comment:

Just a note that this is a problem for me too. My library (EasyRdf) is
still being used by people running PHP 5.2 and people using old style
name-spacing on PHP 5.3.

Would it be possible to work something into the test that says if class
contains underscores but the path matches it, then it is ok?

Something like:
implode(DIRECTORY_SEPARATOR, explode('_', 'Foo_Bar')).'.php' ==

Previous Comments:

[2012-11-11 22:21:37] squiz

Yes, the mailing list for the PHP FIG seems like it doesn't like
receiving mail, which is
a little odd given they have released a common PHP coding standard to
community. A great thing, but you're obviously going to get feedback.

Still, I'd ask there because it isn't the sort of call I could make as
I'm not a voting
member. If the authors of the standard decide to relax things and just
say that both
methods of namespacing are fine, then it's just a little bit of code to


[2012-11-09 08:31:06] zygous

Would it be worth honouring the PEAR comment if that's present? From
what I've read of the PSRs I don't think that would be in contravention,
would it? Any means necessary to identify the target PHP version...

We have a lot of code written before PHP 5.3 that we're now running on
5.3 servers. It all works, so there's no reason to change namespacing,
and I believe it's PSR compliant in all other regards. It wasn't written
for 5.3, so needn't use 'real' namespaces.

I know the mailing list is fed-up of discussing. PSRs 1 and 2, but
perhaps iI should raise this on the list...

I'm not offended by the bogus status :-) Oh, and good job on the


[2012-11-08 23:18:43] squiz

-Status: Feedback
+Status: Bogus
Yeah, it would be good if the PSR standards said something about
documenting the
min PHP version. PEAR has a requirement for this inside the file comment
on each
PHP file, but documentation is not covered at all by the PSRs.

Hopefully this will change one day, but maybe PHP5.2 support will be
dropped before
then anyway. THe PSRs seems to move a little slowly.

Wish I had a Not a Bug status, but I only have Bogus. Please don't be


[2012-11-08 12:19:41] zygous

Yep, that all makes sense. It's a shame there's no PHPDoc tag to specify
a minimum required PHP version that PHPCS could check. Having to
maintain a custom set of sniffs would be a bit of a nuisance.

I guess this report can be resolved as not-a-bug then.


[2012-11-07 21:44:50] squiz

-Status: Open
+Status: Feedback
-Assigned To:
+Assigned To: squiz
The reason you are seeing that error is because you are running PHPCS
using a
version of PHP that supports namespaces.

PSR-1 states that if code is written for 5.3 and after then is MUST use
But there is nothing that will actually tell me what version of PHP your
code is
supposed to support. The only thing I can check is the PHP version.

So my problem when doing this sniff was that I have to throw an error
(the use of
MUST means error, not warning) if you are using old-style namespacing
for code
meant to run under PHP 5.3+. If I see old-style namespacing and I don't
throw an
error, I could be hiding a really important error message and that would
probably be
a bigger mistake.

If you know that you'll always be running PHP_CodeSniffer using PHP
5.3+, you can
write your own standard that mutes this particular error message. Or you
can run
PHP_CodeSniffer using the lowest PHP version that your code supports
(seems like
PHP 5.2 in this case).

If you want to create your own standard, create a file somewhere called
example) mystandard.xml and make the contents:
<?xml version="1.0"?>
<ruleset name="MyStandard">
<description>My custom coding standard.</description>
<rule ref="PSR2"/>
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">

Then you can run PHP_CodeSniffer like this:
phpcs --standard=/path/to/mystandard.xml /path/to/code


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 2 | next ›
Discussion Overview
grouppear-bugs @
postedJan 7, '13 at 11:58a
activeJan 7, '13 at 8:42p

2 users in discussion

Njh: 1 post Gsherwood: 1 post



site design / logo © 2022 Grokbase