public function __toString() { return "Foo"; } } class Bar { } try { E2::assert(new Foo()); } catch (\UnexpectedValueException $e) { echo $e->getMessage() . "\n"; } try { E2::assert(new Bar()); } catch (\UnexpectedValueException $e) { echo $e->getMessage() . "\n"; } class Baz { public function __toString() { return 'green'; } } try { E2::assert(new Baz()); } catch (\UnexpectedValueException $e) { echo $e->getMessage() . "\n"; } }
require_once $GLOBALS['HACKLIB_ROOT']; final class E1 { private function __construct() { } private static $hacklib_values = array('Fly' => "15", 'Blue' => 12, 'Red' => 16, 'Green' => "green"); use \HH\HACKLIB_ENUM_LIKE; const Fly = "15"; const Blue = 12; const Red = 16; const Green = "green"; } var_dump(E1::getNames()); final class E2 { private function __construct() { } private static $hacklib_values = array('Fly' => "15", 'Blue' => 12, 'Red' => 15, 'Green' => "green"); use \HH\HACKLIB_ENUM_LIKE; const Fly = "15"; const Blue = 12; const Red = 15; const Green = "green"; } try { E2::getNames(); } catch (HH\InvariantException $e) { echo $e->getMessage() . "\n"; }
} private static $hacklib_values = array('Fly' => "15", 'Blue' => 12, 'Red' => 15, 'Green' => "green"); use \HH\HACKLIB_ENUM_LIKE; const Fly = "15"; const Blue = 12; const Red = 15; const Green = "green"; } echo "ImmVector: "; var_dump(E2::assertAll(new \HH\ImmVector(array(15, "15", "12", 12, "green")))); echo "array: "; var_dump(E2::assertAll(array(15, "15", "12", 12, "green"))); echo "Map: "; var_dump(E2::assertAll(\HH\Map::hacklib_new(array(12, "1", 1, "grey", 3), array(15, "15", "12", 12, "green")))); function fn() { $a = array(15, "15", "12", 12, "green"); foreach ($a as $v) { (yield $v); } } $g = fn(); echo "Generator: "; var_dump(E2::assertAll($g)); try { E2::assertAll(array(15, "true", 12)); } catch (\UnexpectedValueException $e) { echo $e->getMessage() . "\n"; } var_dump(E2::assertAll("15"));
const Red = 15; const Green = "green"; } echo "\nE2:\n"; display(E2::coerce(12)); display(E2::coerce("12")); display(E2::coerce("15")); display(E2::coerce(15)); display(E2::coerce("green")); display(E2::coerce(13)); class Foo { public function __toString() { return "Foo"; } } class Bar { } display(E2::coerce(new Foo())); display(E2::coerce(new Bar())); class Baz { public function __toString() { return 'green'; } } display(E2::coerce(new Baz())); }
private function foo() { echo "D2::foo " . (isset($this) ? "true\n" : "false\n"); } public function test() { F2::foo(); } } class E2 extends D2 { } class F2 extends D2 { } $e2 = new E2(); $e2->test(); // Outputs 'D2::foo false' (Zend outputs 'D2::foo true') class D3 { private function foo() { echo "D3::foo " . (isset($this) ? "true\n" : "false\n"); } public function test() { F3::foo(); } } class X3 extends D3 {
public function test() { $this->foo(); } } class D2 extends C2 { protected function foo() { echo "D2::foo\n"; } } class E2 extends D2 { } $obj = new E2(); // This should call C2::foo, not D2::foo $obj->test(); class C3 { private function foo() { echo "C3::foo\n"; } public function test() { $this->foo(); } } class D3 extends C3 {
<?php require_once $GLOBALS['HACKLIB_ROOT']; final class E2 { private function __construct() { } private static $hacklib_values = array('Fly' => "15", 'Blue' => 12, 'Red' => 15, 'Green' => "green"); use \HH\HACKLIB_ENUM_LIKE; const Fly = "15"; const Blue = 12; const Red = 15; const Green = "green"; } var_dump(E2::isValid("15")); var_dump(E2::isValid(15)); var_dump(E2::isValid(12)); var_dump(E2::isValid("12")); var_dump(E2::isValid(13)); class Foo { } var_dump(E2::isValid(new Foo()));
<?php require_once $GLOBALS['HACKLIB_ROOT']; final class E1 { private function __construct() { } private static $hacklib_values = array('Fly' => "15", 'Blue' => 12, 'Red' => 16, 'Green' => "green"); use \HH\HACKLIB_ENUM_LIKE; const Fly = "15"; const Blue = 12; const Red = 16; const Green = "green"; } var_dump(E1::getValues()); final class E2 { private function __construct() { } private static $hacklib_values = array('Fly' => "15", 'Blue' => 12, 'Red' => 15, 'Green' => "green"); use \HH\HACKLIB_ENUM_LIKE; const Fly = "15"; const Blue = 12; const Red = 15; const Green = "green"; } var_dump(E2::getValues());
function main2() { $e2 = new E2(); $e2->test(); // Outputs 'D2::foo false' (Zend outputs 'D2::foo true') }