欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php 魔术方法 深度理解 php 魔术 php php中的魔术方法

程序员文章站 2022-05-07 09:13:10
...
??摘要:在trace yii框架源码的时候,遇到__set()魔术方法的使用,有些疑惑,所以写了demo来测试,果然发现了玄机,整理如下。

1. 先来看看书本上讲魔术方法__set()是怎么用的

??使用__set()魔术方法的目的是:在对象外部 为私有属性赋值,不能获取私有属性的值。
??函数原型:

void __set(string name,mixed value)

写个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); }); });

以上就介绍了php 魔术方法 深度理解,包括了PHP 魔术方法方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签: PHP 魔术方法