note 102394 modified in language.oop5.autoload by danbrown

From: Date: Fri, 11 Feb 2011 16:14:33 +0000
Subject: note 102394 modified in language.oop5.autoload by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176912@lists.php.net to get a copy of this message
This is an example of how I used autoloading in my application: <?php spl_autoload_register(function ($className) { $possibilities = array( APPLICATION_PATH.'beans'.DIRECTORY_SEPARATOR.$className.'.php', APPLICATION_PATH.'controllers'.DIRECTORY_SEPARATOR.$className.'.php', APPLICATION_PATH.'libraries'.DIRECTORY_SEPARATOR.$className.'.php', APPLICATION_PATH.'models'.DIRECTORY_SEPARATOR.$className.'.php', APPLICATION_PATH.'views'.DIRECTORY_SEPARATOR.$className.'.php', $className.'.php' ); foreach ($possibilities as $file) { if (file_exists($file)) { require_once($file); return true; } } return false; }); ?> --was-- This is an example of how I used autoloading in my application: <?php spl_autoload_register(function ($className) { $possibilities = array( APPLICATION_PATH.'beans'.DIRECTORY_SEPARATOR.$className.'.php', APPLICATION_PATH.'controllers'.DIRECTORY_SEPARATOR.$className.'.php', APPLICATION_PATH.'libraries'.DIRECTORY_SEPARATOR.$className.'.php', APPLICATION_PATH.'models'.DIRECTORY_SEPARATOR.$className.'.php', APPLICATION_PATH.'views'.DIRECTORY_SEPARATOR.$className.'.php', $className.'.php' ); foreach ($possibilities as $file) { if (file_exists($file)) { require_once($file); return true; } } return false; }); ?> http://www.lystadonline.no/ http://php.net/manual/en/language.oop5.autoload.php

« previous php.notes (#176912) next »