0

I want to create object from string type variable but I'm failed. I am trying this -

My code:

$variableName="I am a novice OOP programmer";
$variableInstance= new $variableName();

echo $variableInstance;

Output notice is Fatal error: Uncaught Error: Class 'I am a novice OOP programmer' not found

If you kindly get me another answer what is fatal error? And why it may be shown?

Jewel
  • 13
  • 6
  • You are getting the fatal error because the class doesn't actually exist. In order to accomplish what you are after you need to define a class first. – Adam Rodriguez Nov 27 '18 at 05:56
  • Possible duplicate of [instantiate a class from a variable in PHP?](https://stackoverflow.com/questions/534159/instantiate-a-class-from-a-variable-in-php) – yivi Nov 27 '18 at 05:59
  • @Jewel, have you read the duplicate link? – yivi Nov 27 '18 at 08:50
  • Do you understand you can't create an object if the class has not been defined? `$variableName` in your example, needs to be **the name of an existing class**. – yivi Nov 27 '18 at 08:51

0 Answers0