主页
PHP
PHP OOP 析构函数
tryphp_destructor2
运行 ❯
×
更改方向
保存代码
更改主题
<!DOCTYPE html> <html> <body> <?php class Fruit { // Properties var $name; var $color; // Methods function __construct($name, $color) { $this->name = $name; $this->color = $color; } function __destruct() { echo "The fruit is {$this->name} and the color is {$this->color}."; } } $apple = new Fruit("Apple", "red"); ?> </body> </html>
The fruit is Apple and the color is red.