# Allowing static as a return type

- Thread: https://externals.io/message/91467
- Original archive: https://news-web.php.net/php.internals/91467
- Started by Lee Davis on 2016-03-01T11:46:01+00:00
- Messages: 2
- 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

---

## #91467 — Lee Davis — 2016-03-01T11:46:01+00:00

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

Hi Internals,

  whilst recently playing with return type hints on PHP 7 I noticed that
"static" cannot be used as a valid return type. I'm not entirely sure
whether this has been purposely prevented or not.

https://3v4l.org/LEXis

The behaviour works it's just a parse error that's stopping it. It's fairly
easy to get around this behaviour by using 'self' on the return hint
however I'm not too sure how correct this is considering you might want to
have that method be extendable.

https://3v4l.org/rk4W6

I always considered 'self' to represent the class where the definition
lies, and 'static' to mean the caller class (i.e. when using LSB) so it
might be something that you'd want to define on the type hint.

Do you think this is something we should allow into the type system?

Thoughts?

---

## #91469 — Niklas Keller — 2016-03-01T17:31:53+00:00

URL: https://externals.io/message/91467#91469 · In reply to: #91467

The reason is probably that return types are currently invariant, so a
inheriting class would have to declare the parent as return type anyway.

Lee Davis <leedavis81@gmail.com> schrieb am Di., 1. März 2016 12:46:

> Hi Internals,
>
>   whilst recently playing with return type hints on PHP 7 I noticed that
> "static" cannot be used as a valid return type. I'm not entirely sure
> whether this has been purposely prevented or not.
>
> https://3v4l.org/LEXis
>
> The behaviour works it's just a parse error that's stopping it. It's fairly
> easy to get around this behaviour by using 'self' on the return hint
> however I'm not too sure how correct this is considering you might want to
> have that method be extendable.
>
> https://3v4l.org/rk4W6
>
> I always considered 'self' to represent the class where the definition
> lies, and 'static' to mean the caller class (i.e. when using LSB) so it
> might be something that you'd want to define on the type hint.
>
> Do you think this is something we should allow into the type system?
>
> Thoughts?
