【发布时间】:2018-06-25 13:19:29
【问题描述】:
我希望能够动态查找常量的值,但使用变量不适用于语法。
<?php
class Food {
const FRUITS = 'apple, banana, orange';
const VEGETABLES = 'spinach, carrot, celery';
}
$type = 'FRUITS';
echo Food::FRUITS;
echo Food::$type;
?>
给予
apple, banana, orange
Fatal error: Access to undeclared static property: Food::$type
如何动态调用常量?
【问题讨论】:
-
我想你不能。
标签: php constants class-constants