Php class loading performance and using extensions,

I have an includes.php page that I load at the top of every page of my website. When I design a website, the number of classes I use is growing. So I get something like this:

$db = new DB($config);
$login = new Login($db, $config);
$form = new Form($db, $config);

And the list goes on and on. I have two questions about this practice:

Firstly, given that I cannot use a class on a specific page (I may not have a $ form on every single page), how important is it to deal with loading this class every time any given page is loaded?

Secondly, you may have noticed that I am passing an instance of the $ db class to all other classes, as well as the $ config variable. In the php code of each class, I am doing something like this:

public $db;
public $config;

public function __construct($db, $config, $smarty){
    $this->db = $db;
    $this->config = $config;
}

'this' :

public function myfunction(){
  $this->db;
  $this->config;
}

'extends', $db , db? $db - ?

!

+5
5

'extends' $db , db?

- , !

:

  • "class A extends B" "class A **is a** B"
    • , a Car a MotorVehicule; a MotorVehicule a Vehicule; a Bus a MotorVehicule; - Vehicule
    • Vehicule
    • a Form DataBase! Login
  • PHP extend
    • - Vehicule Animal
    • Car MotorVehicule, Vehicule : -)

( ), "" . , .

( Form " " ); , . , .


$db

$db , ...
, Injection Dependancy, btw ( , )


, :

  • ,
  • - , APC,

- , ; -)


:

$db - ?

, ; , , , google ... ?

, , ! , , , , : -)

+7

- ?

function __autoload($class_name) {
 require_once("includes/php/class." . $class_name . ".php");
 }

, , . ( php-... class.Object.php, "Object" ).

+4

script , -, apc, .

+2

, ? , , , . , includes.php , .

$db , . ( PHP5, PHP4 '&.)

+1

, ('extends') . $db $config, .

, , - .

$config global. , ? , $db. , , , .

+1

All Articles