gpt4 book ai didi

php - 解析错误 PHP

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

我的 IDE 在我的 php 文件的这一行显示“解析错误”:

var $meat = new Category(Meat-Free Meat, 1);

我正在尝试让这行代码工作:

return parent::displayData($viewData);

$ViewData 需要是 Category 对象的数组。

我的语法哪里出错了?

完整文件如下:

class CategorySelect extends BaseSelect {
static $template = 'select_multiple_template.php';

public static function display() {
var $meat = new Category(Meat-Free Meat, 1);
var $dairy = new Category(Dairy-Free dairy, 2);
var $confectionery = new Category(Confectionery, 3);
var $baking = new Category(Baking, 4);
var $dessert = new Category(Dessert, 5);
var $viewData = array($meat, $dairy, $confectionery, $baking, $dessert);
return parent::displayData($viewData);
}
}

class Category {
function Category($name, $id) {
$this->name = $name;
$this->id = $id;
}
}

这是它扩展的抽象类:

interface iSelect {
public static function display();
}

abstract class BaseSelect implements iSelect {
static $template = 'select_template.php';
public static function displayData($viewData) {
if ( class_exists( 'View' ) ) {
$templatePath = dirname( __FILE__ ) . '/' . static::$template;
return View::render( $templatePath, $viewData );
}
else {
return "You are trying to render a template, but we can't find the View Class";
}
}
}

最佳答案

你的问题在这里

var $meat = new Category(Meat-Free Meat, 1);
var $dairy = new Category(Dairy-Free dairy, 2);

无肉肉是字符串吗?你必须添加引号,那么它应该是:

$meat = new Category("Meat-Free Meat", 1);
$dairy = new Category("Dairy-Free dairy", 2);

关于php - 解析错误 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35662174/

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