Bug #81629 [NEW]: Error casting object to array
| From: | newed2008 at gmail dot com | Date: | Wed, 17 Nov 2021 08:37:34 +0000 |
| Subject: | Bug #81629 [NEW]: Error casting object to array | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-237800@lists.php.net to get a copy of this message | ||
From: newed2008 at gmail dot com
Operating system:
PHP version: 7.4.25
Package: *General Issues
Bug Type: Bug
Bug description:Error casting object to array
Description:
------------
Following the strong typing in the class description, I expect that when
casting an object to an array, the array will match the described types
or throw an exception.
In this example, I also have a property ($typeString) that cannot be
null. I skipped the initialization of this property in the code and
expected that when I tried to transform such an object to an array, I
would get an exception like Typed property ... must not be accessed
before initialization, as if I access an uninitialized property.
I think if the property is in a typed class, then casting to an array
should take into account typing.
Test script:
---------------
class A
{
public int $typeNumber;
public string $typeString;
}
$a = new A();
$a->typeNumber = 1;
var_dump(
(array)$a
);
Expected result:
----------------
Uncaught Error: Typed property A::$typeString must not be accessed
before initialization
Actual result:
--------------
array(1) {
["typeNumber"]=>
int(1)
}
--
Edit bug report at https://bugs.php.net/bug.php?id=81629&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81629&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81629&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81629&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81629&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81629&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81629&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81629&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81629&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81629&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81629&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81629&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81629&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81629&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81629&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81629&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81629&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81629&r=mysqlcfg