·  PHP – Syntax – OOP – Classes – Components – Fields – Scopes – Protected


- Info:

  - Field is declared as protected by using keyword protected.

  - Protected fields are only accessible from within the class in which they are defined or its subclasses.

  - This is in contrast to private fields which are not accessable from subclasses.


- Example:

  - This example shows how to define Class with two fields and one function.

  - Creat PHP Console Application Test.php.





      //USE CLASS.----------------------------------------------------------

      $myObject = new MyClass();   //Create Object from Class.

      $myObject->displayString();  //Function call: Hello from object!

      echo($myObject->var);        //Variable call: Hello from object!


      //DEFINE CLASS.-------------------------------------------------------

      class MyClass {


        public    $var = "Hello from object!\n";

        protected $var2;


        public function displayString() {