Result Size: 1264 x 19
x
 
<!DOCTYPE html>
<html>
<body>
<?php
class Fruit {
  public $name;
  public $color;
  public function __construct($name, $color) {
    $this->name = $name;
    $this->color = $color;
  }
  protected function intro() {
    echo "Плод {$this->name} цвет {$this->color}.";
  }
}
class Strawberry extends Fruit {
  public function message() {
    echo "Я фрукт или ягода? ";
    // Вызов защищенной функции из производного класса - ОК
    $this -> intro();
  }
}
$strawberry = new Strawberry("Strawberry", "red");  // OK. __construct() is public
$strawberry->message(); // OK. message() является общедоступным и вызывает intro() (который защищен) из производного класса
?>
</body>
</html>
                
Я фрукт или ягода? Плод - клубника, красный цвет