Is self a keyword in PHP and therefore should it be in lower case according to PSR-12?

154 views Asked by At

The PHP manual does not include self in its list of keywords. A comment on the manual page suggests that self should be included, but it has been significantly downvoted. Does that mean that self is not a keyword?

The reason this matters is that the PSR-12 specification on coding style states that all PHP reserved keywords and types must be in lower case. The specification contains two links to lists of reserved keywords and types, but self does not appear in either of them. Does that mean that PSR-12 is silent on whether self should be lower case?

1

There are 1 answers

1
Nigel Ren On BEST ANSWER

If you look at the page about the the Scope Resolution Operator (::), it states that

Three special keywords self, parent and static are used to access properties or methods from inside the class definition.

So although the keyword page doesn't acknowledge them, other pages in the manual seem to have a different opinion. Unless the fact they are special means something.

As to if it's part of the PSR-12, although I can't answer this, you would generally see these three special keywords in lower case (not sure if I've ever seen them any other way) and so more would stick to this rather than care if a standard decrees it or not.