括号里面奇怪的语法错误,我有一个简单的代码如下所示:PHP - 与类数组
class o99_custom_fields {
/**
* @var string $prefix The prefix for storing custom fields in the postmeta table
*/
var $prefix = 'o99_';
/**
* @var array $customFields Defines the custom fields available
*/
var $customFields = array(
array(
"name" => "some_name",
"title" => "some Title",
"description" => "Some Desctiption Text",
"type" => "k_upload",
"scope" => array("post"),
"capability" => "edit_post"
),
array(
"name" => "some_name2",
"title" => "some Title",
"description" => "Some Desctiption Text",
"type" => "k_upload",
"scope" => array("post"),
"capability" => "edit_post"
),
array(
"name" => "some_name3",
"title" => "some Title",
"description" => "",
"type" => "k_textarea",
"scope" => array("post"),
"capability" => "edit_post"
),
);
... more functions and more code ...
} // End Class
,一切似乎正常,
问题开始时,我试图改变一些数组值,并把它们括号内()
例如:
array(
"name" => "some_name",
"title" => __("some Title","text_domain"),// ERROR OCCUR
"description" => "Some Desctiption Text",
"type" => "k_upload",
"scope" => array("post"),
"capability" => "edit_post"
),
的错误信息是:
Parse error: syntax error, unexpected '(', expecting ')' in E:\my_path\myfile.php on line 18
注意,它是不相关的功能__()
(standard wordpress translation function)和误差是不相关的功能,但是SYNTAX
。 (我已经使用这个功能数百名在过去的时代,没有任何问题 - 在这种情况下,也_x()
和_e()
无法在相同的语法错误。)
我所有的括号被关闭,我已经检查并重新检查,除非我完全失明,否则我会说没问题,但我仍然得到这个错误,无论我把括号放在这个类的什么地方。
又如:这也将失败,相同的错误:
class o99_custom_fields {
/**
* @var string $prefix The prefix for storing custom fields in the postmeta table
*/
var $prefix = 'o99_';
/**
* @var array $customFields Defines the custom fields available
*/
var $dummy_strings = array (
__('x1','text_domain'),
__('x2','text_domain'),
);
... more functions and more code ...
} // End Class
同样,错误似乎是SYNTAX
相关,即使我的所有支架都关闭。 我还检查了正确的PHP开始和结束标记的文件,甚至字符集和编码(UTF-8无BOM)
我以前从来没有遇到过这样的问题 - 所以任何帮助/提示/有识之士将大大感激..
编辑我:
这些阵列后,自带的建设者..
/**
* PHP 4 Compatible Constructor
*/
function o99_custom_fields() { $this->__construct(); }
/**
* PHP 5 Constructor
*/
function __construct() {
add_action('admin_menu', array(&$this, 'createCustomFields'));
add_action('save_post', array(&$this, 'saveCustomFields'));
}
以及你完全正确的,这是奇怪的有:/ –