【发布时间】:2013-05-11 04:08:57
【问题描述】:
我有以下课程:
class Mode{
const Enabled = 1;
const Disabled = 2;
const Pending = 3;
}
class Product{
public static $Modes = Mode;
}
我想通过 Product 的静态访问来访问 Mode 类的常量。
if($product_mode == Product::$Modes::Pending){
//do something
}
有什么办法吗?
【问题讨论】:
-
你能扩展你的用例吗?在我看来,您好像在做错事。
-
我正在使用 autoload 来自动加载我的类,所以如果我将 Mode 类放在 Product.php 中,它只会在使用 Product 时自动加载。当我直接调用 Mode::Pending 而不使用 Product 时,会发生错误,告知 Mode 类不存在。
-
Mode和Product是否声明在一个文件中?
标签: php class static constants