# [RFC][VOTE] Default parent constructors RFC

- Thread: https://externals.io/message/80340
- Original archive: https://news-web.php.net/php.internals/80340
- Started by Stanislav Malyshev on 2015-01-11T00:34:23+00:00
- Messages: 5
- RFC: Default parent constructors (Declined) — https://externals.io/rfc/default_ctor.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #80340 — Stanislav Malyshev — 2015-01-11T00:34:23+00:00

URL: https://externals.io/message/80340#80340

Hi!

I'd like to initiate a vote on this RFC:
https://wiki.php.net/rfc/default_ctor

TLDR: this RFC would make a call to parent::__construct() succeed (as in
"not produce a fatal error") even if the parent class does not define a
ctor. Same for __destruct and __clone. The motivation for it is in the
RFC and here: https://php100.wordpress.com/2014/11/04/default-constructors/

I've chosen the simplest way of implementing it, as suggested by Dmitry,
in https://github.com/php/php-src/pull/990. There are other
alternatives, but I think the simpler the better.

Previous discussion is at: http://marc.info/?t=141630266000001&r=2&w=2
-- 
Stas Malyshev
smalyshev@gmail.com

---

## #80342 — Yasuo Ohgaki — 2015-01-11T02:08:35+00:00

URL: https://externals.io/message/80340#80342 · In reply to: #80340

Hi Stas,

On Sun, Jan 11, 2015 at 9:34 AM, Stanislav Malyshev <smalyshev@gmail.com>
wrote:

> I'd like to initiate a vote on this RFC:
> https://wiki.php.net/rfc/default_ctor
>
> TLDR: this RFC would make a call to parent::__construct() succeed (as in
> "not produce a fatal error") even if the parent class does not define a
> ctor. Same for __destruct and __clone. The motivation for it is in the
> RFC and here:
> https://php100.wordpress.com/2014/11/04/default-constructors/
>
> I've chosen the simplest way of implementing it, as suggested by Dmitry,
> in https://github.com/php/php-src/pull/990. There are other
> alternatives, but I think the simpler the better.
>
> Previous discussion is at: http://marc.info/?t=141630266000001&r=2&w=2
>

Nice RFC. It covers __clone(), __destruct() also.
This would be great for rapid prototyping.

Small comment to the patch.

+ (strcasecmp(Z_STRVAL_P(function_name), ZEND_DESTRUCTOR_FUNC_NAME) == 0 ||
+ strcasecmp(Z_STRVAL_P(function_name), ZEND_CONSTRUCTOR_FUNC_NAME) == 0 ||
+ strcasecmp(Z_STRVAL_P(function_name), ZEND_CLONE_FUNC_NAME) == 0)) {

The comparison order would be better

+ (strcasecmp(Z_STRVAL_P(function_name), ZEND_CONSTRUCTOR_FUNC_NAME) == 0 ||
+ strcasecmp(Z_STRVAL_P(function_name), ZEND_CLONE_FUNC_NAME) == 0 ||
+ strcasecmp(Z_STRVAL_P(function_name), ZEND_DESTRUCTOR_FUNC_NAME) == 0)) {

I suppose default constructor is used most, then clone, destructor. It
depends on a script, though.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #80352 — francois@tekwire.net — 2015-01-11T04:50:15+00:00

URL: https://externals.io/message/80340#80352 · In reply to: #80340

> De : Stanislav Malyshev [mailto:smalyshev@gmail.com]
>
> TLDR: this RFC would make a call to parent::__construct() succeed (as in
> "not produce a fatal error") even if the parent class does not define a
> ctor. Same for __destruct and __clone. The motivation for it is in the
> RFC and here: https://php100.wordpress.com/2014/11/04/default-
> constructors/

+1.

Considering implicit empty constructors and destructors is totally intuitive and should have been done a long time ago.

For __clone, no opinion as I never used it.

François

---

## #81076 — Pascal Martin — 2015-01-24T15:13:26+00:00

URL: https://externals.io/message/80340#81076 · In reply to: #80340

Le 11/01/2015 01:34, Stanislav Malyshev a écrit :
> I'd like to initiate a vote on this RFC:
> https://wiki.php.net/rfc/default_ctor
>
Hi,

After discussing this RFC with other people of AFUP, we would be +1 on 
this, by a small margin.

On one side, being able to always call a parent constructor without 
having to check if it exists could be useful, especially when the parent 
class is in a library.
On the other hand, it feels like the current situation doesn't cause 
problems that often; and if a constructor is added to a parent class, it 
will likely expect specific parameters, which means child classes will 
need to be updated anyway.

-- 
Pascal MARTIN, AFUP - French UG
http://php-internals.afup.org/

---

## #81081 — Yasuo Ohgaki — 2015-01-24T16:50:43+00:00

URL: https://externals.io/message/80340#81081 · In reply to: #80340

Hi all,

On Sun, Jan 11, 2015 at 9:34 AM, Stanislav Malyshev <smalyshev@gmail.com>
wrote:

> I'd like to initiate a vote on this RFC:
> https://wiki.php.net/rfc/default_ctor
>
> TLDR: this RFC would make a call to parent::__construct() succeed (as in
> "not produce a fatal error") even if the parent class does not define a
> ctor. Same for __destruct and __clone. The motivation for it is in the
> RFC and here:
> https://php100.wordpress.com/2014/11/04/default-constructors/
>
> I've chosen the simplest way of implementing it, as suggested by Dmitry,
> in https://github.com/php/php-src/pull/990. There are other
> alternatives, but I think the simpler the better.
>
> Previous discussion is at: http://marc.info/?t=141630266000001&r=2&w=2
>

It seems -1 vote are increasing. Therefore, I would like to mention
benefits of this RFC again.

This RFC is great for rapid app development/prototyping. There are many
cases that base
class constructors calls are needed or not. This RFC allow us to just call
parent constructor,
then add implementation later if it is needed.

It makes code maintenance easier for production code also.

I can understand the reason why people vote -1 (non existent
method/function calls should
not be able to be called and raise), but benefits override. IMHO.

PHP is for easier/faster development, isn't it?

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net
