Bug #81386 [NEW]: ReflectionProperty::getDefaultValue() and promoted properties

From: Date: Thu, 26 Aug 2021 10:30:38 +0000
Subject: Bug #81386 [NEW]: ReflectionProperty::getDefaultValue() and promoted properties
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-19108@lists.php.net to get a copy of this message
From:             enumag at gmail dot com
Operating system: 
PHP version:      8.0.9
Package:          Documentation problem
Bug Type:         Bug
Bug description:ReflectionProperty::getDefaultValue() and promoted properties

Description:
------------
Currently when you declare a promoted property with a default value the
ReflectionProperty::getDefaultValue() won't return that value.

I'm not sure if this behavior is expected or not but in either case
something needs to be changed.

If this behavior is unexpected then it should be fixed to return the
correct value.

If this behavior is expected then the documentation of
ReflectionProperty::getDefaultValue() should mention this drawback along
with a few lines of code how to get to the relevant ReflectionParameter
and get the value there.

Test script:
---------------
<?php

class X {
    public function __construct(
        public bool $y = false
    ) {
    }
}

var_export((new ReflectionProperty('X', 'y'))->getDefaultValue());

Expected result:
----------------
Either the value should be returned or this behavior needs to be
documented.

Actual result:
--------------
The default value is not returned and there is no mention of this
behavior in the documentation

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


Thread (11 messages)

« previous php.doc.bugs (#19108) next »