N
N
nindzja_ubiyza2016-08-01 13:20:32
PHP
nindzja_ubiyza, 2016-08-01 13:20:32

How to derive from one class the property of another?

Hello! There is a small class that loads various modules, and I need to get the values ​​​​of the properties of this class after the constructor passes:

<?php
class LOADER {
  public $conf;
  public $db;
  public $action;
  public $templater;
  public $test = "trololo";
  public $route;
  private $saying;
  
  function __construct() {
    require_once('core/class_configs.php');
    $this->conf = new CONFIGS();
    
    require_once('core/class_db.php');
    $this->db = new DB();
    
    $this->action = explode('/', $_SERVER['REQUEST_URI']);
    require_once('core/class_templater.php');
    $this->templater = new TEMPLATER();
    
    require_once('core/class_route.php');
    $this->route = new ROUTE();
  }

}

those. Here I want something like:
<?php
class Route {
    function test() {
        echo $this->action[1];
        echo $this->template;
    }
}

Can you please tell me how this can be implemented? Inheritance did not help, as I understand inheritance does not work for magic methods.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2016-08-01
@nindzja_ubiyza

Let's omit the sad words about the code, now I would like to understand - what and where do you want to call? You have 2 (described) classes, one creates an instance of the other, then what? How to call its properties? Create an instance of LOADER (why capitalized?) and then from it already $this->route->test(); (by the way, also capitalized in the constructor for some reason). Or the purpose to deduce from route the properties belonging to loader? Then this is nonsense, the router does not know (and should not) anything about the loader, if this is needed, it means "something went wrong" when designing the code, although this is already visible without such a deep analysis)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question