This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

PHP Destructor

The fruit is Apple.

I figured out the reason PHP is displaying the information at the end of the file instead of above. The lesson provided wrong information!!! I modified the code to show both the correct code and the wrong code.

<?php 
// define class Fruit
class Fruit {
  public $name;
  public $color;

// define __construct()
  function __construct($name) {
    $this->name = $name; 
    echo "<p>The fruit is {$this->name}.</p>"; 
  }

// define __destruct()
  function __destruct() {
    echo "<p>The fruit is {$this->name}.</p>"; 
  }

}
$apple = new Fruit("Apple");
?>

The fruit is Apple.