php - How can i manage my dependencies? -
i'm working on large php project have many classes, , problem appears when classes depends on others, example error-handling class may depend on security class, user class may depend on database class , on...
$obj1 = new class1(); $obj2 = new class2($obj1); $obj3 = new class3(); $obj4 = new class4($obj3 , $obj1); etc...
hence quesion comes in! best way manage dependancies ?
try autoloading classes. way if class needs class, doesn't have require()
it.
http://php.net/manual/en/function.spl-autoload-register.php
example documentation:
<?php function my_autoloader($class) { include 'classes/' . $class . '.class.php'; } spl_autoload_register('my_autoloader'); // or, using anonymous function of php 5.3.0 spl_autoload_register(function ($class) { include 'classes/' . $class . '.class.php'; }); ?>
Comments
Post a Comment