Answer the question
In order to leave comments, you need to log in
Sharing a variable across all php classes?
How to make such a task possible:
- for example, there are classes with the same methods - provide. How can I make the $title variable available in each of these class methods ? And also when changing it in one of the methods, did it change for other methods with the same value?
Answer the question
In order to leave comments, you need to log in
class TitleProvider {
private $title;
public function getTitle() { return $this->title; }
public function setTitle($title) { $this->title = $title;}
}
class Foo {
private $titleProvider;
public function __construct(TitleProvider $titleProvider){
$this->titleProvider;
}
}
Create another class:
class MyVar {
public static $title;
}
public function provide(){
MyVar::$title = 'Hello world!';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question