Public method access problems. & Lt ;? Php & nbsp; classA {publicfunctionpp () {return1300; & nbsp;} publicfunction _ construct () {echo1 ;}& nbsp; classB {& nbsp; public method access problems.
Class {
Public function pp (){
Return 1300;
}
Public function _ construct (){
Echo 1;
}
}
Class B {
Public function _ construct (){
// Echo A :__ construct ();
// Echo A: pp ();
}
}
$ Cc = new C;
?>
Question:
Pp is A public method of class A, so it can be accessed by class name + double colon. The question is, why does the _ construct method in class A go to A :__ construct () the following error is reported during the call:
Fatal error: Non-static method A :__ construct () cannot be called statically, assuming $ this from incompatible context in D: \ wamp \ www \ 1.php on line 12
There is another problem, for example: [B] [/B]
Class {
Public $ m = 10;
}
Since $ m is public, internal class access, subclass access, and instance access should be supported.
I have seen in some books that they can be accessed "anywhere. I would like to ask if there are any other unrelated classes (classes that do not have an inheritance relationship with A). how can I access them if they support access? How do I write the code?
------ Solution --------------------
Static method or instantiation
The code above instantiates access like this
PHP code
class A{ public $mm=10;}class B{ protected $classA; public function __construct($number){ $this->classA=$number; echo $this->classA; }}$aa=new A;$bb=new B($aa->mm);