主页
PHP
PHP OOP 析构函数
tryphp_destructor
运行 ❯
×
更改方向
保存代码
更改主题
<!DOCTYPE html> <html> <body> <?php class Fruit { public $name; public $color; function __construct($name, $color) { $this->name = $name; $this->color = $color; } function __destruct() { echo "Name: " . $this->name . ". Color: " . $this->color .".<br>"; } } $apple = new Fruit('Apple', 'Red'); $banana = new Fruit('Banana', 'Yellow'); ?> </body> </html>
The fruit is Apple.