コード例 #1
0
ファイル: ConstructorsTest.php プロジェクト: websublime/enum
 public function testVenus()
 {
     // Now that VENUS has data attached we can use her public properties
     $venus = Planet::VENUS();
     $this->assertInstanceOf('Planet', $venus);
     print sprintf('Venus is also a %s.', $venus->related) . PHP_EOL;
 }
コード例 #2
0
ファイル: Constructors.php プロジェクト: websublime/enum
 public static function __()
 {
     // Within this static initializer, we can attach data by doing a 'constructor' call (without the new keyword)
     // Let's attach the inhabitant's name and a related object/service that is identical to the planet's name
     Planet::MERCURY('Mercurian', 'Chemical element');
     Planet::VENUS('Venusian', 'Roman goddess of love');
     Planet::EARTH('Terrestrial', 'Soil we walk on');
     // Note how static and/or self can also be used as they point to Planet. This ensures a robust enum definition withstanding any future name changes
     static::MARS('Martian', 'Well-known candy bar');
     self::PLUTO('Plutonian', 'Fictional Disney character');
 }