Skip to content

Support new in initializers#6746

Closed
nikic wants to merge 6 commits into
php:masterfrom
nikic:objects-in-constexpr
Closed

Support new in initializers#6746
nikic wants to merge 6 commits into
php:masterfrom
nikic:objects-in-constexpr

Conversation

@nikic

@nikic nikic commented Mar 2, 2021

Copy link
Copy Markdown
Member

This allows writing code like public Vec $prop = new Vec();.

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

@Illuminat

Illuminat commented Mar 4, 2021

Copy link
Copy Markdown

Hello @nikic. Good RFC. What about using closure inside and default variables?
Something like this
class Test {
private $url = 'https://some.com';
private $key = 'some-api-key';
private $client = new Client($this->url, $this->key);
private $lazyClient = static function () { return new Client()}; }

//or we can use anonymous class for this
public $lazyClient = new class { function __invoke() { return new Client()}; }

}

@nikic nikic force-pushed the objects-in-constexpr branch 2 times, most recently from f2708dd to 5698766 Compare March 4, 2021 15:52
thekid added a commit to xp-framework/compiler that referenced this pull request Mar 6, 2021
@nikic nikic force-pushed the objects-in-constexpr branch from 5698766 to 84a91ea Compare March 18, 2021 09:58
@nikic nikic force-pushed the objects-in-constexpr branch from 84a91ea to de8362a Compare March 19, 2021 10:53
@zlianon

zlianon commented Apr 14, 2021

Copy link
Copy Markdown

@nikic any chance of getting this in PHP 8.1? when does feature freeze start?

@nikic

nikic commented Apr 14, 2021

Copy link
Copy Markdown
Member Author

@zlianon Feature freeze is currently planned for Jul 20, see https://wiki.php.net/todo/php81.

@nikic

nikic commented Jul 13, 2021

Copy link
Copy Markdown
Member Author

Closing in favor of #7153.

@nikic nikic closed this Jul 13, 2021
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