protected member variable : protected « Class « PHP






protected member variable


<?php

   class Staff
   {
      protected $name;
      protected $title;

      function __construct()
      {
         echo "<p>Staff constructor called!</p>";
      }
   }

   class Manager extends Staff
   {
      function __construct()
      {
         parent::__construct();
         echo "<p>Manager constructor called!</p>";
      }
   }

   $employee = new Manager();

?>

           
       








Related examples in the same category

1.Class members' visibility
2.Class using access control
3.Private and protected variables
4.Properties and methods marked as protected are accessible only through the object that owns them