Buat fail Cirle.class.php baharu
Kaedah pengesahan:
<?php function yan($arr) { $bz = true; if ($arr['r']< 0) { $this->error .= "半径小于0;"; $bz = false; } else { if (!is_numeric($arr['r'])) { $this->error .= "半径不是数字;"; $bz = false; } } return $bz; }
Kecuali kaedah pengesahan, kaedah pengiraan dan perbezaan lain, ikuti logik kod secara asasnya :
<?php class Cirle extends Shape { private $r; function __construct($arr = array()) { if (!empty($arr)) { $this->r = $arr['r']; } $this->name = "圆形"; $this->error = ''; } function area() { return pi()* $this->r* $this->r; ; } function zhou() { return 2*$this->r*pi(); } function view($arr) { $form=''; $form .= "<form action='index.php?action=cirle' method='post'>"; $form .= "请输入".$arr['name']."的半径:<input type='text' name='r' value='".$_POST['r']."'/><br>"; $form .= "<br>"; $form .= "<input type='submit' name='sub' value='提交'/> "; $form .= "<input type='reset' name='ret' value='重置'/>"; $form .= "</form>"; echo $form; } function yan($arr) { $bz = true; if ($arr['r']< 0) { $this->error .= "半径小于0;"; $bz = false; } else { if (!is_numeric($arr['r'])) { $this->error .= "半径不是数字;"; $bz = false; } } return $bz; } } ?>
Keputusan larian adalah seperti berikut:
bahagian seterusnya