dongpin4611 2011-09-06 13:33
浏览 28
已采纳

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?

  • 写回答

1条回答 默认 最新

  • douyue4334 2011-09-06 13:36
    关注

    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()
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部