How can I pass a arbitrary number of arguments to the class constructor using the Object() function defined below?
<?php
/*
./index.php
*/
function Object($object)
{
static $instance = array();
if (is_file('./' . $object . '.php') === true)
{
$class = basename($object);
if (array_key_exists($class, $instance) === false)
{
if (class_exists($class, false) === false)
{
require('./' . $object . '.php');
}
/*
How can I pass custom arguments, using the
func_get_args() function to the class constructor?
$instance[$class] = new $class(func_get_arg(1), func_get_arg(2), ...);
*/
$instance[$class] = new $class();
}
return $instance[$class];
}
return false;
}
/*
How do I make this work?
*/
Object('libraries/DB', 'DATABASE', 'USERNAME', 'PASSWORD')->Query(/* Some Query */);
/*
./libraries/DB.php
*/
class DB
{
public function __construct($database, $username, $password, $host = 'localhost', $port = 3306)
{
// do stuff here
}
}
?>