在课堂上,我在第22行收到“意外的''''[...],而且我可以终生不知道为什么。
错误在第22行
<?php
namespace oowp\post;
global $wpdb;
class PostObjectQueryBuilder extends QueryBuilder implements IExtendable {
use Extendable;
// WP Tables
private $tablePosts; //The table of Posts.
private $tablePostmeta; //The Meta Content (a.k.a. Custom Fields) table.
private $tableComments; //The Comments table.
private $tableCommentmeta; //The table contains additional comment information.
private $tableTerms; //The terms table contains the 'description' of Categories, Link Categories, Tags.
private $tableTermTaxonomy; //The term_taxonomy table describes the various taxonomies (classes of terms). Categories, Link Categories, and Tags are taxonomies.
private $tableTermRelationships; //The term relationships table contains link between the term and the object that uses that term, meaning this file point to each Category used for each Post.
private $tableUsers; //The table of Users.
private $tableUsermeta; //The usermeta table contains additional user information, such as nicknames, descriptions and permissions.
private $tableLinks; //The table of Links.
private $tableOptions; //The Options table.
// LINE 22 BELOW
const BASE_QUERY = "SELECT wp.ID FROM `{$this->tablePosts}` wp
INNER JOIN `{$this->tablePostMeta}` wm ON (wm.`post_id` = wp.`ID`)
INNER JOIN `{$this->tableTermRelationships}` wtr ON (wp.`ID` = wtr.`object_id`)
INNER JOIN `{$this->tableTermTaxonomy}` wtt ON (wtr.`term_taxonomy_id` = wtt.`term_taxonomy_id`)
INNER JOIN `{$this->tableTerms}` wt ON (wt.`term_id` = wtt.`term_id`)";
我尝试重写有问题的行,并尝试将const声明移到顶部,以及删除该use
语句。两者都不起作用。
这是因为类常量需要具有常量值,并且您的定义不是常量。
从类常量手册中:
该值必须是一个常量表达式,而不是(例如)变量,属性或函数调用。
你可以证明你的语法类的正确外通过移除const
和车削BASE_QUERY
成$BASE_QUERY
和删除$this->
其他一些变量,它应该成功的解析。
您可以将此表达式定义为成员变量,但不能在初始化期间定义。这是因为PHP中的成员变量也必须初始化为常量表达式。最简单的解决方案是$BASE_QUERY
在类中定义,然后在构造函数中对其进行初始化。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句