Php basic questions

Source: Internet
Author: User
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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.