Bug #80938 [NEW]: ParseError with class_exists & property promotion

From: Date: Mon, 05 Apr 2021 16:03:13 +0000
Subject: Bug #80938 [NEW]: ParseError with class_exists & property promotion
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233176@lists.php.net to get a copy of this message
From:             jr at rushlow dot dev
Operating system: 
PHP version:      7.4.16
Package:          Class/Object related
Bug Type:         Bug
Bug description:ParseError with class_exists & property promotion

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 bug report at https://bugs.php.net/bug.php?id=80938&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=80938&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=80938&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=80938&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=80938&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=80938&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=80938&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=80938&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=80938&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=80938&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=80938&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80938&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=80938&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=80938&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=80938&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=80938&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=80938&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=80938&r=mysqlcfg


Thread (8 messages)

« previous php.bugs (#233176) next »