[php-src] Issue #19049: Class constants allow narrowing override from untyped to typed

From: Date: Sun, 06 Jul 2025 09:12:57 +0000
Subject: [php-src] Issue #19049: Class constants allow narrowing override from untyped to typed
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-250380@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/19049 Author: khaledalam ### Description Ref: [RFC: typed_class_constants](https://wiki.php.net/rfc/typed_class_constants#:~:text=Inheritance%20and%20variance) The following code https://3v4l.org/MUm1l: ```php <?php // overriding an untyped parent constant with a typed one class A { public const VALUE = 42; // untyped } class B extends A { public const float VALUE = 42.5; // narrowing to float } echo "Parent type: " . gettype(A::VALUE) . "\n"; echo "Child value: " . B::VALUE . "\n"; ``` Resulted in this output: ``` Parent type: integer Child value: 42.5 ``` But I expected this output instead: ``` Fatal error: Cannot override constant A::VALUE with incompatible type in %s on line %d ``` ### PHP Version ```plain 8.3.0 - 8.3.23, 8.4.1 - 8.4.10 ``` ### Operating System _No response_

« previous php.bugs (#250380) next »