Skip to content

Closure casted to array behaves inconsistently with other objects #18610

Open
@mvorisek

Description

@mvorisek

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions