运行 ❯
获取你
自己的 PHP
服务器
×
更改方向
更改主题,深色/浅色
进入 Spaces
<!DOCTYPE html> <html> <body> <?php interface Machine { public function activate(); public function deactivate(); public function isActive(); } class Kettle implements Machine { private $isOn = false; public function activate() { $this->isOn = true; } public function deactivate() { $this->isOn = false; } public function isActive() { return $this->isOn; } } $machine = new Kettle(); $machine->activate(); if($machine->isActive()) { echo "The machine is on"; } else { echo "The machine is off"; } echo "<br>"; $machine->deactivate(); if($machine->isActive()) { echo "The machine is on"; } else { echo "The machine is off"; } ?> </body> </html>
机器已开机
机器已关机