PHP Version Not Specified Warning In CodeSniffer

13th October 2008 - 2 minutes read time

In my last post I talked about the PHP CodeSniffer, so today I thought I would solve a common problem that doesn't seem to have any documentation. Whilst correcting a class file I had there was this one warning that just wouldn't go away.

FILE: myclass.php
--------------------------------------------------------------------------------
FOUND 0 ERROR(S) AND 1 WARNING(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
 11 | WARNING | PHP version not specified
--------------------------------------------------------------------------------

There is no documentation (that I could find) on the CodeSniffer site about how to solve this, so I dove into the source files for the CodeSniffer extension and found this line.

 * PHP Version 5

Add this to the file docs at the top of your file. You can change the version to be more specific if you wish, so if your class required at least PHP version 5.0.1 then use this as the version. I hope this little snippet helps someone.

Additionally, if this doesn't work then try using:

 * PHP version 5

With a lower case v on the version.

Comments

Permalink
This helped me, that's for dang sure!

Xedecimal (Wed, 01/28/2009 - 04:14)

Permalink

Thanks for this. In addition, had to add the version information before the php doc tags to keep the warning from showing up.

Anonymous (Wed, 06/01/2011 - 07:21)

Permalink
This feels really unnecessary. I'd rather not include the PHP version. It doesn't seem to offer any value.

Darek Kowalski (Sat, 02/06/2016 - 01:02)

Permalink
I agree with you there. Adding the major version of PHP seems irrelevant to me as well. It felt the same when I wrote this 9 years ago.

Add new comment

The content of this field is kept private and will not be shown publicly.