Php traverses object attributes in two ways-PHP source code

Source: Internet
Author: User
Ec (2); php tutorial traversing object attributes two methods * In this article, we will provide you with two methods for Traversing object attributes, and give examples to illustrate the application of traversing object attributes in php. * Classfoo {& nbsp; private $ a; & nbsp; public $ b1; & nbsp; public $ c; & nbsp; script ec (2); script

Php tutorial traversing object attributes two methods
/*
In this article, we will provide you with two methods for Traversing object attributes, and illustrate the application of traversing object attributes in php.
*/
Class foo {
Private $;
Public $ B = 1;
Public $ c;
Private $ d;
Static $ e;

Public function test (){
Var_dump (get_object_vars ($ this ));
}
}

$ Test = new foo;
Var_dump (get_object_vars ($ test ));

$ Test-> test ();


// Method 2
Class foo {
Private $;
Public $ B = 1;
Public $ c = '111cn. net ';
Private $ d;
Static $ e;

Public function test (){
Var_dump (get_object_vars ($ this ));
}
}

$ Test = new foo;
Var_dump (get_object_vars ($ test ));

$ Test-> test ();

// The result is as follows:
Array (2 ){
["B"] =>
Int (1)
["C"] =>
111cn.net
}
Array (4 ){
["A"] =>
NULL
["B"] =>
Int (1)
["C"] =>
111cn.net
["D"] =>
NULL
}

/*
Seeing the above result, it is very easy to traverse the object attributes.
*/

?>

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.