|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2021-04-05 16:03 UTC] jr at rushlow dot dev
Description: ------------ Calling class_exists() on a class that uses constructor property promotion results in a ParseError. Property promotion is only available in PHP8.0+ but one would expect that you could use class_exists() regardless class implementation. Test script: --------------- // See https://github.com/rushlow-development/attribute-test for a simple reproducer w/ composer && phpunit <?php class PromoteConstructorProperty { public function __construct( public string $var ) { } } $bool = class_exists(PromoteConstructorProperty); Expected result: ---------------- $bool = true Actual result: -------------- ParseError: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 15:00:01 2025 UTC |
Good catch dan! <?php class PromoteConstructorProperty { public function __construct( public string $var ) { } } $bool = class_exists(PromoteConstructorProperty::class); -> https://3v4l.org/4cMW4