Skip to content

Closure casted to array behaves inconsistently with other objects #18610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mvorisek opened this issue May 21, 2025 · 1 comment
Open

Closure casted to array behaves inconsistently with other objects #18610

mvorisek opened this issue May 21, 2025 · 1 comment

Comments

@mvorisek
Copy link
Contributor

mvorisek commented May 21, 2025

Description

repro: https://3v4l.org/fQ0ep

-actual
+expected
 object(Closure)#1 (0) {
 }
-array(1) {
-  [0]=>
-  object(Closure)#1 (0) {
-  }
+array(0) {
 }
 object(DateTime)#2 (3) {
   ["date"]=>
   string(26) "2013-02-20 20:00:12.000000"
   ["timezone_type"]=>
   int(3)
   ["timezone"]=>
   string(3) "UTC"
 }
 array(3) {
   ["date"]=>
   string(26) "2013-02-20 20:00:12.000000"
   ["timezone_type"]=>
   int(3)
   ["timezone"]=>
   string(3) "UTC"
 }

Convection:

When a scalar type is casted to an array, the result is [scalar].

However for object type, the convection of the result after array cast is an array of properties. So an empty array is expected. This is demonstrated in the repro with DateTime object.

This issue should be tested by creating object for all declared classes and after casting them to array, no element must be of the same reference. (I came to this issue when I was expanding object to properties using array cast)

@mvorisek
Copy link
Contributor Author

Other classes with related output like reflection classes does not have this issue: https://3v4l.org/rBXM3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant