Skip to content

Feature request; Primary constructors #18287

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

Open
Tchilly opened this issue Apr 9, 2025 · 5 comments
Open

Feature request; Primary constructors #18287

Tchilly opened this issue Apr 9, 2025 · 5 comments

Comments

@Tchilly
Copy link

Tchilly commented Apr 9, 2025

Description

class User (Repo $repo, string $text) {
    public method() {
        // ...
    }
}

Love the syntax from C# over the __contruct we have today, It’s cleaner and more declarative. RFC time?

@iluuu1994
Copy link
Member

iluuu1994 commented Apr 9, 2025

PHP used to have C#-style constructors with public function ClassName. https://3v4l.org/mhdNu#veol

So, we're very very unlikely to go full-circle. PHP uses __ for many built-in functions (https://www.php.net/manual/en/language.oop5.magic.php).

Edit: Some additional context: https://wiki.php.net/rfc/remove_php4_constructors

@Tchilly
Copy link
Author

Tchilly commented Apr 9, 2025

PHP used to have C#-style constructors with public function ClassName. https://3v4l.org/38fRO

So, we're very very unlikely to go full-circle. PHP uses __ for many built-in functions (https://www.php.net/manual/en/language.oop5.magic.php).

I mean, if enough people want it... share the love <3

@iluuu1994
Copy link
Member

This would definitely require an RFC, which is described here: https://wiki.php.net/rfc/howto

Please send an initial e-mail to the mailing list to propose your idea so see how it is perceived. But to warn you, I highly doubt the feedback will be positive. 🙂

@Tchilly
Copy link
Author

Tchilly commented Apr 9, 2025

I'll try to write a compelling RFC, but I'll check in with the mailing list. Honestly, PHP has gotten so much better with time, and compared to many other communities, it's perfectly fine :D I've been using PHP sincle like '96, but never touched the engine parts :D

@iluuu1994
Copy link
Member

No worries, if people are interested in your idea I'm sure you'll find volunteers for the implementation. Usually it's the idea itself that fails, unless the implementation is very complicated.

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

2 participants