Skip to content

Conversation

@alexandre-daubois
Copy link
Member

Because the API is different depending on if you deal with hash maps or lists, it would be nice to expose a method that returns whether the hashtable is packed.

My use case: I'm getting back to callable support and while writing a custom array_map(), I want to keep indexes if it's not a list. I have to check whether the provided hash table is packed or not.


// IsPacked determines if the given zval pointer represents a packed array (list).
// Returns false if the zval is nil, not an array, or not packed.
func IsPacked(zval unsafe.Pointer) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it take a HashTable instead of a zval?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exported functions receive arrays as a zval. That's why I preferred to create a new function instead of just exposing htIsPacked: it's a bit more flexible and allow a quick check without having to do manual casts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1894

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, let's wait for it to be merged before going forward with this one then 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants