·  PHP – Syntax – OOP – Classes – Components – Methods – Custom – Type Hinting

 

- Info:

  - Type hinting defines valid class for method's input parameter.

 

- Example:

  - This example shows how to access provate method from another method of the same class.

  - Creat PHP Console Application Test.php.

 

    Test.php

    <?php

   

      //CLASS PERSON.-------------------------------------------------------

      class Person {     

        public function displayName()  { echo "John"; }

      }

      

      //CLASS SOLDIER.------------------------------------------------------

      class Soldier extends Person { 

        public function displayName(Person $person) { $person->displayName(); }   

      } 

      

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

      $person  = new Person();

      $soldier = new Soldier();       //Create Object from Class. 

      $soldier->displayName($person); //Call protected method from superclass.

      

    ?>