【发布时间】:2014-02-28 16:24:19
【问题描述】:
我有一个使用 CList 的基本函数 - 出于某种原因,我收到以下错误:
CList and its behaviors do not have a method or closure named "setReadOnly".
我的php代码
$list = new CList(array('python', 'ruby'));
$anotherList = new Clist(array('php'));
var_dump($list);
$list->mergeWith($anotherList);
var_dump($list);
$list->setReadOnly(true); // CList and its behaviors do not have a method or closure named "setReadOnly".
谁能解释我为什么会收到这个错误?
P.S 我直接从最近的一本 Yii 书中复制了这段代码......所以我有点困惑
// 更新:在mergeWith()前后添加了var_dump
object(CList)[20]
private '_d' =>
array (size=2)
0 => string 'python' (length=6)
1 => string 'ruby' (length=4)
private '_c' => int 2
private '_r' => boolean false
private '_e' (CComponent) => null
private '_m' (CComponent) => null
object(CList)[20]
private '_d' =>
array (size=3)
0 => string 'python' (length=6)
1 => string 'ruby' (length=4)
2 => string 'php' (length=3)
private '_c' => int 3
private '_r' => boolean false
private '_e' (CComponent) => null
private '_m' (CComponent) => null
【问题讨论】:
-
你试过 print_r($list);检查 clist 是否具有只读变量。在合并之前和之后执行 print_r。
-
我在调用 mergeWith() 函数之前和之后添加了列表变量的 var_dump
-
readonly 是公共成员但继承。反正问题很奇怪。
-
这很奇怪..这并不重要我只是在 Yii 中玩一些“较小”的功能我还没有遇到过......但是我同意这很奇怪:)
标签: yii frameworks clist