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

Example Analysis of PHP object-oriented programming and reflective API

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

Share

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

This article is about sample analysis of reflective API such as PHP object-oriented programming. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The details are as follows:

Understanding CLA

Class_exists verifies that the class exists

Get_class checks the class of the object instanceof verifies whether the object belongs to a class

Get_class_methods gets a list of all the methods in the class, only the methods of public, but not the methods of protected,private. The default is public.

Output:

Array ([0] = > _ construct [1] = > getPlayLength [2] = > getSummaryLine [3] = > getProducerFirstName [4] = > getProducerMainName [5] = > setDiscount [6] = > getDiscount [7] = > getTitle [8] = > getPrice [9] = > getProducer)

More validation

Output:

TitletitletitletitleArray ([coverUrl] = >) CdProduct is a subclass of ShopProductCdProduct is a subclass of incidentalCdProduct is an interface of incidental

_ _ call method

Output:

Thing

Pass parameters to use

Output:

Another thing (hi, hello)

Reflection API

Fullshop.php

Output:

Class [class CdProduct extends ShopProduct] {@ @ D:\ xampp\ htdocs\ popp-code\ 5 fullshop.php 53-73-Constants [0] {}-Static properties [0] {}-Static methods [0] {}-Properties [2] {Property [private $playLength] Property [protected $price]}-Methods [10] {Method [public method _ construct] {@ D:\ xampp\ htdocs\ popp- Code\ 5\ fullshop.php 56-61-Parameters [5] {Parameter # 0 [$title] Parameter # 1 [$firstName] Parameter # 2 [$mainName] Parameter # 3 [$price] Parameter # 4 [$playLength = 78]} Method [public method getPlayLength] {@ @ D:\ xampp\ htdocs\ popp-code\ 5\ fullshop.php 63-65 Method [public method getSummaryLine] {@ @ D :\ xampp\ htdocs\ popp-code\ 5\ fullshop.php 67-71} Method [public method getProducerFirstName] {@ D:\ xampp\ htdocs\ popp-code\ 5\ fullshop.php 17-19} Method [public method getProducerMainName] {@ D:\ xampp\ htdocs\ popp-code\ 5\ fullshop.php 21-23} Method [public method setDiscount] {@ D:\ xampp\ htdocs\ popp-code\ 5\ fullshop.php 25-27-Parameters [1] {Parameter # 0 [$num]} Method [public method getDiscount] {@ D:\ xampp\ htdocs\ popp-code\ 5\ fullshop.php 29-31} Method [public method getTitle] {@ @ D:\ xampp\ htdocs\ popp-code\ 5\ fullshop.php 33-35} Method [public method getPrice] {@ D:\ xampp\ htdocs\ popp-code\ 5\ fullshop.php 37-39} Method [public method getProducer] {@ @ D:\ xampp\ htdocs\ popp-code\ 5\ fullshop.php 41-44}}

Comments: see the class thoroughly in a mess, which is much better than var_dump. Which attributes and what classes are inherited. It is clear at a glance which methods in the class are their own, which are overridden, and which are inherited.

View class data

Output:

CdProduct is user defined

CdProduct can be instantiated

View method data

Output:

_ _ construct is user defined__construct is public__construct is the constructor----getPlayLength is user definedgetPlayLength is public----getSummaryLine is user definedgetSummaryLine is public----getProducerFirstName is user definedgetProducerFirstName is public----getProducerMainName is user definedgetProducerMainName is public----setDiscount is user definedsetDiscount is public----getDiscount is user definedgetDiscount is public----getTitle is user definedgetTitle is public----getPrice is user definedgetPrice is public----getProducer is user definedgetProducer is public

Get constructor parameters

Output:

$title has position 0$ title can be null$firstName has position 1$ firstName can be null$mainName has position 2$ mainName can be null$price has position 3$ price can be null$playLength has position 4$ playLength has default: 78$ playLength can be null Thank you for reading! This is the end of this article on "sample analysis of PHP object-oriented programming and reflective API". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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