Übergeben von Argumenten an den Konstruktor der Klasse

Wie kann ich übergeben eine beliebige Anzahl von Argumenten an den Konstruktor der Klasse mit dem Objekt () - Funktion unten definiert?

<?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
    }
}

?>
InformationsquelleAutor Alix Axel | 2009-04-23
Schreibe einen Kommentar