Php basic questions
Class Test1 {static private $ _ name;} $ _ test1 = new Test1 ('Zhang San'); var_dump ($ _ test1 );
The page outputs:
Object (Test1) #1 (0 ){}
I also passed parameters during the instantiation, but I didn't write the constructor _ construct () in the Test1 class. why isn't an error reported?
Reply to discussion (solution)
The constructor is not required either. if you pass the parameter in, it will not be executed.
The constructor is known. you do not define that it is null.
The constructor is not required either. if you pass the parameter in, it will not be executed.
The foundation is not very good. could you give me a simple example? thank you!
Class Test1 {static private $ _ name; public $ _ date; public function _ construct () {$ this-> _ date = 123 ;}} $ _ test1 = new Test1 ('Zhang San'); var_dump ($ _ test1 );
Do I remember executing the constructor when instantiating the class?
Why does the parameter not match?
However
Class Test1 {
Static private $ _ name;
}
The constructor _ construct is not defined.
Class Test1 {private static $ _ name; public $ _ date; public function _ construct ($ name) {$ this-> _ date = 123; self :: $ _ name = $ name;} function output () {return self: $ _ name. '-'. $ this-> _ date ;}$ _ test1 = new Test1 ('Zhang San'); echo $ _ test1-> output ();