3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Item { // more code public function getPrice() { return $this->price; } public function setPrice(float $price) { $this->price = $price; } public function setTitle(string $title) { $this->title = $title; } public function setPublished(bool $published) { $this->published = $published; } public function setId(int $id) { $this->id = $id; } } $item = new Item(); $item->setPrice('1.2'); var_dump($item->getPrice()); ?>
based on Hq55k
Output for 7.0.0 - 7.2.0
float(1.2)
Output for 5.3.18 - 5.6.28
Catchable fatal error: Argument 1 passed to Item::setPrice() must be an instance of float, string given, called in /in/CbnWu on line 27 and defined in /in/CbnWu on line 9
Process exited with code 255.