# Ensure correct signatures for PHP magic methods

- Thread: https://externals.io/message/107990
- Original archive: https://news-web.php.net/php.internals/107990
- Started by Gabriel Caruso on 2020-01-05T17:43:42+00:00
- Messages: 6
- 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

---

## #107990 — Gabriel Caruso — 2020-01-05T17:43:42+00:00

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

Hello Internals,

I have a PR proposing to start checking the signatures for PHP magic
methods in the next major version of PHP:
https://github.com/php/php-src/pull/4177. The idea for this PR came from
https://bugs.php.net/bug.php?id=69718.

I'd like to hear your opinion before putting more effort into this :)

Best regards.

---

## #108000 — G. P. B. — 2020-01-06T00:28:02+00:00

URL: https://externals.io/message/107990#108000 · In reply to: #107990

On Sun, 5 Jan 2020 at 18:44, Gabriel Caruso <carusogabriel34@gmail.com>
wrote:

> Hello Internals,
>
> I have a PR proposing to start checking the signatures for PHP magic
> methods in the next major version of PHP:
> https://github.com/php/php-src/pull/4177. The idea for this PR came from
> https://bugs.php.net/bug.php?id=69718.
>
> I'd like to hear your opinion before putting more effort into this :)
>
> Best regards.
>

Hello Gabriel,

I do like the idea, but I would agree that I'd want void as the return type
instead of a no return compile error.
Other than that +1 from my side.

Best regards

George P. Banyard

---

## #108001 — Nikita Popov — 2020-01-06T09:04:48+00:00

URL: https://externals.io/message/107990#108001 · In reply to: #107990

On Sun, Jan 5, 2020 at 6:44 PM Gabriel Caruso <carusogabriel34@gmail.com>
wrote:

> Hello Internals,
>
> I have a PR proposing to start checking the signatures for PHP magic
> methods in the next major version of PHP:
> https://github.com/php/php-src/pull/4177. The idea for this PR came from
> https://bugs.php.net/bug.php?id=69718.
>
> I'd like to hear your opinion before putting more effort into this :)
>
> Best regards.
>

To be clear, the suggestion here is to verify that no *wrong* types are
specified -- but not specifying a type at all remains legal, right? If so,
sounds reasonable to me.

Nikita

---

## #108003 — Gabriel Caruso — 2020-01-06T09:23:35+00:00

URL: https://externals.io/message/107990#108003 · In reply to: #108001

> On Sun, Jan 5, 2020 at 6:44 PM Gabriel Caruso <carusogabriel34@gmail.com>
> wrote:
>
> > […]
>
> To be clear, the suggestion here is to verify that no *wrong* types are
> specified -- but not specifying a type at all remains legal, right? If so,
> sounds reasonable to me.
>

Right! If no type is provided no problem but, if provided, then we're going
to check.

Important: *this has nothing to do* with `strict_types` flag enabled or not.


>
> Nikita
>


Best regards,

---

## #108004 — Gabriel Caruso — 2020-01-06T09:29:17+00:00

URL: https://externals.io/message/107990#108004 · In reply to: #108000

Hello George



> On Sun, 5 Jan 2020 at 18:44, Gabriel Caruso <carusogabriel34@gmail.com>
> wrote:
>
> > […]
>
> Hello Gabriel,
>
> I do like the idea, but I would agree that I'd want void as the return
> type instead of a no return compile error.
> Other than that +1 from my side.
>


The reason why I didn't want to go with `__construct(): void`, for example,
is because some articles that I've read say that Constructors and
Destructors do not return anything:

- https://www.geeksforgeeks.org/php-constructors-and-destructors/
- https://docs.phpdoc.org/references/phpdoc/tags/return.html
- https://stackoverflow.com/questions/11904255/constructor-returning-value

Also, the community has pushing this standard, as it can be seen in
https://github.com/slevomat/coding-standard#slevomatcodingstandardtypehintsreturntypehint-
.

Best regards,


>
> Best regards
>
> George P. Banyard

---

## #108007 — G. P. B. — 2020-01-06T15:10:53+00:00

URL: https://externals.io/message/107990#108007 · In reply to: #108004

On Mon, 6 Jan 2020 at 10:29, Gabriel Caruso <carusogabriel34@gmail.com>
wrote:

> Hello George
>
> 
>
> > […]
>
>
> The reason why I didn't want to go with `__construct(): void`, for
> example, is because some articles that I've read say that Constructors and
> Destructors do not return anything:
>
> - https://www.geeksforgeeks.org/php-constructors-and-destructors/
> - https://docs.phpdoc.org/references/phpdoc/tags/return.html
> - https://stackoverflow.com/questions/11904255/constructor-returning-value
>
> Also, the community has pushing this standard, as it can be seen in
> https://github.com/slevomat/coding-standard#slevomatcodingstandardtypehintsreturntypehint-
> .
>
> Best regards,
>

Well the void return type means no return or an early return, so I would
say that "no return" is a stronger requirement then void, but I think
adding the void return type is a massive BC break as all code which doesn't
define the magic methods as void break ... I didn't think that through as
it seems the no return thing doesn't have that problem, so seems fine by me
however this is done.

Best regards

George P. Banyard
