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; }
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'); }