8000 New in initializers (reduced version) by nikic · Pull Request #7153 · php/php-src · GitHub
[go: up one dir, main page]

Skip to content

New in initializers (reduced version) #7153

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

Closed
wants to merge 2 commits into from

Conversation

nikic
Copy link
Member
@nikic nikic commented Jun 15, 2021

This is #6746, but allowing new only in:

  • Parameter default values. This includes default values for promoted properties.
  • Attribute arguments.
  • Static variables.
  • Global constants.

It does not allow new in properties and class constants, as these have tricky evaluation order issues, for which no satisfactory resolution was reached.

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

@nikic nikic added the RFC label Jun 15, 2021
@zlianon
Copy link
zlianon commented Jul 2, 2021

for years we get things in half

case ZEND_AST_NEW:
{
zend_class_entry *ce = zend_ast_fetch_class(ast->child[0], scope);
if (!ce) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Would UNEXPECTED make sense for the return FAILURE branches added in this PR? I see them in the above case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I think we have too much UNEXPECTED in places where it's unlikely to actually matter...

@nikic nikic force-pushed the objects-in-constexpr-3 branch from e11e76b to 9d3ff89 Compare July 13, 2021 10:26
@nikic nikic closed this in 52d3d0d Jul 13, 2021
fabpot added a commit to symfony/symfony that referenced this pull request Aug 18, 2021
…e-daubois)

This PR was merged into the 5.4 branch.

Discussion
----------

[Validator] Add support of nested attributes

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #38503
| License       | MIT
| Doc PR        | symfony/symfony-docs#15541

Although the RFC (https://wiki.php.net/rfc/new_in_initializers) is in the voting phase (until 14 July), it is already well on its way to passing.

Based on `@nikic`'s development (php/php-src#7153), this makes the development of support possible. It will obviously take a little while before this pull request is merged.

If this pull request is OK for you, I'll get to work on writing the existing documentation for the attribute validation constraints.

![Capture d’écran du 2021-07-05 17-11-23](https://user-images.githubusercontent.com/2144837/124491886-0d2f7d80-ddb4-11eb-8147-493bdc6c48ac.png)

Not sure about the Symfony version to target, as `AtLeastOneOf` has been introduced in 5.1. Although, I couldn't find attributes validation documentation for 4.4.

Commits
-------

1449450 [Validator] Add support of nested attributes for composite constraints
symfony-splitter pushed a commit to symfony/validator that referenced this pull request Aug 18, 2021
…e-daubois)

This PR was merged into the 5.4 branch.

Discussion
----------

[Validator] Add support of nested attributes

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #38503
| License       | MIT
| Doc PR        | symfony/symfony-docs#15541

Although the RFC (https://wiki.php.net/rfc/new_in_initializers) is in the voting phase (until 14 July), it is already well on its way to passing.

Based on `@nikic`'s development (php/php-src#7153), this makes the development of support possible. It will obviously take a little while before this pull request is merged.

If this pull request is OK for you, I'll get to work on writing the existing documentation for the attribute validation constraints.

![Capture d’écran du 2021-07-05 17-11-23](https://user-images.githubusercontent.com/2144837/124491886-0d2f7d80-ddb4-11eb-8147-493bdc6c48ac.png)

Not sure about the Symfony version to target, as `AtLeastOneOf` has been introduced in 5.1. Although, I couldn't find attributes validation documentation for 4.4.

Commits
-------

1449450e2f [Validator] Add support of nested attributes for composite constraints
jrfnl added a commit to PHPCompatibility/PHPCompatibility that referenced this pull request Jan 3, 2023
…niff

> `new` in Initializers
>
> It is now possible to use `new ClassName()` expressions as the default value of a parameter, static variable, global constant initializers, and as attribute arguments.

Refs:
* https://wiki.php.net/rfc/new_in_initializers
* https://www.php.net/manual/en/migration81.new-features.php#migration81.new-features.core.new-in-initializer
* php/php-src#7153
* php/php-src@52d3d0d

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

Successfully merging this pull request may close these issues.

3 participants
0