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!