How to call a protected method in php?

前端 未结 4 2066
清酒与你
清酒与你 2021-01-22 14:28

here is the class structure. I want Observer:callme() to be callable from Children too.

class Observer
{
    protected callme()
    {
    }
}

class Parent exten         


        
4条回答
  •  故里飘歌
    2021-01-22 14:57

    I think I found the solution:

    class Parent extends Observer
    {
        function createChild()
        {
            $this->callme(); // this is OK
            return new Child (function() { $this->callme(); });
        }
    }
    
    class Child
    {
        private $gatewayFunction;
        public function __constructor (Closure $gatewayFunction)
        {
            $this->gatewayFunction = $gatewayFunction;
        }
    
        public function __destroy()
        {
            $this->gatewayFunction->__invoke();
        }
    }
    

    Who is going to crap himself? :)

提交回复
热议问题