# Order of properties in (array) cast on PHP 8.1

- Thread: https://externals.io/message/116274
- Original archive: https://news-web.php.net/php.internals/116274
- Started by Benjamin Morel on 2021-10-13T21:45:13+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #116274 — Benjamin Morel — 2021-10-13T21:45:13+00:00

URL: https://externals.io/message/116274#116274

Hi internals,

While running the test suite of one of my libs against PHP 8.1, I noticed
that the order in which properties are returned in an (array) cast has
changed.

For example when casting an instance of this class to array:

class A
{
    private $x = 'x';
}

class B extends A
{
    public $y;
    public $z;
}

On PHP 7.4-8.0, $x is returned last, while on PHP 8.1, it is returned first.

Demo: https://3v4l.org/FTMki

It's not a big deal, but before I change my test suites, I wanted to double
check here if this change was expected?

Thanks in advance,
— Benjamin

---

## #116275 — G. P. B. — 2021-10-13T21:54:34+00:00

URL: https://externals.io/message/116274#116275 · In reply to: #116274

On Wed, 13 Oct 2021 at 22:45, Benjamin Morel <benjamin.morel@gmail.com>
wrote:

> Hi internals,
>
> While running the test suite of one of my libs against PHP 8.1, I noticed
> that the order in which properties are returned in an (array) cast has
> changed.
>
> For example when casting an instance of this class to array:
>
> class A
> {
>     private $x = 'x';
> }
>
> class B extends A
> {
>     public $y;
>     public $z;
> }
>
> On PHP 7.4-8.0, $x is returned last, while on PHP 8.1, it is returned
> first.
>
> Demo: https://3v4l.org/FTMki
>
> It's not a big deal, but before I change my test suites, I wanted to double
> check here if this change was expected?
>
> Thanks in advance,
> — Benjamin
>

Yes, this change is expected and documented, see:
https://www.php.net/manual/en/migration81.other-changes.php#migration81.other-changes.functions.core

Best regards,

George P. Banyard

---

## #116276 — Benjamin Morel — 2021-10-13T22:01:12+00:00

URL: https://externals.io/message/116274#116276 · In reply to: #116275

>
> Yes, this change is expected and documented, see:
>
> https://www.php.net/manual/en/migration81.other-changes.php#migration81.other-changes.functions.core
>

Thanks for the pointer!
And sorry for the noise.

— Benjamin
