Introduction to php object-oriented magic methods

Source: Internet
Author: User
Tags php books php web development
Several common php magic methods are introduced! (1) _ get and _ set methods. when the reference class does not contain members, you can call two methods. The _ set method must accept two parameters, used to store the name and attribute value of the property to be written. Running result: set

Several common php magic methods are introduced!
(1) _ get and _ set methods. when the reference class does not contain members, you can call two methods. The _ set method must accept two parameters,
Used to store the name and attribute value of the property to be written.
Running result:
Set :::: php: php web development Daquan
Get: php
Php books = php web development


 "; $ This-> p [$ name] = $ value;} function _ get ($ name) {print" get ::::{$ name}
"; // Array_key_exists check whether the given key name or index exists in the array return array_key_exists ($ name, $ this-> p )? $ This-> p [$ name]: null ;}$ computer = new BookStore (); $ computer-> php = 'php web development corout '; echo "php books = ". $ computer-> php;?>

(2) _ autoload (): are you still worried about calling too many classes or functions? are you still worried about writing require () and include () n times ()
However, if you know the _ autoload () method, you don't need to do so. here I will give you a reference:
MyClass. php file:


 

General. inc. php file


 

Main. php


 PrintWeb ();} else {echo "class file not transferred" ;}?>


Running result:
The website you are visiting is www.phpddt.com.

Of course there are still many magic methods, such as _ isset () ,__ unset () ,__ toString () ,__ clone,
I have limited technical skills and can only guide some beginners!

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.