douji1058 2014-06-09 14:35
浏览 106
已采纳

PHP:实例化一个类并获取属性

Is it possible it instantiate a new class and get a property without assigning it to a variable object.

example:

$fileid = 1;
$filepath = new fileclass($fileid)->path;

I know the above is incorrect but is the concept possible?

  • 写回答

1条回答 默认 最新

  • dongxuandong2045 2014-06-09 14:36
    关注

    It is in PHP >= 5.4.0

    $filepath = (new fileclass($fileid))->path;
    

    The brackets are important

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?