PHP 5.3.2:实例化对象的不推荐使用的方法?

问题描述:

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?

获取死亡白屏,因此决定远程调试我怀疑使用now实例化对象的应用程序 不支持的方法: p>

$ type ['content_object'] = new $ type ['handler_class'](); code> p>

这仍然合法吗? p> div>

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()
?>