预期类型 'array'。发现 'int'.intelephense(1006)

Expected type 'array'. Found 'int'.intelephense(1006)

我的 PHP 代码没有什么问题。 确实,当我执行 array_push 或内爆数组时出现错误:“预期类型 'array'。找到 'int'.intelephense(1006)”。

我已经在构造函数中声明了 $element 的类型:我不明白。

我给你我的代码。

My code in picture

(我无法粘贴我的代码:它太长了)

感谢您的帮助。 西里尔.

array_push 引用您的数组和要添加的元素。

您的代码应如下所示:

array_push(&$this->element, $element);

或更现代的等效(技术上更快)变体:

$this->element[] = $element;

数组上的 [] 运算符添加元素。