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!