A summary of the definition and usage of magic methods

Source: Internet
Author: User
Tags php source code
__set () function: __set (): When assigning a value to an unreachable property (private,protected, not present), PHP executes the __set () method. As we said above, the function of __set () is: When assigning a value to an unreachable property (private,protected, not present), PHP executes the __set () method. What does this mean? For example, let's take the example above. We put the monkeys like to eat peaches for bananas, but according to the rules, $food the key word is protected, can not be directly accessed, but we need to assign value to $food, what should we do? <?phpclass monkey{public $name;p rotected $food, function __construct ($name, $food) {$this->name = $name; $this

1. Magic Method __set () Example (PHP Object-oriented Advanced tutorial)

Summary: __set () function: __set (): When assigning a value to an inaccessible property (private,protected, not present), PHP executes the __set () method. As we said above, the function of __set () is: When assigning a value to an unreachable property (private,protected, not present), PHP executes the __set () method.

2. PHP Object-oriented-detailed description of the example code for overloading (overloading)

Summary: Overloading PHP provides "overloads" (overloading) as dynamic "create" class properties and methods. is achieved by means of magic methods. Overloaded methods are called when a class property or method is called that is undefined or not visible under the current environment. These undefined or invisible class properties or methods are addressed by using the inaccessible members and the inaccessible methods (inaccessible methods) later in this section. All overloaded methods must be

3. C # is inaccessible due to its level of protection and can only handle detailed code descriptions of public types

Summary: Error encountered when implementing C # Export list data to an XML file [with Source]: not accessible because of its level of protection. Only public types can be processed. The line of code that generated the error: XmlSerializer XmlSerializer = new XmlSerializer (typeof (List)); Error reason: class definition in the following code is: Class Usermodel does not add the public access modifier////////////User entity class//

4. Introduction and use of PHP magic methods and Magic constants

Introduction::P HP Magic methods and Magic constants introduction and use: Some things if not often used, it is easy to forget, such as magic methods and magic constants. Magic Method (Magic methods) in PHP, the method of starting with two underscores is called the Magic Method, which plays a pivotal role in PHP. Magic methods include: __construct (), class constructor __destruct (), Class destructor __call (), calling an inaccessible method in an object when called __callstatic (), when invoking an inaccessible method in a static manner

5. PHP Magic Use method Summary 2 PHP CI framework using PHP escape character using PHP source code to teach

Introduction: Use Method, Php:php Magic use method summarizes 2:1.__construct,__destruct__constuct build object when called; __destruct explicitly destroys object or is called at end of script; 2.__get,__set__ Set is called when the __get read is not accessible or does not exist when the property is assigned to an unreachable or nonexistent property when the call is called 3.__isset,__unset__isset to an inaccessible or nonexistent property called isset () or empty () Unset to a non-accessible or nonexistent

6. PHP Magic Method __get __set (ii), __get__set_php tutorial

Introduction: PHP Magic Method __get __set (ii), __get__set. PHP Magic Method __get __set (ii), __get__set slowly long seek night, the moon Hanging __get ()-Read the value of the Inaccessible property, __get () will be called __set ()-in the given inaccessible properties

7. Php Magic Method __get, __set use instance, __get__set_php tutorial

Introduction: Php Magic method __get, __set use instance, __get__set. Php Magic Method __get, __set use instance, __get__set __get ()-When reading the value of an inaccessible property, __get () is called. __set ()-When assigning a value to an inaccessible property, __set () is

8. thinkphp require parent directory prompt does not have permission, how to configure Apache

Introduction: The site uses the THINKPHP5 framework, the server is built with WDCP and then upload the public files to the/website/public_html directory, other inaccessible framework files are placed in the/website/directory, but when PHP require/ website/some classes in the directory, he will prompt fail ...

9. [Solve] The server is set to a non-accessible extranet can you use Phpmailer SMTP to send mail?

Summary: [solve] The server is set to a non-accessible extranet can you use Phpmailer SMTP to send mail?

Summary of the use of magic methods and magic constants in PHP

Introduction: Magic Method (Magic methods) in PHP, the method that starts with two underscore __ is called the Magic Method, which plays a pivotal role in PHP. Magic methods include: __construct (), class constructor __destruct (), Class destructor __call (), call an inaccessible method in an object when calling __callstatic (), call in a static way an inaccessible

"Related question and answer recommendation":

Linux-local access to VMware virtual machines, addresses are accessible, domain names are inaccessible

JavaScript-Two JS public functions need to call the same function, what is the method?

Nginx How to set a directory that cannot be accessed

Javascript-js Scope and no block-level scope both, a bit of a circle ~

thinkphp-php require parent directory prompt does not have permission, how to configure Apache

Related Article

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.