note 81249 added to ref.classobj

From: Date: Wed, 20 Feb 2008 06:50:34 +0000
Subject: note 81249 added to ref.classobj
Groups: php.notes 
Request: Send a blank email to php-notes+get-136296@lists.php.net to get a copy of this message
Sorry for my bad language. Main class that ad’s other classes from includes main.php : define(EXT, '.php'); $config = array( 'path' => array ( 'data' => 'data/', 'inc' => 'inc/', 'lang' => 'lng/', 'dl' => 'dl/', ), ... ); class general { private $cfg; public $call = array(); function __construct($configs) { global ${"$configs"}; $this->cfg = $configs; } function _include($filename) { foreach($this->cfg[path] as $dir) { if(file_exists($dir.$filename.EXT)) { include($dir.$filename.EXT); if(class_exists($filename)) { $this->call[$filename] = new $filename(); } return true; } } ... } $main = new general(); // call profiler->start() $main->call[profiler]->start(); profiler.php : class profiler { // simple profiler private $time_start; private function get_time() { list($usec, $sec) = explode(' ', microtime()); return ((float)$usec + (float)$sec); } function start() { $this->time_start = $this->get_time(); } function finish() { return ($this->get_time() - $this->time_start); } } index.php : require('main.php'); ... $main->call[profiler]->finish(); You can edit $config to add path to other directories, and do $main->_include(‘CLASS) and it will include a script and if class named ‘CLASS exist it will create a new class in call[]. You can easily access class $main->call[‘CLASS] Thank you for reading. ---- Server IP: 69.147.83.197 Probable Submitter: 80.64.102.155 ---- Manual Page -- http://www.php.net/manual/en/ref.classobj.php Edit -- https://master.php.net/note/edit/81249 Del: integrated -- https://master.php.net/note/delete/81249/integrated Del: useless -- https://master.php.net/note/delete/81249/useless Del: bad code -- https://master.php.net/note/delete/81249/bad+code Del: spam -- https://master.php.net/note/delete/81249/spam Del: non-english -- https://master.php.net/note/delete/81249/non-english Del: in docs -- https://master.php.net/note/delete/81249/in+docs Del: other reasons-- https://master.php.net/note/delete/81249 Reject -- https://master.php.net/note/reject/81249 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136296) next »