问题描述
我必须将Twig模板转换回网站的PHP,所以我们基本上是在模仿功能.我从PHP中得到一个错误,突出显示了我的类属性$ link,该属性包含其他变量数组.
I have to convert Twig template back into PHP for a site so we are basically mimicking the functionality. I'm getting an error from PHP highlighting my class property $link which contains an array of other variables.
我不明白为什么要突出显示此属性,而不是突出显示我的其他属性,直接位于名为$ downloadLink的下面.两者都是数组,除非我遗漏了一些东西.该错误最初并未突出显示,但直到后来我继续其余代码时才突出显示.
I don't understand why it is highlighting this property but not my other property directly underneath named $downloadLink. Both are arrays, unless I'm missing something. This error did not highlight initially but only later as I continued the rest of my code.
class Card {
public $title;
public $image;
public $text;
public $link = array(
$url,
$nale,
);
public $downloadLink = array(
$url,
$title,
$type,
$weight,
);
function __construct(string $title, string $image, string $text, array $link_arr, array $downloadLink_arr)
{
$this->title = $title;
$this->image = $image;
$this->text = $text;
$this->link->url = $link_arr[0];
$this->link->nale = $link_arr[1];
$this->downloadLink->url = $downloadLink_arr[0];
$this->downloadLink->title = $downloadLink[1];
$this->downloadLink->type = $downloadLink[2];
$this->downloadLink->weight = $downloadLink[3];
}
}
推荐答案
这是PHP的基本知识.
This is a PHP basic stuff.
您不能使用变量来初始化变量,并且当变量是数组时,您将尝试使用对象分配.
You can't initialize variables with variables and you are trying to use Object assignments when your variable is an array.
<?php
class Card
{
public $title;
public $image;
public $text;
public $link = array();
public $downloadLink = array();
public function __construct(string $title, string $image, string $text, array $link_arr, array $downloadLink_arr)
{
$this->title = $title;
$this->image = $image;
$this->text = $text;
$this->link['url'] = $link_arr[0];
$this->link['nale'] = $link_arr[1];
$this->downloadLink['url'] = $downloadLink_arr[0];
$this->downloadLink['title'] = $downloadLink[1];
$this->downloadLink['type'] = $downloadLink[2];
$this->downloadLink['weight'] = $downloadLink[3];
}
}
这篇关于常量表达式包含无效运算-不突出显示其他变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!