Hi Larry Garfield, > Right now they'd do the same as objects, so they'd serialize as an object. > Unserializing like that, though... hm, that would probably NOT still be === > due to the way PHP handles objects. > That's probably undesireable, but I'm not sure at the moment the best way > around that. I'll have to discuss with Iliya.
At a glance, it seems like it's doable in php 8.1 internals to make the unserializer return a singleton if you override the C `unserialize` callback of the class (this could introduce edge cases during unserialization failure for destruction, expected to be solvable). This would require using the `C:` serialize() encoding (php uses that for classes implementing Serializable), not `o:` (unserialize can be set to a generic C function that creates a value and puts it in `*object*`) ``` // Zend/zend.h struct _zend_class_entry { /* .... serializer callbacks */ int (*serialize)(zval *object, unsigned char **buffer, size_t *buf_len, zend_serialize_data *data); int (*unserialize)(zval *object, zend_class_entry *ce, const unsigned char *buf, size_t buf_len, zend_unserialize_data *data); // ext/standard/var_unserializer.c, in object_custom() if (ce->unserialize == NULL) { zend_error(E_WARNING, "Class %s has no unserializer", ZSTR_VAL(ce->name)); object_init_ex(rval, ce); } else if (ce->unserialize(rval, ce, (const unsigned char*)*p, datalen, (zend_unserialize_data *)var_hash) != SUCCESS) { return 0; } ``` (I'm one of the maintainers of https://pecl.php.net/package/igbinary , an alternative binary php serializer) - Tyson -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php