gpt4 book ai didi

PHP:$this->something->($this->foo)->bar 合法吗?

转载 作者:IT老高 更新时间:2023-10-28 13:32:41 26 4
gpt4 key购买 nike

这行 PHP 合法吗?

$this->mongo->($this->db)->$collection_name->insert($document_name);

如果 $this->db 是一个带有要使用的 db 名称的常量。

谢谢

最佳答案

尝试使用花括号代替括号:

$this->mongo->{$this->db}->$collection_name->insert($document_name);

或者将 $this->db 分配给本地变量并使用它来代替:

$db_name = $this->db;
$this->mongo->$db_name->$collection_name->insert($document_name);

关于PHP:$this->something->($this->foo)->bar 合法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4683945/

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