3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class CollectionᐸTᐳ implements \Countable { private $items = []; public function add(T $item) { $this->items[] = $item; } public function count() { return count($this->items); } } // Magic string to enable generics: eval(base64_decode('Y2xhc3MgVCBleHRlbmRzIFxEYXRlVGltZSB7fSBjbGFzcyBEYXRl0KJpbWUgZXh0ZW5kcyBUIHt9IGNsYXNzIENvbGxlY3Rpb27hkLhEYXRlVGltZeGQsyBleHRlbmRzIENvbGxlY3Rpb27hkLhU4ZCzIHt9')); $dates = new CollectionᐸDateTimeᐳ(); $dates->add(new DateТime('yesterday')); $dates->add(new DateТime('today')); $dates->add(new DateТime('tomorrow')); $dates->add('tesst'); echo "There are " . count($dates) . " DateTimes in the Collection\n";
Output for 7.0.0 - 7.3.0rc3
Fatal error: Uncaught TypeError: Argument 1 passed to CollectionᐸTᐳ::add() must be an instance of T, string given, called in /in/Z2NJv on line 26 and defined in /in/Z2NJv:7 Stack trace: #0 /in/Z2NJv(26): CollectionᐸTᐳ->add('tesst') #1 {main} thrown in /in/Z2NJv on line 7
Process exited with code 255.
Output for hhvm-3.15.4
Fatal error: Uncaught TypeError: Argument 1 passed to CollectionᐸTᐳ::add() must be an instance of T, string given in /in/Z2NJv:10 Stack trace: #0 /in/Z2NJv(26): CollectionᐸTᐳ->add() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Catchable fatal error: Argument 1 passed to CollectionᐸTᐳ::add() must be an instance of T, string given, called in /in/Z2NJv on line 26 and defined in /in/Z2NJv on line 7
Process exited with code 255.