<?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('string');
var_dump($item->getPrice());
?>
Fatal error: Uncaught TypeError: Item::setPrice(): Argument #1 ($price) must be of type float, string given, called in /in/PYARb on line 27 and defined in /in/PYARb:9
Stack trace:
#0 /in/PYARb(27): Item->setPrice('string')
#1 {main}
thrown in /in/PYARb on line 9
Process exited with code 255.
Fatal error: Uncaught TypeError: Argument 1 passed to Item::setPrice() must be of the type float, string given, called in /in/PYARb on line 27 and defined in /in/PYARb:9
Stack trace:
#0 /in/PYARb(27): Item->setPrice('string')
#1 {main}
thrown in /in/PYARb on line 9
Process exited with code 255.
Catchable fatal error: Argument 1 passed to Item::setPrice() must be an instance of float, string given, called in /in/PYARb on line 27 and defined in /in/PYARb on line 9
Process exited with code 255.