Confusing call to class and method in OpenCart

I have a controller class (OpenCart) Controller (for example: catalog / controller / product / product.php), the code looks like this:

class ControllerProductProduct extends Controller {
    public function index() {
      //some code
      $this->response->setOutput($this->render());
      //some more code
    }
}

there is an expression of type $this->response->setOutput($this->render());. I know what this expression is used for, but I'm very confused about how it works.

$thisrefers to the current ie class ControllerProductProduct, this means that the object $this->responsemust exist either in ControllerProductProductor in its parent class Controller. But this is not so. This object does exist in the protected property of the parent class Controlleras Controller::registry->data['response']->setOutput(). Therefore, one should not say so:

$this->registry->data['response']->setOutput();

instead of $ This-> response-> setOutput ();

I also give a fragment of the class Controllerso you can think.

abstract class Controller {
    protected $registry;    
    //Other Properties
    public function __construct($registry) {
        $this->registry = $registry;
    }
    public function __get($key) {
        //get() returns registry->data[$key];
        return $this->registry->get($key);
    }
    public function __set($key, $value) {
        $this->registry->set($key, $value);
    }
    //Other methods
}

, ? , ?

.

+5
2

, __get() __set().

(, ), __get('property_name') .

, $response, __get() $this->registry->get('response') ( $response).

, $this->registry->get('response')->setOutput($this->render()); , . , PHP , __get(), .

, .

EDIT: :

class Controller {
    //...
    function getResponse() {
        return $this->registry->get('response');
    }
    //...
}

, :

class ControllerProductProduct extends Controller {
    public function index()
        //...
        $this->getResponse()->setOutput($this->render());
    }
}

, getXYZ, __get() $registry ( , , $register getProperty(), / ).

+1

"".
:

<?php

class PropsDemo 
{
    private $registry = array();

    public function __set($key, $value) {
        $this->registry[$key] = $value;
    }

    public function __get($key) {
        return $this->registry[$key];
    }
}

$pd = new PropsDemo;
$pd->a = 1;
echo $pd->a;

http://php.net/manual/en/language.oop5.overloading.php. .

0

All Articles