gpt4 book ai didi

PHP数组错误: Indirect modification of overloaded property

转载 作者:可可西里 更新时间:2023-11-01 00:14:55 25 4
gpt4 key购买 nike

为什么是这行代码:

$this->plugins_dir[0] = SMARTY_DIR . 'plugins';

导致此错误?

ERRNO: 8
TEXT: Indirect modification of overloaded property Page::$plugins_dir has no effect

顺便说一下,这行代码位于名为“Page”的类的构造函数中。

我正在使用 PHP 和 PostgreSQL,但经验不足。我卡住了这个问题几个小时了,找不到原因。

最佳答案

PHP 试图告诉您的是属性 ->plugins_dir 并不真正存在,但是编写了一个神奇的 __get() 函数,它将返回一个值,如果你从中读取。将变量直接分配给它也可能有效(如果有相应的 __set())但您不能修改它,因为它实际上是一个函数返回值。您实际上是在尝试说 $this->__get('plugins_dir')[0] = 'foo',这没有任何意义。

然而,看着the relevant Smarty documentation ,我们可以看到正确的解决方案是什么:

Note: As of Smarty 3.1 the attribute $plugins_dir is no longer accessible directly. Use getPluginsDir(), setPluginsDir() and addPluginsDir() instead.

因此您的代码实际上应该使用 the doc page for addPluginsDir() 上的示例之一的模式,例如:

$this->setPluginsDir( SMARTY_DIR . 'plugins' )
->addPluginsDir( '/some/other/source/of/plugins' );

关于PHP数组错误: Indirect modification of overloaded property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15712606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com