我有一个像这样的简单代码:
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
请注意,它与功能__()
(标准 wordpress 翻译功能)无关,错误与功能无关,而是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 打开和关闭标签,甚至是字符集和编码(没有 BOM 的 UTF-8)
我以前从未遇到过这样的问题 - 所以任何帮助/提示/见解将不胜感激..
编辑我:
在这些数组之后,是构造函数..
/**
* 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' ) );
}