Calling Classes. Best Practice?
Posted: Tue Jul 29, 2008 4:14 pm
I am wondering what is the best practice for calling (initiating) custom classes that do not need to be included/started every time the script is ran. Currently I have a __autoload function for classes I miss, but I'd like to stick away from defaulting to it.
Is it best to manually include and call it everytime?
Create a function?
Create a 'lib' function that can be included into every page (I have a 'lib' class that has a great deal of functions) and will return the class.
Or default to the __autoload() function? Or is there a better way? Or am I doing something REALLY wrong?
Is it best to manually include and call it everytime?
Code: Select all
require_once("folder/file.php");
$var = new class;Code: Select all
function startClass($class)
{
Global $$class;
if(TRUE != is_object($$class))
{
require_once("folder/" . $class .".php");
$this->$class = new $class;
}
else
{
$this->$class = $$class;
}
}
Code: Select all
function startClass($class)
{
Global $$class;
if(TRUE != is_object($$class))
{
require("folder/" . $class . ".php");
return new $class;
}
else
{
return $$class;
}
}