How to load a class inside the function in PHP?
I have a class already load inside __construct()
of my page, aft开发者_如何学编程er that once again I want to load this class, inside another function. Here is my code.
<?php
class MainClass {
public $config;
public function __construct($config) {
$this->config = $config;
}
public function routes() {
// here I need to load the config class
}
}
?>
inside routes function i want to call an array form config class file
Your $config
is already loaded as a property of the object, since you passed it in the constructor. If you need to access the $config
from another member function, just use $this->config->whatever
public function routes() {
//here i need to load the config class
$something = $this->config->somearray[0];
}
public function routes() {
require_once "/path/to/YourClass.php"
$your_class_instance = new YourClass();
}
精彩评论