·  PHP – Syntax – OOP – Classes – Helper Functions


- Info:

  - This tutorial shows helper functions for working with classes.


- Example:

  - Creat PHP Console Application Test.php.






      class Person {

        var $name = "John";

        var $age  = 50;

        function func1() {}

        function func2() {}



      class Soldier extends Person {}



      $person  = new Person();

      $soldier = new Soldier();



      $bool         = class_exists     ("Person"); //TRUE if class is defined.

      $className    = get_class        ($person);  //Name of the class to which object belongs.

      $methods      = get_class_methods("Person"); //Return indexed array with method names.

      $vars         = get_class_vars   ("Person"); //Return associative array with fields name/values.

      $classes      = get_declared_classes();      //Return indexed array of all declared classes.

      $objvars      = get_object_vars  ($person);  //Return associative array with fields name/values.

      $parentClass  = get_parent_class ($person);  //NOT WORKING.


      $objOfClass   = is_a          ($person ,"Person"); //TRUE if object belongs to given class.

      $objOfSubclass= is_subclass_of($soldier,"Person"); //TRUE if object's class extends given class.

      $methodExists = method_exists ($person ,"func1" ); //TRUE if object contains given method. 



      echo("bool     =$bool     \n");