3v4l.org

run code in 300+ 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"
No results found

preferences:
133.76 ms | 992 KiB | 7 Q