I want to be able to look up the value of a constant dynamically, but using a variable doesn't work with the syntax.
<?php
class Food {
const FRUITS = 'apple, banana, orange';
const VEGETABLES = 'spinach, carrot, celery';
}
$type = 'FRUITS';
echo Food::FRUITS;
echo Food::$type;
?>
gives
apple, banana, orange
Fatal error: Access to undeclared static property: Food::$type
How can I dynamically call the constant?