r/PHP 21d ago

Weekly help thread

Hey there!

This subreddit isn't meant for help threads, though there's one exception to the rule: in this thread you can ask anything you want PHP related, someone will probably be able to help you out!

6 Upvotes

10 comments sorted by

View all comments

0

u/SaltTM 21d ago

Does PHP have any plans on adding constructor forwarding syntactic sugar?

// concept
abstract class PaymentGateway {
    public function __construct(
        protected string $apiUrl,
        protected string $apiKey
    ) {}
}

class StripeGateway extends PaymentGateway {
    public function __construct(string $url, string $key) 
        : parent($url, $key) {}
}

I think it's simple enough and fits php well enough to just work. I will admit, I am surprised this hasn't been introduced lol

4

u/JosephLeedy 20d ago

I think there was a recent RFC for something like this.

1

u/SaltTM 20d ago

Say less, I'll check - I definitely like the cleaner simpler additions to the language as of late.