Bug #80938 [Nab]: ParseError with class_exists & property promotion
Edit report at https://bugs.php.net/bug.php?id=80938&edit=1
ID: 80938
User updated by: jr at rushlow dot dev
Reported by: jr at rushlow dot dev
-Summary: jr@rushlow.dev
+Summary: ParseError with class_exists & property promotion
Status: Not a bug
Type: Bug
Package: Class/Object related
PHP Version: 7.4.16
Block user comment: N
Private report: N
New Comment:
oops..
Previous Comments:
------------------------------------------------------------------------
[2021-04-05 16:32:11] jr at rushlow dot dev
Good catch dan!
<?php
class PromoteConstructorProperty
{
public function __construct(
public string $var
) {
}
}
$bool = class_exists(PromoteConstructorProperty::class);
-> https://3v4l.org/4cMW4
------------------------------------------------------------------------
[2021-04-05 16:23:26] danack@php.net
https://3v4l.org/oEW4q even
------------------------------------------------------------------------
[2021-04-05 16:22:56] jr at rushlow dot dev
That makes sense. But to put it another way for clarity - calling class_exists() on a class that is
not correctly defined for the PHP version used a runtime cannot be done?
If that is the case - should we change the docs to reflect this?
"class_exists â Checks if the class has been defined" -> https://www.php.net/manual/en/function.class-exists.php
I'll start a thread in internals (to further discuss options) if the above is true as it would
seem that one can no longer use class_exists() in code bases that support multiple PHP versions.
Granted I may be missing something obvious :)
------------------------------------------------------------------------
[2021-04-05 16:22:25] danack@php.net
Incidentally, the reproduce code gives a different error https://3v4l.org/oEW4q:
Fatal error: Uncaught Error: Undefined constant "PromoteConstructorProperty" in
/in/oEW4q:11
class_exists(PromoteConstructorProperty);
should probably be:
class_exists(PromoteConstructorProperty::class);
------------------------------------------------------------------------
[2021-04-05 16:05:30] nikic@php.net
class_exists() with autoload:true (the default) will load the class. If the class declaration
doesn't parse, you get an error, as usual.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=80938
--
Edit this bug report at https://bugs.php.net/bug.php?id=80938&edit=1
Thread (8 messages)