0

I have two class.

First class = database.class.php (sub)->vericek.class.php

Database.class.php is:

Class Database
{
    public function __construct($class)
    {
        foreach($class as $class)
        {
            require_once("sub/" . $class . ".class.php");
            $$class = new $class();
        }
    }
}

$database = new Database(array("vericek"));
$database->vericek->abc();

and vericek.class.php is:

Class vericek
{
    public function abc()
    {
        echo "try";
    }
}

I want to see "try".. but i can't.. I can see this error: Fatal error: Call to a member function abc() on a non-object in C:\AppServ\www\ozetizle\classes\database.class.php on line 32

How can i?

tereško
  • 58,060
  • 25
  • 98
  • 150
Programmer
  • 157
  • 2
  • 3
  • 11

1 Answers1

2

You'll need to assign it as $this->$class = ... because using $$class will be a local variable, just visible in your constructor.

jprofitt
  • 10,874
  • 4
  • 36
  • 46