Answer the question
In order to leave comments, you need to log in
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();
}
}
<?php
class Route {
function test() {
echo $this->action[1];
echo $this->template;
}
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question