The member attributes cannot be shared between the two steps.

Source: Internet
Author: User
The member attributes cannot share the class & nbsp; a & nbsp; {& nbsp; public & nbsp; $ a0; & nbsp; & nbsp; public & nbsp; fucntion & nbsp; ax () {& nbsp; & nbsp; & Member attributes cannot be shared between two methods

class a {
public $a=0;
public fucntion ax(){
$this->a='111';
}

public fucntion bx(){
echo $this->a;
}
}

$ A after assigning a value in ax (), how can I call the $ a value equal to 111 in bx? After assigning values to an attribute in a method, the other method cannot obtain the value.

PHP

Share to: a = '000000 ';?????}???? Pub... 'data-pics = ''>


------ Solution --------------------
After instantiation, execute ax in order, and the bx will have
You need to understand that ax/bx is parallel in the class. it doesn't mean that you write it in front of it, and there are values in the back.

------ Solution --------------------


class a {
public $a=0;
public function a(){
return $this->a='111';
}
public function bx(){
echo $this->a();
}
}

$p = new a();
$p->bx();

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.