|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-11-17 13:35 UTC] cmb@php.net
-Package: *General Issues
+Package: Scripting Engine problem
-Assigned To:
+Assigned To: nikic
[2021-11-17 13:35 UTC] cmb@php.net
[2021-11-17 13:38 UTC] nikic@php.net
-Status: Assigned
+Status: Not a bug
[2021-11-17 13:38 UTC] nikic@php.net
[2021-11-17 14:16 UTC] cmb@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 22:00:01 2025 UTC |
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) }