Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.1 new in initializers support #104

Open
Ocramius opened this issue Sep 14, 2021 · 5 comments
Open

PHP 8.1 new in initializers support #104

Ocramius opened this issue Sep 14, 2021 · 5 comments
Assignees

Comments

@Ocramius
Copy link
Member

https://wiki.php.net/rfc/new_in_initializers

@Ocramius Ocramius added this to the 4.5.0 milestone Sep 14, 2021
@Ocramius Ocramius self-assigned this Sep 14, 2021
@Ocramius Ocramius changed the title PHP 8.1 new in initializers suppoy PHP 8.1 new in initializers support Sep 22, 2021
@michaelpetri
Copy link
Contributor

This one should be implemented as a new flag as well? PropertyGenerator::FLAG_IN_INITIALIZER ?

@Ocramius
Copy link
Member Author

Difficult to say: I think this is part of ParameterGenerator, not PropertyGenerator? 🤔

The bulk of all logic lives in the ValueGenerator, which is not currently capable of complex expressions:

class ValueGenerator extends AbstractGenerator

It may perhaps be something relevant post-release, but the isomorphism between ParameterGenerator and ReflectionParameter is something we should try to achieve

@michaelpetri
Copy link
Contributor

Will give it a try on wednesday @lyska or after my other two open patches ✌️

@Ocramius
Copy link
Member Author

As discussed with @michaelpetri, the problem with new in initializers is that we can't deduct a PHP expression for generating a value, when given a value.

The ValueGenerator would need radical adjustments here, but it would not be capable of generating an expression in a reliable way.

For example:

class MyDefaultValue {
    public int $value;
    public function __construct() {
        $this->value = random_int(1, 10000);
    }
}

$value = new MyDefaultGenerator();

// this is potentially wrong: `'new MyDefaultValue()'` is probably not reliable either?
$parameterGenerator->setDefaultValue(ValueGenerator::fromObject($value)); 

I don't think it is realistically feasible to solve this problem by 4.5.0, and therefore removing the milestone.

@Ocramius Ocramius removed this from the 4.5.0 milestone Nov 29, 2021
@nicolas-grekas
Copy link
Contributor

nicolas-grekas commented Apr 27, 2022

This might be doable by casting reflectors to string since php/php-src#7540

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants