Posts

Isset Method

  <?php //To check Whether any value is set OR Not to any Variable We can use isset() method. //isset() function returns two values 1(True) OR 0(False). class Student {     public $course ;     private $first_name ;     private $last_name ;     private $detail = [ "name" => "Test name" , "age" => "30" ];     public function setName ( $fname , $lname )     {         $this -> first_name = $fname ;         $this -> last_name = $lname ;     }         // public function __isset($property)         // {         //     echo isset($this->$property);         // }     public function __isset ( $name )     {         echo isset ( $this -> detail [ $name ]);     } } $test = new Student (); $test -> setName ( "...

CallStatic Method

  <?php //When we try to call any private static method from outside the class at that time __callStatic() //method will automatically call. class Student {     private static function hello ( $name )     {         echo "This is static hello function" . "<br>" ;         echo "Good Morning : $name " ;     }     public static function __callStatic ( $method , $args )     {         echo "This is Private Method : $method " . "<br>" ;         if ( method_exists ( __class__ , $method ))         {             call_user_func_array ([ __class__ , $method ], $args );         }         else         {             echo "Method does not exist : $method " ;         }     } }...

Call method

  <?php //__call() is a Magic method. //__call() method will automatically call when we try to call any Private method OR any Non //Existing method. class Student {     private $first_name ;     private $last_name ;     private function setName ( $fname , $lname )     {         $this -> first_name = $fname ;         $this -> last_name = $lname ;     }     public function __call ( $method , $args )     {         echo "This is privated Method OR Non Existing Method : $method " . "<br>" ;         print_r ( $args );         echo "<br>" ;         if ( method_exists ( $this , $method ))         {             call_user_func_array ([ $this , $method ], $args );         }         el...

Set Method

<?php //__set() method is a Magic Method. __set() method will automatically call while assigning value to // private propety OR Non Existing property OR assigning value to the property which is not Exist. // When we access any private property OR Non Existing at that time __get() method will be called //and When We try to assign value to any private property OR Non Existing Property at that time //__set() method will be called. This is the Main difference between __get() and __set() method. class Student {     private $name ;     public function showMessage ()     {         echo $this -> name ;     }     public function __get ( $property )     {         echo "You are trying to access non Existing OR Private property ( $property )" . "<br>" ;     }     public function __set ( $property , $value )     {         echo "...

Get Method

  <?php //__get() method is a Magic Method. __get() method will automatically call while accessing private //propety OR Non Existing property OR accessing the property which is not Exist. class Abc {     private $name = "Yahoo Baba" ;     private $data = [ "name" => "Yahoo Baba" , "course" => "PHP" , "fee" => "2000" ];     // public function __get($property)     // {     //     echo "You are trying to access Non Existing OR Private property($property)" . "<br>";     // }     public function __get ( $key )     {         if ( array_key_exists ( $key , $this -> data ))         {             return $this -> data [ $key ];         }         else         {             return "This key( $key ) is not defined." ...

Destruct Method

  <?php //__destruct() method will automatically call when object related all the operations will completed //as shown below: class Abc {     public function __construct ()     {         echo "This is Construct Function" . "<br>" ;     }     public function hello ()     {         echo "Hello Everyone" . "<br>" ;     }     public function __destruct ()     {         echo "This is destruct Function" . "<br>" ;     } } $test = new Abc (); $test -> hello (); $test -> hello (); $test -> hello (); //OUTPUT: //This is Construct Function // Hello Everyone // Hello Everyone // Hello Everyone // This is destruct Function ? >

Magic Methods

  <?php //MAGIC METHODS WILL AUTOMATICALLY CALL(RUN) BASED ON CONDITION. //MAGIC METHODS WILL ALWAYS START WITH (__)DOUBLE UNDERSCORES. //MAGIC METHODS AVAILABLE IN PHP AS SHOWN BELOW: //__construct(), __destruct(), __get(), __set(), __isset(), __unset(), __autoload(), __clone(), //__sleep(), __wakeup(), __call(), __callStatic(), __toString(), __invoke() ? >