我看过很多关于这个主题的问题,但没有一个能涵盖我的情况。
我正在构建一个基于 5 个类的 ACL 模块:
- 角色
- 特权
- 组
- Wrapper(猜猜它做了什么..)Privilege、Role 和 Group 类的工厂
- 组/角色的 AccessList 存储(基于使用情况和案例)
我正在考虑使用 SplQueue 来存储权限级别(主要用于继承权限)所以我正在考虑使用单个对象来存储所有内容并且不认为普通的多维数组将是最佳选择.流程将类似于 this paste ,它是 TL;DR.. 对此感到抱歉。
So my question is will the SplQueue be an overkill in my case?
Should I use and alternative Spl Data Structure, and if so which one?
编辑 好吧,我想不出一个很好的用法示例,所以让我们继续使用基于 UNIX 的 GBAC。
最佳答案
如果您想以对象形式存储数据,请使用SplObjectStorage
。 SplQueue 对于小阵列来说会过大。
SplQueue works on FIFO.
因此您不能直接访问到最后或接近最后,并且需要时间。
我建议您使用 Array 而不是 SplQueue
,因为您可以通过数组索引直接访问任何元素。
您也可以查看这个问题的答案:Associative Array versus SplObjectStorage
您还可以检查 SPLobjectStorage 和数组的性能,here is the code .
更多read here .
SplObjectStorage definitely scaled linearly. Array performance was less predictable (larger standard deviation) with smaller data sets. And SplObjectStorage is indeed a better solution for storing lots of objects in a set.
因此,如果您的数据很小,那么您应该使用数组,否则使用 SplObjectStorage
来处理大量数据。
关于使用 Spl DataStructures 的 PHP 替代多维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17721812/