What is the naming convention for protected/private members?

#1

I’ve been trying to find if there is a CakePHP naming convention for private and protected class members.

This isn’t part of the official coding style as it likely doesn’t really affect the end-user. However, since we are trying to following CakePHP conventions to keep issues minimal, I was curious if there was an internal/informal standard for this.

I seen in some cases that an _ is used for both protected fields/variables and methods. However, this isn’t consistent. I see a mix of _ and regular names in classes. Is there a standard that new code follows even if some old code is mixed?

#2

You could just look through some of the vendor code to see, for example.

But browse more files.

#3

Like I said, it is inconsistent. I guess that means it is random.

#4

In a nutshell, CakePHP uses PSR-2 with a few additions/changes. One of the legacy issues of this, is that many protected/private members use a underscore prefix, but newer code does not (Since it would not be good for BC to remove the existing ones). Using underscores is still PSR-2 compliant since PSR-2 only recommends not using them.

You can see the full CakePHP coding standard, and use the official CakePHP Codesniffer sniffs to automatically ensure your code follows the standard.