Skip to content

Property hook variable missing when using get_object_vars #17988

@iquito

Description

@iquito

Description

The following code: (see https://3v4l.org/jnJJe#v8.4.4)

<?php

final class SomeAction
{
    public function __construct(
        public ?string $powerOfAttorneyDate = null {
            set => $value === '' ? null : $value;
        },
    ) {
    }
}

$data = new SomeAction('2025-01-01');

echo "powerOfAttorneyDate is included when printing the obj:\n";
echo print_r($data, true);

echo "powerOfAttorneyDate is missing (bug) when using get_object_vars:\n";
echo print_r(get_object_vars($data), true);

echo "powerOfAttorneyDate is included when using foreach on the object:\n";
foreach ($data as $name => $value) {
  echo $name . ' => ' . $value;
}

Resulted in this output:

powerOfAttorneyDate is included when printing the obj:
SomeAction Object
(
    [powerOfAttorneyDate] => 2025-01-01
)
powerOfAttorneyDate is missing (bug) when using get_object_vars:
Array
(
)
powerOfAttorneyDate is included when using foreach on the object:
powerOfAttorneyDate => 2025-01-01

But I expected this output instead:

powerOfAttorneyDate is included when printing the obj:
SomeAction Object
(
    [powerOfAttorneyDate] => 2025-01-01
)
powerOfAttorneyDate is missing (bug) when using get_object_vars:
Array
(
    [powerOfAttorneyDate] => 2025-01-01
)
powerOfAttorneyDate is included when using foreach on the object:
powerOfAttorneyDate => 2025-01-01

PHP Version

PHP 8.4.4

Operating System

No response

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions