$ This in php

Source: Internet
Author: User
Please refer to the following code {code ...}} the above is a piece of case code from the instructor. What I want to ask is, in the third line, why can't I directly write ($ options) in the function ~ For more information, see the following code:

Public function setOption ($ options) {$ vars = get_object_vars ($ this); foreach ($ options as $ key => $ val ){... ...}

}

The above is the instructor's case code.
In the third row, why cannot I write ($ options) directly in the ($ this) function)
Problem ~ Please kindly advise

Reply content:

See the following code

Public function setOption ($ options) {$ vars = get_object_vars ($ this); foreach ($ options as $ key => $ val ){... ...}

}

The above is the instructor's case code.
In the third row, why cannot I write ($ options) directly in the ($ this) function)
Problem ~ Please kindly advise

For example, setSun is the sun, and the real parameter ($ planet) is its satellite, and $ this is the whole galaxy. The earth is defined as a member of the Milky Way. We can use $ this-> earth to find it. Assign it to $ planet, and the Earth is surrounded by the sun. Similarly, $ this-> mars = $ planet, mars is surrounded by the sun. However, the sun has eight satellites. We should first use get_object_vars ($ this) to list all the stars in the Milky Way, and find these eight columns as arrays and assign them to $ planet, so setSun can run as the solar system.

$ This refers to the current class. You can print it out in var_dump ($ this. And $ options are two different things.

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.