[php-src] PR #21875: Fix #18542: unserialize() respects class_alias for private properties

From: Date: Sat, 25 Apr 2026 19:24:41 +0000
Subject: [php-src] PR #21875: Fix #18542: unserialize() respects class_alias for private properties
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-35898@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/21875 Author: HakanIST ## Problem When a class with private properties is serialized, the property names are mangled as \0ClassName\0propName. If the class is later aliased via class_alias(), unserialize() fails to match the mangled class name against the actual class entry, causing properties to be treated as dynamic instead of declared. This results in: - Creation of dynamic property is deprecated warning (PHP 8.2+) - Typed property must not be accessed before initialization fatal error ## Root Cause In is_property_visibility_changed() (ext/standard/var_unserializer.re), the mangled class name is only compared against ce->name via strcasecmp(). When class_alias() is used, the mangled string contains the alias name while ce->name holds the canonical class name — these don't match, so the property is not recognized as declared. ## Fix Added a fallback check that uses zend_hash_str_find_ptr_lc(EG(class_table), ...) to verify whether the mangled class name resolves to the same zend_class_entry. This: - Uses **zero heap allocations** (zend_hash_str_find_ptr_lc uses stack-allocated do_alloca internally) - Is only triggered as a **fallback** when the direct name comparison fails, so there is **zero overhead** on the normal (non-alias) path - Does not trigger autoloading (direct hash table lookup) ## Test Added ext/standard/tests/serialize/unserialize_class_alias_private_props.phpt covering private, protected, and public properties with class_alias(). All existing serialization tests (164) and class_alias tests (26) pass with zero regressions. Closes #18542

« previous php.git-pulls (#35898) next »