private - nested classes php or other method


I am looking for a method like the suggested php >=5.6 nested classes.


class Parent {

   public function call(){
       return new $this->Child;

    class Child {



Basically what I'm looking to do is something like




You can do something similar in JavaScript ex:

function Secure(){

     return {
   Encryption: function(){

I want to have private members only accesible to theEncryption member. I know that nested classes are not possible yet so I'm looking for an alternative

People are also looking for solutions to the problem: php - CakePHP Posting Error


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.