Skip to content

= new without $value creates it twice. Hooked object. #20813

@ACEx86

Description

@ACEx86

Description

The following code:

<?php
$B = new B;
$B->A = new A;
Class B
{
    Final Object $A{
        get => $this->A;
        set(Object $value) => new A;
    }
}

Class A
{
    public function __construct()
    {
        echo 'A'.PHP_EOL;
    }
}

Resulted in this output:

A
A

But I expected this output instead:

A

In the hooked variable set with = to new A instead of value will call it twice.
If object is not equal to calling value don't do actions.

PHP Version

PHP 8.5.1 (cli) (built: Dec 16 2025 18:26:57) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.1, Copyright (c), by Zend Technologies

Operating System

No response

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