Let's talk about the problem again.

Source: Internet
Author: User
The problem is coming again. What are the experts ;? Phperror_reporting (E_ALL | E_STRICT); classmycls {& nbsp; private $ p1; & nbsp; ** the overloaded data is stored here * & nbsp; private $ dataarray (); & nbsp; & nbs problem again, big bull
Error_reporting (E_ALL | E_STRICT );

Class mycls {

Private $ p = 1;


/** Store the overloaded data here */
Private $ data = array ();


Function func ()
{
Echo "none static ";
}


/* Public function _ set ($ name, $ value)
{
Echo "Setting '$ name' to' $ value'
\ N ";
$ This-> $ name = $ value;
}*/

Public function _ get ($ name)
{
Echo "Getting '$ name'
\ N ";
Return $ this-> $ name;

}


}


$ My = new mycls;

$ My-> a = 10 ;//


Echo $ my->;
?>

------ Solution --------------------
No problem
------ Solution --------------------
You have $ my-> a = 10;
Of course, it won't call _ get.
------ Solution --------------------
You can write it in this way.
PHP code
Error_reporting (E_ALL | E_STRICT); class mycls {private $ p = 1;/** the overloaded data is saved here */private $ data = array (); function func () {echo "none static";} public function _ set ($ name, $ value) {echo "Setting '$ name' to '$ value'
\ N "; $ this-> data [$ name] = $ value;} public function _ get ($ name) {echo" Getting '$ name'
\ N "; return $ this-> data [$ name] ;}}$ my = new mycls; $ my-> a = 10; // echo $ my->;
------ Solution --------------------
Erer
------ Solution --------------------
$ My = new mycls;

Echo $ my-> a; // direct output will be called.

If no echo statement is available and the value is assigned directly, _ set is called.

But your code is logged out.
------ Solution --------------------
Discussion

Reference:
Reference:
You can write it in this way.

PHP code
Error_reporting (E_ALL | E_STRICT );

Class mycls {
Private $ p = 1;

/** Store the overloaded data here */
Private $ data = array ();

Function func ()
{
Echo "none sta ......

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.