Example #1
0
 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";
     }
 }
Example #2
0
    }
    // Leverage built-in __toString() implementation for $color2.
    echo $color1->getName() . $comparison_result . $color2 . "<br />\n";
}
// Run demonstrations.
echo "<h2>Say Nice Stuff</h2>";
saySomethingNice(Color::BLUE());
saySomethingNice(Color::RED());
saySomethingNice(Color::YELLOW());
echo "<h2>List html codes</h2>";
listHtmlCodes();
echo "<h2>Compare colors</h2>";
compareColors(Color::RED(), Color::BLUE());
compareColors(Color::YELLOW(), Color::YELLOW());
$serialCopyColor = unserialize(serialize(Color::YELLOW()));
if ($serialCopyColor === Color::YELLOW()) {
    echo "\nunexected === match on serialized/deserialized value\n";
} else {
    echo "\n Expected === mismatch on serialized/deserialized value\n";
}
switch ($serialCopyColor) {
    case Color::YELLOW():
        echo "case match!\n";
        break;
    case Color::BLACK():
        echo "case false positive!\n";
        break;
    default:
        echo "case false negative!\n";
        break;
}