Hi internals,
I would like to propose a new RFC titled “Prevent instantiation and cloning of __PHP_Incomplete_Class”.
RFC: https://wiki.php.net/rfc/deprecate-incomplete-class-instantiation
Implementation PR: https://github.com/php/php-src/pull/21325
This RFC proposes to disallow direct instantiation and cloning of the internal class __PHP_Incomplete_Class.
This change introduces a backward compatibility break. The expected impact is small, as __PHP_Incomplete_Class is an internal class and not intended for direct use. Only code that explicitly instantiates or clones it would be affected.
I have two immediate questions for discussion:
-
Should we target PHP 8.6 or PHP 9.x? Given the limited scope of the break, I am currently leaning towards 8.6, though this is a (small) BC break. If we lean towards 9.x, I propose to add deprecations in 8.6.
-
Should instantiation and cloning be voted on separately, or is a single combined vote acceptable?
Feedback is very welcome.
Hi
On 3/3/26 19:02, Jordi Kroon wrote:
I would like to propose a new RFC titled “Prevent instantiation and cloning of __PHP_Incomplete_Class”.
RFC: PHP: rfc:deprecate-incomplete-class-instantiation
Implementation PR: Prevent instantiation and cloning of __PHP_Incomplete_Class by jordikroon · Pull Request #21325 · php/php-src · GitHub
This RFC proposes to disallow direct instantiation and cloning of the internal class __PHP_Incomplete_Class.
I don't find the motivation particularly compelling. Yes, manually instantiating the class is not particularly useful, but it's also not harmful. Similarly for cloning: If the cloning operation works correctly (i.e. it returning a new object with the same state), then it is just behaving according to expectations.
On the contrary, I would like to see fewer behavioral differences between internal classes and userland classes. A class that can only be instantiated by the engine without there being a good engine-related reason is yet another special case that users need to learn about.
Best regards
Tim Düsterhus
PS: Unserialization for unknown classes should just throw an Exception.