解析错误PHP

时间:2016-02-26 21:34:03

标签: php

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

  

var $ meat = new Category(无肉,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";
        }
    }
}

1 个答案:

答案 0 :(得分:8)

你的问题在这里

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);