Skip to content

Infinite recursion in property hooks inside traits. #15280

Closed
@SerafimArts

Description

@SerafimArts

Description

Referenced RFC #13455

Positive Case

<?php

class FirstExample
{
    public string $value = 'default' {
        get => $this->value;
    }
}

echo new FirstExample()->value; // "example"

Negative Case

<?php

trait TraitWithProperty
{
    public string $value = 'default' {
        get => $this->value;
    }
}

class SecondExample
{
    use TraitWithProperty;
}

echo new SecondExample()->value;

// Fatal error: Uncaught Error: Maximum call stack size of 8339456 bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. Infinite recursion? in /test.php:15
// Stack trace:
// #0 /test.php(15): SecondExample->$value::get()
// #1 ....

@iluuu1994 I think it makes sense to mention you as the maintainer of the feature. It seems like this is not a duplicate issue, a known problem?

PHP Version

PHP 8.4-alpha2

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