PHP 5.3.2: Deprecated method of instantiating an object?

爷,独闯天下 提交于 2019-12-25 02:25:14

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!