3v4l.org

run code in 500+ PHP versions simultaneously
<?php class HOGE{ public string $tel{ set{ if(!ctype_digit($value)){ throw new ValueError("電話番号は数値のみ"); } if(strlen($value) < 10){ throw new ValueError("電話番号は10文字以上"); } $this->tel = $value; } get{ return '電話番号は' . $this->tel; } } } $hoge = new HOGE(); $hoge->tel = '123456789012'; // OK // $hoge->tel = 'abcdefghijkl'; // Uncaught ValueError: 電話番号は数値のみ // $hoge->tel = '123'; // Uncaught ValueError: 電話番号は10文字以上 echo $hoge->tel; // "電話番号は123456789012"
Output for 8.3.5
Parse error: syntax error, unexpected token "{", expecting "," or ";" in /in/6uVrU on line 4
Process exited with code 255.

preferences:
45.41 ms | 493 KiB | 3 Q