Bug #81386 [NEW]: ReflectionProperty::getDefaultValue() and promoted properties
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)
- enumag at gmail dot com
- enumag at gmail dot comBug #81386 [Com]: ReflectionProperty::getDefaultValue() and promoted properties
- nikic@php.netBug->Doc #81386 [Opn]: ReflectionProperty::getDefaultValue() and promoted properties
- enumag at gmail dot comDoc #81386 [Com]: ReflectionProperty::getDefaultValue() and promoted properties
- selectmumbaigirls dot com at gmail dot comDoc #81386 [Com]: ReflectionProperty::getDefaultValue() and promoted properties
- aromaspa001 at gmail dot comDoc #81386 [Com]: ReflectionProperty::getDefaultValue() and promoted properties
- hotkiran dot com at gmail dot comDoc #81386 [Com]: ReflectionProperty::getDefaultValue() and promoted properties
- hugo dot nicolas dot hn at gmail dot comDoc #81386 [Com]: ReflectionProperty::getDefaultValue() and promoted properties
- kevinhawks14 at aol dot comDoc #81386 [Com]: ReflectionProperty::getDefaultValue() and promoted properties
- evgeeek at gmail dot comDoc #81386 [Com]: ReflectionProperty::getDefaultValue() and promoted properties
- rafr at generaxion dot dkDoc #81386 [Com]: ReflectionProperty::getDefaultValue() and promoted properties