Re: [RFC] Add is_assoc_array() function

From: Date: Sat, 21 Feb 2026 04:24:26 +0000
Subject: Re: [RFC] Add is_assoc_array() function
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-130118@lists.php.net to get a copy of this message
On 2/20/26 20:35, Muhammed Arshid KV wrote:
Hi internals, I’ve proposed a small RFC to add *is_assoc_array(array $array):* bool to the PHP core. RFC: https://wiki.php.net/rfc/is_assoc_array The function detects associative arrays using internal storage *(HT_IS_PACKED)*. Similar helpers exist in frameworks, and a native version would be faster and more consistent. No BC breaks. No impact on SAPIs or OPcache. Feedback welcome. Thanks, Muhammed Arshid
Your implementation is pretty much the inverse of zend_array_is_list(),[^1] so you could probably simplify it with the following (note the negation operator (!) in front of zend_array_is_list(array).
    PHP_FUNCTION(is_assoc_array)
    {
        HashTable *array;
        ZEND_PARSE_PARAMETERS_START(1, 1)
            Z_PARAM_ARRAY_HT(array)
        ZEND_PARSE_PARAMETERS_END();
        RETURN_BOOL(!zend_array_is_list(array));
    }
For the sake of consistency, I would change the name of the function to array_is_assoc(). Cheers, Ben [^1]: https://github.com/php/php-src/blob/da6d890e00d56fd0d842e844aeac03baf7e47f17/Zend/zend_hash.h#L1602-L1633

Attachment: [application/pgp-signature] OpenPGP digital signature OpenPGP_signature.asc
« previous php.internals (#130118) next »