Home  >  Article  >  Backend Development  >  php magic method in-depth understanding of php magic php magic method in php

php magic method in-depth understanding of php magic php magic method in php

WBOY
WBOYOriginal
2016-07-29 08:49:18986browse

??Summary: When tracing the source code of the yii framework, I encountered the use of the __set() magic method and was a little confused, so I wrote a demo to test it, and I discovered the mystery, which is summarized as follows.

1. Let’s first take a look at how the magic method __set() is used in the book

??The purpose of using the __set() magic method is to assign values ​​to private properties outside the object and cannot obtain the value of the private property. .
??Function prototype:

void __set(string name,mixed value)

Write a demo:

classCModule {private$_components = '';

    publicfunction__set($name,$value){$this->$name = $value;
    }

    publicfunctionechoPrivate(){echo$this->_components;
    }
}

$config = array(
    '_components'=>'request'
);
$module = new CModule();
$module->_components = 'request';
$module->echoPrivate();
//打印结果是//request

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced an in-depth understanding of PHP magic methods, including the content of PHP magic methods. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn