【发布时间】:2013-11-02 08:00:01
【问题描述】:
我有一个像这样的简单代码:
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 开始和结束标记,甚至字符集和编码(没有 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' ) );
}
【问题讨论】:
-
嗯,你完全正确,这很奇怪:/
标签: php arrays syntax brackets