Results for Interface

PHP Object Oriented Programming (OOP) | Introduction to object oriented programming in PHP

April 29, 2021

Object Oriented Programming (OOP)

Object Oriented Programming in PHP


Introspection:

  • It is the ability of a program to examine an object’s characteristics, such as its name, parent class, properties and methods.
  • Introspection, allow you to
  • Obtain name of class to which on objects belongs and properties and methods
  • Write generic debugger, serializes, profile etc.

Examining Classes:

The introspective functions provide by PHP


1.  class_exists() : To determine whether a class exits, takes in a string and return a Boolean value.
      Syntax: $yes_no=class_exists(classname);
 
2. get_declared_classes () : Return an array of defined classes and you can verify the class name in the     returned array :
    syntax : $classes = get_declared_classes();
 
3. get_class_methods() : You can get the methods and properties that exist in a class. This function taks     a class name and returns an array:
    syntax : $methods = get_class_methods(classname);
 
4. get_class_vars() : returns only properties that have default values
    syntax : $properties = get_class_vars(classname);
 
5. get_class() : To get the class to which an object belongs, first check if it is an object using the                 is_object function, then get the class with the get_class() function
     syntax : $yes_no = is_object(var);
     $classname = get_class(object);
 
6. get_parent_class() : Retrive parent class name for object or class.
    Syntax : superclass = get_class(object);
 
7. get_object _vars() : Returns an array of properties that are set in an object.
    Syntax : $array = get_object_vars(object);
 
8. method_exists() : Before calling a method on an object, you can check that is exists using the function :
    syntax : $yes_no = method_exists(object, method);

PHP Object Oriented Programming (OOP) | Introduction to object oriented programming in PHP PHP Object Oriented Programming (OOP)  | Introduction to object oriented programming in PHP Reviewed by technical_saurabh on April 29, 2021 Rating: 5
Powered by Blogger.