Sunday, 15 August 2010

php - accessing a class from another class -



php - accessing a class from another class -

i have thought requires loading in class. let's have index.php includes 1 time (database.php). in class, is acceptable create new object not extended class? in otherwords, brining in content globally instead? here's mean...

index.php: ---------------------- include_once ('./core/dataaccess.php'); .... class home { private function getusers() { $dataaccess = new dataaccess(); } }

it's acceptable , used practice, in cases not best solution. advanced way using dependency injection, means other objects needed class " injected" outside, making them interchangeable. happen in constructor, in setter method or straight parameter needed.

the methods utilize new keyword mill methods nil else creating objects.

php oop class

No comments:

Post a Comment