Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 静态getter/setter的缺点_Php_Codeigniter_Oop - Fatal编程技术网

Php 静态getter/setter的缺点

Php 静态getter/setter的缺点,php,codeigniter,oop,Php,Codeigniter,Oop,我不知道这个问题是否适合这个网站,但我还是要问:使用静态getter的缺点是什么?对于我的网站,我使用CodeIgniter,并在my_Model.php中编写了一个“finder”函数。各个模型将此模型用作父模型,并且只是某种程度上镜像数据库。我将使用finder方法获取模型的对象,然后使用静态getter(也在my_model.php中声明)获取属性。像这样: <?php $article = Article::find(array( 'id' => $someId, )

我不知道这个问题是否适合这个网站,但我还是要问:使用静态getter的缺点是什么?对于我的网站,我使用CodeIgniter,并在my_Model.php中编写了一个“finder”函数。各个模型将此模型用作父模型,并且只是某种程度上镜像数据库。我将使用finder方法获取模型的对象,然后使用静态getter(也在my_model.php中声明)获取属性。像这样:

<?php
$article = Article::find(array(
    'id' => $someId,
));
echo Article::get($article, 'title');

您也可以使用神奇的方法,通过这种方式将getter和setter作为对象方法


然而,我不知道我是否明白你问题的重点。在我看来,你试图做的是以某种方式。ORM与模型不同。模型不关心持久层和反射层之类的东西,他们甚至不知道。

getter/setter是邪恶的哇,我完全忘记了神奇的getter和setter。。。谢谢
<?php
$article = Article::find(array(
    'id' => $someId,
));
Article::set($article, 'title', $theTitle)
       ->set($article, 'text', $theText);
if (!$article->update()) {
    return false;
}
return true;