__autoload() magic method in oop

<?php

/* __autoload() magic method take important part to increase the performance of the application by dynamically include its required class …

Lets have close look at the below programme … here i create two file of class one is named a.class.php and another b.class.php .. now in raw php we call them both at a time .. it does not creat a matter for us what object of class we working in .. means if we create object of a.class.php we include both the classs .. certainly it slow up the performance little bit ..
and the __autoload() method help us to get rid of this .. it include the class only if we create an object of that class and speed up the performance … */

function __autoload($class)
{
require ($class.’.class.php’);
}
$object = new a();

$object->seta(12);
echo $object->geta();
?>

 

 

/*** **** a.class.php ********/

<?php

class a
{
private $a;
public function seta($a)
{
$this->a = $a;
}
public function geta()
{
return $this->a;
}
}

?>

 

/*** **** b.class.php ********/

 

<?php

class b
{
private $b;
public function setb($b)
{
$this->b = $b;
}
public function getb()
{
return $this->b;
}
}

?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s