无法正确使用字符串偏移量作为数组
Cannot use correctly string offset as an array
我使用的是旧的 PHP hook class,我的 PHP 更新有问题
这是我的错误
[php7:error] PHP Fatal error: Uncaught Error: Cannot use string offset as an array in /var/www/html/libs/Hooks.class.php:202\nStack
这是我的源代码 (ligne 202)
function add_hook($tag, $function, $priority = 10) {
if (! isset ( $this->hooks [$tag] )) {
die ( "There is no such place ($tag) for hooks." );
} else {
$this->hooks [$tag] [$priority] [] = $function; // <-- this is problem (line 202)
}
}
如果我更改导致问题的行如下:
$this->hooks [$tag] [$priority] = $function; // <-- this is problem (line 202)
我只得到内容的第一个字母(如图)
不知道怎么解决这个问题
如果您将 var 定义为字符串 - 您不能添加数组元素。您的解决方案 - 将库函数更改为:
function set_hook($tag) {
$this->hooks [$tag] = [];
}
为了提高代码质量 - 将函数声明更改为:
function add_hook($tag, $function, $priority = "10") {
我使用的是旧的 PHP hook class,我的 PHP 更新有问题
这是我的错误
[php7:error] PHP Fatal error: Uncaught Error: Cannot use string offset as an array in /var/www/html/libs/Hooks.class.php:202\nStack
这是我的源代码 (ligne 202)
function add_hook($tag, $function, $priority = 10) {
if (! isset ( $this->hooks [$tag] )) {
die ( "There is no such place ($tag) for hooks." );
} else {
$this->hooks [$tag] [$priority] [] = $function; // <-- this is problem (line 202)
}
}
如果我更改导致问题的行如下:
$this->hooks [$tag] [$priority] = $function; // <-- this is problem (line 202)
我只得到内容的第一个字母(如图)
不知道怎么解决这个问题
如果您将 var 定义为字符串 - 您不能添加数组元素。您的解决方案 - 将库函数更改为:
function set_hook($tag) {
$this->hooks [$tag] = [];
}
为了提高代码质量 - 将函数声明更改为:
function add_hook($tag, $function, $priority = "10") {