php - How to make sure an object exists before performing operations -
i have index.php loads bites of page other php files. @ top of index.php have require_once statements including php class handles db connection , instantiate object of class:
<?php require_once 'libs/databasehandler.php'; $dbh = new databasehandler('localhost', 'root', '*******', 'pride2012'); require_once 'pages/01_includes.php'; require_once 'pages/02_menu.php'; require_once 'pages/03_slider.php'; require_once 'pages/04_news.php'; ?> the page-bit using db managing class 04_news.php, enough constructing object before 04_news.php loads make myself sure object exists before database related operations start?
defining object prior operations enough.
alternatively, can use built-in __autoload( ) method dynamically load classes needed.
take @ php.net: autoloading classes more information.
Comments
Post a Comment