Jack
Jack

Reputation: 446

What is new $class() in CodeIgniter

I am working on a project in CodeIgnitor that is written by someone else While studying the code I came across the following line:

$CI = new $class();

is this $class a PHP built in function to instantiate a generic object? or what is it exactly Thanks in advance

Upvotes: 0

Views: 1332

Answers (1)

Lucarnosky
Lucarnosky

Reputation: 514

If you have a class, class ExampleClass, and you have a variable somewhere and you call it $class = "ExampleClass"; you can write the code you specified in the question, which is the same as write $CI = new ExampleClass(). In php you can do that even with variables.

Upvotes: 1

Related Questions