About _ set

Source: Internet
Author: User
Class & nbsp; aa {function & nbsp ;__ set ($ pro, & nbsp ;v v) {echo & nbsp;; $ this-& gt; pro $ v; echo & nbsp; $ vn ;}$ anew & nbsp; aa; $ a-& gt; b1; output is a & nbsp; a & nbsp; 1 & nbsp; 1; 2 questions, why about _ set

Class aa {
Function _ set ($ pro, $ v ){
Echo "a \ n ";
$ This-> pro = $ v;
Echo "$ v \ n ";
}
}

$ A = new aa;
$ A-> B = 1;


The output is a 1 1;

Why are two problems output;

Why is it a 1 1, not a 1 a 1;


------ Solution ----------------------
Change echo "a \ n" to echo "$ pro \ n ".
B enters the _ set method because the B attribute does not exist.
Pro also enters the _ set method again because the pro attribute does not exist.
It is not surprising to print the value twice after entering 1.
1

When $ this-> pro = $ v;
Change to $ this-> $ pro = $ v;
Only once

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.