本文整理汇总了PHP中Color::RED方法的典型用法代码示例。如果您正苦于以下问题:PHP Color::RED方法的具体用法?PHP Color::RED怎么用?PHP Color::RED使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Color
的用法示例。
在下文中一共展示了Color::RED方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
public static function main()
{
$color1 = Color::BLUE();
$color2 = Color::YELLOW();
$color3 = Color::BLUE();
self::displayColor($color1);
self::displayColor($color2);
self::displayColor($color3);
self::compareColor($color1, $color2);
self::compareColor($color2, $color3);
self::compareColor($color1, $color3);
self::compareColor($color1, $color1);
switch ($color1) {
case Color::RED():
echo 'red' . "\n";
break;
case Color::ORANGE():
echo 'orange' . "\n";
break;
case Color::YELLOW():
echo 'yellow' . "\n";
break;
case Color::GREEN():
echo 'green' . "\n";
break;
case Color::BLUE():
echo 'blue' . "\n";
break;
case Color::INDIGO():
echo 'indigo' . "\n";
break;
case Color::VIOLET():
echo 'violet' . "\n";
break;
}
try {
$invalidColor = Color::BLACK();
} catch (\BadFunctionCallException $e) {
echo 'error : ' . $e->getMessage() . "\n";
}
}
示例2: saySomethingNice
/**
* Demonstrate type hinting against Enum implementation by saying something nice about the
* received Color.
*
* @param Color $color The color to say something nice about.
*
* @return void
*/
function saySomethingNice(Color $color)
{
switch ($color) {
case Color::RED():
$something_nice = ' is like the love of a rose petal.';
break;
case Color::BLUE():
$something_nice = ' is like a deep sea on a sunny day.';
break;
default:
$something_nice = ' is a wonderful color.';
break;
}
echo 'The color ' . $color->getName() . $something_nice . "<br />\n";
}