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

From: Date: Thu, 26 Aug 2021 10:33:43 +0000
Subject: Bug #81386 [Com]: ReflectionProperty::getDefaultValue() and promoted properties
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-19109@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81386&edit=1

 ID:                 81386
 Comment by:         enumag at gmail dot com
 Reported by:        enumag at gmail dot com
 Summary:            ReflectionProperty::getDefaultValue() and promoted
                     properties
 Status:             Open
 Type:               Bug
 Package:            Documentation problem
 PHP Version:        8.0.9
 Block user comment: N
 Private report:     N

 New Comment:

Forgot to mention: ReflectionProperty::hasDefaultValue() needs to be fixed or better documented as
well.


Previous Comments:
------------------------------------------------------------------------
[2021-08-26 10:30:38] enumag at gmail dot com

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 this bug report at https://bugs.php.net/bug.php?id=81386&edit=1


Thread (11 messages)

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