这是我的代码=>分配数组作为数组元素的PHP的类变量/属性
class Dbhead{
public static $category=array(
"id"=>"Id",
"title"=>"Title",
"code"=>"Code",
"description"=>"Description",
"remarks"=>"Remarks"
);
public static $client=array(
"id"=>"Id",
"title"=>"Title",
"name"=>"Name",
"mobile"=>"Mobile",
"address"=>"Address",
"remarks"=>"Remarks"
);
public $allfields=array(
"client"=>self::$client,
"category"=>self::$category
);
}
分配$client
& $category
阵列$allfields
作为元素中断的代码。 我已尝试将$client
& $category
更改为仅公开。
我已经尝试了所有可能的方法,我知道要实现它,除了使用方法/函数,因为我不想这样做。
在你的'__construct()'方法中做。 –
从[PHP文档](http://www.php.net/manual/en/language.oop5.properties.php)这个声明可能包含一个初始化,但是这个初始化必须是一个常量值 - 即,它必须能够在编译时进行评估,并且不得依赖运行时信息进行评估。“......即,你不能......你必须定义一些像这样动态的东西在方法 –
@Julien我不想使用任何方法。我在寻找替代品。 '__construct()'是一个魔术棒。我正在尝试,因为它是从过程到面向对象的过渡时间。 –