gpt4 book ai didi

php - 内联 PHP 克隆

转载 作者:行者123 更新时间:2023-12-03 00:08:15 24 4
gpt4 key购买 nike

尝试在 PHP 5.2.9 中执行此操作时:

$foo = (clone $template)->bar();

PHP 给我一个语法错误:

Parser error "';' expected after expression (Found token: ->)"

我做错了什么吗?或者根本没有办法克隆内联对象,这样我就必须将语句分成两行?

最佳答案

不幸的是,PHP 不允许使用该语法(在任何版本中)。作为将其分成两行的替代方法,您可以这样做:

$foo = call_user_func(array(clone $template, 'bar'));

关于php - 内联 PHP 克隆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22512027/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com