bookmark - Php Magic Method Magic:To represent the thinks

Php Magic Method - Magic:To represent the thinks

 
 Discussion by veerumits with 0 Replies.
 Last Update: November 10, 2008, 5:53 pm
 
bookmark - Php Magic Method Magic:To represent the thinks  
    
free web hosting
 
PHP 5, have magic method:--

The __autoload() Magic Method:- The __autoload() magic method get automatically called whenever you try to load an object of the class in which resides in separate file and even you have not included those files using any of these method include,require and include_once. but It is neccessary to use the filename as that of the class name.

for example:-
//file name: abc.php;

CODE

<?php
class abc{
var $user="Raju";
var $city="delhi";
function xyz(){ echo "Hello ".$this->user." Your city is ".$this->city; }
}
?>

//file name: xyz.php;

CODE

<?php
function __Autoload($x){ include_once("$x.php"); }
$obj=new abc;
echo $obj->user."<br>";
echo " &nbsp <br>".$obj->xyz();
?>


output when you brows xyz.php:

Raju
Hello Raju Your city is delhi

here what we see in xyz.php not have any class with the name of abc even i have create here object of class abc,
it is automatically called because i am using magic method __autoload($x), $x is variable which is assign by the name of filename abc and in include _once("$x.php"); it become include _once("abc.php"); so this is magic because it represent something like magic.

both file should be in same directory.

thanks.

Mon Nov 10, 2008    Reply    New Discussion   


Quickly Post to Php Magic Method Magic:To represent the thinks w/o signup Share Info about Php Magic Method Magic:To represent the thinks using Facebook, Twitter etc. email your friend about Php Magic Method Magic:To represent the thinks Print
Reply / Comment Ask a Question? Share / Bookmark E-Mail a Friend Print

View Php In Another Server   View Php In Another Server (5) (1) Php Iteration - Object Overloading Difference between iteration and overloading  Php Iteration - Object Overloading Difference between iteration and overloading