0

So I have a file lookup.php that's using spl_autoload_register() at the top. It's also namedspaced as "App\Http\Controllers\StaticObjects"

Within the file I have a method that's used to load in classes dynamically based on an array.

foreach ($this->arrayOfRulesMessages as $value) { 
   //$value = 'Terms1';
   $path = 'RulesAndMessages\'.$value;
   $obj = new $path();
}

This keeps throwing an error saying "Class XXX not found."

Yet when I just use the non-variable way of instantiating the object, like below, everything works fine.

$obj = RulesAndMessages\Terms1

I don't understand how the variable way of doing this isn't working.

Mike Reed
  • 74
  • 7
  • 2
    Is that even the correct syntax? `\'` escapes the single quote which makes that string unterminated. Please, if you have debugging issues make sure you provide code that can actually reproduce your problem. – apokryfos Jan 11 '23 at 05:30

0 Answers0