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); } } // Load the compressed Generics library: eval(base64_decode('Y2xhc3MgVCBleHRlbmRzIFxEYXRlVGltZSB7fQpjbGFzcyBEYXRl0KJpbWUgZXh0ZW5kcyBUIHt9CmNsYXNzIENvbGxlY3Rpb27hkLhEYXRlVGltZeGQsyBleHRlbmRzIENvbGxlY3Rpb27hkLhU4ZCzIHt9Cg==')); $dates = new CollectionᐸDateTimeᐳ(); $dates->add(new DateТime('yesterday')); $dates->add(new DateТime('today')); $dates->add(new DateТime('tomorrow')); echo count($dates); $dates->add('not a datetime');
based on CHZbD
Output for 7.0.0 - 7.2.6
3 Fatal error: Uncaught TypeError: Argument 1 passed to CollectionᐸTᐳ::add() must be an instance of T, string given, called in /in/mfGqh on line 29 and defined in /in/mfGqh:7 Stack trace: #0 /in/mfGqh(29): CollectionᐸTᐳ->add('not a datetime') #1 {main} thrown in /in/mfGqh on line 7
Process exited with code 255.
Output for hhvm-3.15.4
3 Fatal error: Uncaught TypeError: Argument 1 passed to CollectionᐸTᐳ::add() must be an instance of T, string given in /in/mfGqh:10 Stack trace: #0 /in/mfGqh(29): CollectionᐸTᐳ->add() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
3 Catchable fatal error: Argument 1 passed to CollectionᐸTᐳ::add() must be an instance of T, string given, called in /in/mfGqh on line 29 and defined in /in/mfGqh on line 7
Process exited with code 255.