Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[draft] short constructor#19133

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
xepozz wants to merge5 commits intophp:master
base:master
Choose a base branch
Loading
fromxepozz:short-constructor
Draft

Conversation

xepozz
Copy link
Contributor

@xepozzxepozz commentedJul 15, 2025
edited
Loading

There is PoC of short constructor syntax (inspired by Kotlin).
I'd like to discuss the possibilities to move it further and the implementation.

key points:

regular

class A;
becomes
class A {}

how to express constructor with params?

class A(private$a,public$b,$local);
becomes
class A {publicfunction__construct(private$a,public$b,$local) { }}

ok, what about inheritance?

class A(private$a,public$b,$local)extends B;
becomes
class Aextends B{publicfunction__construct(private$a,public$b,$local) { }}

how to call parent constructor?

class A(private$a,public$b,$local)extends B($local,"string",24*60*60,$this->a);
becomes
class A {publicfunction__construct(private$a,public$b,$local) {parent::__construct($local,"string",24*60*60,$this->a);    }}

brzuchal reacted with thumbs up emoji
@iluuu1994
Copy link
Member

Variations of this have discussed during the constructor property promotion RFC, and more recently in the records RFC.1 As with previous changes, this needs a discussion on the internals mailing list. My expectation is that you'll likely face significant resistance to this change.

Footnotes

  1. https://wiki.php.net/rfc/records

@xepozz
Copy link
ContributorAuthor

@iluuu1994 thanks for the answer. Records RFC pushed me to implement such feature for classes as well, making "records" look similar to classes to prove that it could be done "with classes"
Btw, it's just a part of process of simplification creating classes

classUUID(privatereadonly string$value);

This is what you need to create a data transfer object

Btw, I'd like to discuss implementation. Theoretically, will it be enough to push the RFC further?
Now the "short constructor" is just a sugarred version of long constructor. Tests with AST printer prove it.

@iluuu1994
Copy link
Member

Btw, I'd like to discuss implementation.

Generally, I don't spend too much time on implementation before knowing that the RFC actually progresses. Most RFCs die before they make it to the vote.

Theoretically, will it be enough to push the RFC further?

Yes, RFCs are the only way to land language changes.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@dstogovdstogovAwaiting requested review from dstogovdstogov will be requested when the pull request is marked ready for reviewdstogov is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@xepozz@iluuu1994

[8]ページ先頭

©2009-2025 Movatter.jp