Du hast es treffend formuliert, Zergling.
Diesen Code hier, habe ich auch mal ausprobiert, funktioniert.
PHP-Code:
<?php
class classHandle
{
public $handle;
public $className;
public $path;
function __construct($class,$handle=0)
{
$this->handle = $handle;
$this->className[$handle] = $class;
#$this->path[$this->handle] = dirname(__FILE__)."\..\classes\\".$class."\\".$class.".php";
$this->path[$this->handle] = dirname(__FILE__)."\classes\\".$class."\\".$class.".php"; # angepasst...
}
function load($handle=0)
{
if(file_exists($this->path[$handle]))
{ include_once($this->path[$handle]);
$this->tempClass[$handle] = new $this->className; # <<<< fehlerzeile
/**
Der Fehler:
Fatal error: Class name must be a valid object or a string in D:\server\projekte\test\classHandle\classHandle_array_method.php on line 21
**/
// Die Lösung:
#$this->tempClass[$handle] = new $this->className[$handle]; <-- Array
return true; }
else
{ return false; }
}
function getVar($str,$handle=0)
{
return $this->path[$handle];
}
function useIn($function,$handle=0)
{
if(!$this->tempClass[$handle]) { return false; }
return $this->tempClass[$handle]->$function();
}
}
$test = new classHandle('testKlasse');
$test->load();
var_dump($test->getVar('test'));
// Funktioniert mit korrigierter Zeile...
?>