[php-src] Issue #24795: PHP: Unknown property hooks are accepted inside discarded declarations

From: Date: Tue, 27 Oct 2026 17:18:52 +0000
Subject: [php-src] Issue #24795: PHP: Unknown property hooks are accepted inside discarded declarations
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-253248@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/24795 Author: alwyn1024 ### Description ## Summary PHP 8.5 and PHP 8.6 accept unknown property-hook names when the enclosing declaration is discarded during compilation, even though the same declaration is rejected when retained or compiled normally. This creates a discrepancy in compile-time validation depending on whether the enclosing expression or declaration survives constant folding. ## Minimal reproducer ```php <?php false && static function() { return new class { public int $x { unknown => 1; } }; }; ``` **Actual behavior:** - PHP 8.5.10: Compilation succeeds. - PHP 8.6.0RC4: Compilation succeeds. ### Retained declaration control ```php <?php $f = static function() { return new class { public int $x { unknown => 1; } }; }; ``` Both PHP 8.5.10 and PHP 8.6.0RC4 reject this during compilation. The reported diagnostic is: ```text Fatal error: Unknown hook "unknown" for property class@anonymous::$x, expected "get" or "set" ``` ### Ordinary class declaration control ```php <?php class C { public int $x { unknown => 1; } } ``` Both versions reject this with: ```text Fatal error: Unknown hook "unknown" for property C::$x, expected "get" or "set" ``` ### Valid property-hook control ```php <?php class C { public int $x { get => 1; } } ``` Both versions compile successfully. ### Additional discarded-expression example The following also compiles successfully in both PHP 8.5.10 and PHP 8.6.0RC4: ```php <?php const F = true ? 1 : static function() { return new class { public int $x { unknown => 1; } }; }; ``` ## Expected behavior / clarification requested Should PHP reject an unknown property-hook name regardless of whether its enclosing declaration survives compilation? Specifically, should the discarded closure and conditional-expression examples above fail compilation, or is their acceptance intentional? If acceptance is intentional, what defines the boundary between declarations that must undergo property-hook validation and declarations eliminated during compilation? The question concerns compile-time source validity, not runtime evaluation of unreachable branches. ## Affected versions - PHP 8.5.10 — Windows x64 - PHP 8.6.0RC4 — Windows x64, NTS, VC2022 - PHP 8.6 source commit: f23b4c222cebe33be93ee8ecaaa14390c5507a08 The PHP 8.6 executable was built from the specified source commit. Reproduce by saving each example separately and running: ```powershell php -n -l example.php ``` ## Relevant implementation - [[Property-hook parser productions](https://github.com/php/php-src/blob/f23b4c222cebe33be93ee8ecaaa14390c5507a08/Zend/zend_language_parser.y#L1160)](https://github.com/php/php-src/blob/f23b4c222cebe33be93ee8ecaaa14390c5507a08/Zend/zend_language_parser.y#L1160) - [[zend_get_property_hook_kind_from_name](https://github.com/php/php-src/blob/f23b4c222cebe33be93ee8ecaaa14390c5507a08/Zend/zend_compile.c#L9348)](https://github.com/php/php-src/blob/f23b4c222cebe33be93ee8ecaaa14390c5507a08/Zend/zend_compile.c#L9348) - [[Property-hook compilation](https://github.com/php/php-src/blob/f23b4c222cebe33be93ee8ecaaa14390c5507a08/Zend/zend_compile.c#L9409)](https://github.com/php/php-src/blob/f23b4c222cebe33be93ee8ecaaa14390c5507a08/Zend/zend_compile.c#L9409) The parser permits hook names represented by T_STRING, while compiler validation recognizes get and set. The observed acceptance appears to depend on whether compilation visits the enclosing declaration. I would appreciate clarification on whether this is intended behaviour or a missing validation step for discarded declarations. ### PHP Version ```plain PHP 8.6.0RC4 (cli) (built: Oct 25 2026 12:45:36) (NTS Visual C++ 2022 x64) Copyright © The PHP Group and Contributors Zend Engine v4.6.0RC4, Copyright © Zend by Perforce with Zend OPcache v8.6.0RC4, Copyright ©, by Zend by Perforce ``` ### Operating System Windows x64 (64-bit), MSVC 2022 build

« previous php.bugs (#253248) next »