I am experimenting with PHP7 type hinting. Following code gives 'fatal error'. I tried few methods to no avail. It works Ok when i give int value. But if i give string it crashes. How can i catch type error without crashing my page. The code is:
<?php
class Book{
public $price;
public function price(int $price){
if (is_numeric($price)){
echo 'This is Number ' . $price;
}else{
echo 'Please enter number';
}
}
}
$book = new Book();
$book->price('Hello');
?>