问题
Getting a white screen of death, so decided to remote debug an application that I suspect is instantiating an object using a now unsupported method:
$type['content_object'] = new $type['handler_class']();
Is this still legitimate?
回答1:
Assuming $type['handler_class']
is a string containing the name of a class, then it's fine, according to the manual:
If a string containing the name of a class is used with new, a new instance of that class will be created.
<?php $instance = new SimpleClass(); // This can also be done with a variable: $className = 'Foo'; $instance = new $className(); // Foo() ?>
来源:https://stackoverflow.com/questions/7326437/php-5-3-2-deprecated-method-of-instantiating-an-object