开发者

PHP Get object indentifier

开发者 https://www.devze.com 2023-02-14 12:55 出处:网络
Hopefully this is an easy one for someone.Basically I have a bunch of SQLite3Result objects that store cached data inside a class.I need to be able to reference this data when a method is called with

Hopefully this is an easy one for someone. Basically I have a bunch of SQLite3Result objects that store cached data inside a class. I need to be able to reference this data when a method is called with the result as an argument. I thought it would be best to just keep the cache in an array where the key is a unique identifier for the result object.

So, is there anyway to get a unique indentifier for an object? Like the addressof() function in 'other' languages. 开发者_如何学GoI just need something so that when subsequent calls to a method with the result as an argument I can look up cached data based on that result.


Since your cached data is represented by your SQLite results, you could use their primary key identifiers as identifiers for your caches.

A PHP OOP-based alternative is spl_object_hash(), but this creates a hash for every unique object even if multiple data objects are referenced by the same database row.

0

精彩评论

暂无评论...
验证码 换一张
取 消