PHP Object-oriented Smart application

Source: Internet
Author: User

Class Test {Public $a, $b;p ublic function __construct ($a, $b) {$this->a= $a; $this->b= $b;} Public function set ($var, $val) {$this-$var. = $val; return $this;} Public function Get () {echo $this->a. '-'. $this->b;}} Class Test2 {public $obj;p ublic function __construct ($obj) {$this->obj= $obj;} Public function Get () {$this->obj->get ();}} $a = ' aaaaa '; $b = ' bbbbbb '; $set = ' set ';///1, chain call method $test = new test ($a, $b); $test 2 = new Test2 ($test); $test--$set (' a ' , ' 111111 ') $set (' B ', ' 222222 '); Call (Class) method through a string variable ps:php another ingenious application///2, sub-call Method $test-> $set (' A ', ' 111111 '), $test-$set (' B ', ' 222222 '); unset ($test); $test 2->get ();

Although the Test2 instantiation has passed in test, test can still set the parameters through the set method and then affect Test2.

Results of the above execution procedure: (both of the above can produce the same result)

aaaaa111111-bbbbbb222222


PHP Object-oriented Smart application

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.