# return/parameter types for magic functions

- Thread: https://externals.io/message/86419
- Original archive: https://news-web.php.net/php.internals/86419
- Started by Stanislav Malyshev on 2015-05-28T07:06:32+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #86419 — Stanislav Malyshev — 2015-05-28T07:06:32+00:00

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

Hi!

Since we now allow defining return value types for functions, one can
also create definition for magic functions that make no sense, such as
__toString() : float or __isset() : Closure. I think we should restrict
such definitions - either to types that makes sense or in case of
methods that aren't supposed to return anything useful, completely. We
already do this for ctors, dtors and __clone but not consistently for
other magics. Also some values for parameter types make no sense.

I've created a bug https://bugs.php.net/bug.php?id=69718 to track this.
Not sure if this really needs an RFC.
-- 
Stas Malyshev
smalyshev@gmail.com

---

## #86420 — Kalle Sommer Nielsen — 2015-05-28T07:24:08+00:00

URL: https://externals.io/message/86419#86420

2015-05-28 9:23 GMT+02:00 Kalle Sommer Nielsen <kalle@php.net>:
> Hi
[snip]
>
> I only think this sounds reasonable, we already do this for
> __toString(), meaning we can convert a few more errors into
> exceptions. So I can only say +1
> --
> regards,
>
> Kalle Sommer Nielsen
> kalle@php.net

/Mornings, forgot to CC the list


-- 
regards,

Kalle Sommer Nielsen
kalle@php.net

---

## #86425 — Levi Morrison — 2015-05-28T17:38:52+00:00

URL: https://externals.io/message/86419#86425 · In reply to: #86419

> Hi!
>
> Since we now allow defining return value types for functions, one can
> also create definition for magic functions that make no sense, such as
> __toString() : float or __isset() : Closure. I think we should restrict
> such definitions - either to types that makes sense or in case of
> methods that aren't supposed to return anything useful, completely. We
> already do this for ctors, dtors and __clone but not consistently for
> other magics. Also some values for parameter types make no sense.

My original patch for return types did not allow return types for
ctors, dtors, and __clone. It seems you did not preserve this? In any
case no RFC is needed because this was outlined in the RFC:
https://wiki.php.net/rfc/return_types#methods_which_cannot_declare_return_types

The only one that should allow anything for now is __toString which
would be permitted to declare a return type of string.

---

## #86426 — Levi Morrison — 2015-05-28T17:39:41+00:00

URL: https://externals.io/message/86419#86426 · In reply to: #86425

> 
> > […]
>
> My original patch for return types did not allow return types for
> ctors, dtors, and __clone. It seems you did not preserve this? In any
> case no RFC is needed because this was outlined in the RFC:
> https://wiki.php.net/rfc/return_types#methods_which_cannot_declare_return_types
>
> The only one that should allow anything for now is __toString which
> would be permitted to declare a return type of string.

My apologies; I misread Dmitry's original statement. Disregard my message.

---

## #86436 — Levi Morrison — 2015-05-28T22:36:59+00:00

URL: https://externals.io/message/86419#86436 · In reply to: #86426

> 
> > […]
>
> My apologies; I misread Dmitry's original statement. Disregard my message.

s/Dmitry/Stas/; seems I shouldn't post anything today; sorry for all
the mistakes and noise.
