2

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?

Tim Rogers
  • 426
  • 5
  • 14

1 Answers1

2

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.

Community
  • 1
  • 1
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
  • Good spot on the Scope Resolution Operator manual page. On the basis that self, parent and static are special keywords and that special keywords must be a subset of all keywords and that PSR-12 states that all keywords must be in lower case, I conclude that the PSR-12 standards mandate that self must be in lower case and I have accepted your answer. It's still a mystery why there are so many downvotes against the comment on the keywords manual page suggesting that self, parent and static should be included in the list of PHP keywords. – Tim Rogers Dec 06 '19 at 23:44