PHP object-oriented-code sharing of object traversal

Source: Internet
Author: User
Object traversal is the same as array traversal. object traversal refers to the traversal of instance attributes. The following traversal attributes are the same as the traversal of an array in the range of "accessible attributes" (access permissions should be considered). object traversal refers Instance attributes.
  
The property Retrieved below is the "accessible property" in this range (the access permission should be considered ).

 $ Value) {// $ key indicates the object's attributes, and $ value indicates its corresponding value echo"
Attribute $ key: ". $ value;}?>

Running result:

Property p1: 1

It can be seen that only public-modified attributes can be traversed. how can all attributes of an object be traversed? Write a traversal method in the class.

 $ Value) {echo"
Attribute $ key: $ value ";}}$ obj1 = new A (); $ obj1-> showAllProperties ();?>

Running result:

Property p1: 1 property p2: 2 Property p3: 3

However, static attributes do not belong to objects, so they cannot be traversed.

The above is the detailed content shared by PHP object-oriented-object traversal code. For more information, see other related articles in the first PHP community!

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.