Bug #80938 [Opn->Nab]: ParseError with class_exists & property promotion

From: Date: Mon, 05 Apr 2021 16:05:30 +0000
Subject: Bug #80938 [Opn->Nab]: ParseError with class_exists & property promotion
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233178@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80938&edit=1

 ID:                 80938
 Updated by:         nikic@php.net
 Reported by:        jr at rushlow dot dev
 Summary:            ParseError with class_exists & property promotion
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Class/Object related
 PHP Version:        7.4.16
 Block user comment: N
 Private report:     N

 New Comment:

class_exists() with autoload:true (the default) will load the class. If the class declaration
doesn't parse, you get an error, as usual.


Previous Comments:
------------------------------------------------------------------------
[2021-04-05 16:03:13] 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)


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80938&edit=1


Thread (8 messages)

« previous php.bugs (#233178) next »