Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of inheritance of private attribute in php Class

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "the analysis of the inheritance of private attributes in the php class". In the daily operation, I believe that many people have doubts about the inheritance of private attributes in the php class. Xiaobian consulted all kinds of materials and sorted out simple and useful methods of operation. I hope it will be helpful for you to answer the doubts of "the inheritance analysis of private attributes in the php class". Next, please follow the editor to study!

Please read this sentence carefully if the parent class has private properties. Then the methods of the parent class only serve the private properties of the parent class.

The following is to deepen our understanding through a series of columns.

This example seems strange that a property $sal is redefined in the subclass, but the system returns the property of the parent class.

The copy code is as follows:

The result of running the program:

The copy code is as follows:

PHP 5.3.8

3000

Change the property $sal of the parent class to protected, and the subclass overrides the properties of the parent class. There is only one $sal in memory.

The copy code is as follows:

The result of running the program:

The copy code is as follows:

PHP 5.3.8

5000

If you have studied java, you will find all this difficult to understand.

In Java, when a subclass is created, the properties and methods of the parent class are created in memory, and even the constructor is called.

This is not the case with PHP5. PHP5 calls the parent class with parent:: instead of parent- >, which is enough to show that PHP5 does not want the parent class to be created in memory. PHP5 wants to make inheritance easier than Java.

At this point, the study on the analysis of the inheritance of private attributes in the php class is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report