Is there anyway to create public or private or protected classes in a namespace just like java?
like…
namespace foo;
public class Account {
.......
}
private class PrivateAccount {
.......
}
please let me know if there is any workaround to do this in PHP.
Typically what you do is declare the constructor of the class private. Then you can create a separate static function in the class that will do some checks (i.e. check the namespace) and conditionally return an instance of the class by calling the private constructor. This is also typically how you implement singletons.