1

Since php does not support private classes, what naming conventions are there to denote them?

I've seen people use classes starting with underscore _ but have been told to keep away from such standard since its been from the old PHP 4 days.

Any alternatives?

2
  • How can you have a private class? A private method, which can be called from within the class alone is one thing, but if a class were to be private, how would you even instantiate it? Commented Mar 23, 2017 at 21:45
  • I still use _ (underscore) for private and __ for magic / reserved things. Heard of Hungarian notation? Looser languages and IDEs you don't see much of that anymore. I respect devs that name things well. Commented Mar 23, 2017 at 21:50

1 Answer 1

2

PHP doesn't have private classes but if you're using PHP7+ you can use anonymous classes.

class MyClass { private function getPrivateClass() { return new class { protected $property = "I'm a private class"; public function getProperty() { return $this->property; } }; } } 
Sign up to request clarification or add additional context in comments.

2 Comments

I'm interested in any naming conventions used for private classes.
@BasilMusa Private classes are not a common pattern in PHP (in part because it's not supported by the language). I've actually never heard of it used in PHP at all. As such I don't think there is any naming convention.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.