gpt4 book ai didi

php - PHP 中的 SplObjectStorage 和含糖语法

转载 作者:可可西里 更新时间:2023-10-31 22:58:08 26 4
gpt4 key购买 nike

快点;我怀疑这是可能的,但是有什么方法可以利用 array($key => $value); PHP 的语法来处理 SplObjectStorage 对象?

我的意思是,有没有这样的方法可以实现:

$store = // ?
new KeyObject() => new ValueObject(),
new KeyObject() => new ValueObject(),
// ...

在初始化对象存储的上下文中?目前我只是在使用:(并且可能会继续,考虑到这种可能性的绝对可能性)

$store = new SplObjectStorage();
$store[new KeyObject()] = new ValueObject();
$store[new KeyObject()] = new ValueObject();
// ...

会很好,高度怀疑它,但也许有人知道得更多。

最佳答案

虽然这会是一个更简洁的语法,但不幸的是这是不可能的。你能做的最好的是:

$store[new KeyObject()] = new ValueObject();

$store->append( new KeyObject(), new ValueObject());

将对象添加到 SplObjectStorage 时。

关于php - PHP 中的 SplObjectStorage 和含糖语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8306758/

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