Answer the question
In order to leave comments, you need to log in
What is the right way, if possible, to call a class inside another class?
In class " B " I can't call a function of class " A ". To call it, you need to redefine it $a = new A() in the " B " class. How can I call so as not to override? or maybe you need to somehow correctly describe the class " A "?
index.php
$a = new A();
$b = new B();
class A {
public function print_tst() {
echo "tst";
}
}
class B {
function __construct() {
$a->print_tst();
}
}
Answer the question
In order to leave comments, you need to log in
1) static class A
here
who and how should guess what a is an instance of class A? respectively:class B { function __construct() { $a->print_tst(); } }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question