# Optional Type Hinting

- Thread: https://externals.io/message/76654
- Original archive: https://news-web.php.net/php.internals/76654
- Started by Dmitry Stogov on 2014-08-18T14:11:52+00:00
- Messages: 8
- RFC: Add scalar type hinting with casts (Withdrawn) — https://externals.io/rfc/scalar_type_hinting_with_cast.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

---

## #76654 — Dmitry Stogov — 2014-08-18T14:11:52+00:00

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

Hi,

What do you think about merging the following proposals into a single and
consistent one:

https://wiki.php.net/rfc/scalar_type_hinting_with_cast
https://wiki.php.net/rfc/returntypehinting
https://wiki.php.net/rfc/nullable_typehints

I think it makes sense to keep syntax consistent with subset of Facebook's
Hack to not make troubles to each other.

I mainly interested in this feature from JIT compiler point of view,
because once compiler knows primitive types of functions arguments and
return values, it may generate much better code. So the solution must
guarantee the types of arguments at function entry point, not the types of
actual parameters (they may be auto-converted if possible).

Thanks. Dmitry.

---

## #76655 — Andrea Faulds — 2014-08-18T14:14:24+00:00

URL: https://externals.io/message/76654#76655 · In reply to: #76654

> What do you think about merging the following proposals into a single and consistent one:
> 
> https://wiki.php.net/rfc/scalar_type_hinting_with_cast
> https://wiki.php.net/rfc/returntypehinting
> https://wiki.php.net/rfc/nullable_typehints

No, please let’s not merge them. First off, the scalar hints proposal is basically dead, I’ll have a replacement at some point, but I have actually abandoned it.

Secondly, merging these together might be the death of all the RFCs. While one might be uncontroversial on its own, bundling it together with other changes might make it unpassable.
--
Andrea Faulds
http://ajf.me/

---

## #76656 — Dmitry Stogov — 2014-08-18T14:21:52+00:00

URL: https://externals.io/message/76654#76656 · In reply to: #76655

I see your point. For me they just don't have a lot of sense without each
other.

Thanks. Dmitry.






>
> 
>
> > […]
> and consistent one:
> > […]
>
> No, please let’s not merge them. First off, the scalar hints proposal is
> basically dead, I’ll have a replacement at some point, but I have actually
> abandoned it.
>
> Secondly, merging these together might be the death of all the RFCs. While
> one might be uncontroversial on its own, bundling it together with other
> changes might make it unpassable.
> --
> Andrea Faulds
> http://ajf.me/

---

## #76662 — Sebastian Bergmann — 2014-08-18T16:16:15+00:00

URL: https://externals.io/message/76654#76662 · In reply to: #76656

Am 18.08.2014 um 16:21 schrieb Dmitry Stogov:
> For me they just don't have a lot of sense without each other.

 https://wiki.php.net/rfc/returntypehinting makes sense without
 https://wiki.php.net/rfc/scalar_type_hinting_with_cast and
 https://wiki.php.net/rfc/nullable_typehints IMHO.

---

## #76665 — Levi Morrison — 2014-08-18T17:57:36+00:00

URL: https://externals.io/message/76654#76665 · In reply to: #76656

> I see your point. For me they just don't have a lot of sense without each
> other.

I am the author of two of those RFCs. I've worked with several members
of the HHVM team so that any inconsistencies are planned and recorded
(or will be; I know of one inconsistency in return types that is not
currently recorded).

I also am definitely not in favor of merging them, for the reasons
Andrea outlined.

Also, Dmitry, if you have interest in working on the implementations
for these RFCs I'm sure Joe would appreciate the help (I know I
would).

---

## #76669 — Dmitry Stogov — 2014-08-18T19:43:00+00:00

URL: https://externals.io/message/76654#76669 · In reply to: #76665

Hi Levi,

The implementation is really not a problem. It must be quite simple and I
may take care about it.
The problem that we can't come to agreement on scalar type hinting for
years :(

Thanks. Dmitry.


On Mon, Aug 18, 2014 at 9:57 PM, Levi Morrison <morrison.levi@gmail.com>
wrote:

> 
> > […]
>
> I am the author of two of those RFCs. I've worked with several members
> of the HHVM team so that any inconsistencies are planned and recorded
> (or will be; I know of one inconsistency in return types that is not
> currently recorded).
>
> I also am definitely not in favor of merging them, for the reasons
> Andrea outlined.
>
> Also, Dmitry, if you have interest in working on the implementations
> for these RFCs I'm sure Joe would appreciate the help (I know I
> would).

---

## #76681 — Levi Morrison — 2014-08-19T04:23:10+00:00

URL: https://externals.io/message/76654#76681 · In reply to: #76669

> Hi Levi,
>
> The implementation is really not a problem. It must be quite simple and I
> may take care about it.
> The problem that we can't come to agreement on scalar type hinting for years
> :(
>
> Thanks. Dmitry.
>
>
> On Mon, Aug 18, 2014 at 9:57 PM, Levi Morrison <morrison.levi@gmail.com>
> wrote:
> > […]

Joe was able to get it mostly completed in a really short period of
time, but there is some issue going on with opcache. I have forgotten
the details now, but I think it had to deal with the fact that the
types need to have delayed binding. Joe or Anthony, can you maybe give
more information here?

Additionally, the implementation was built off of master because it
was created before PHPNG; I think I probably want to target PHP 7
instead of 5.7 (again, PHP 7 was only being dreamed of then) so it
would need rebased at least. Here's the work by Joe and Anthony:
https://github.com/krakjoe/php-src/compare/returntypehinting

---

## #76682 — Dmitry Stogov — 2014-08-19T05:50:17+00:00

URL: https://externals.io/message/76654#76682 · In reply to: #76681

The patch looks good and seems to contain the necessary opcache changes.

I'm not sure if you really need zend_return_hint.used and
zend_return_hint.class_name_type (may be I just didn't analyze the patch
deep enough).

You may support "self" by setting  zend_return_hint.class_name =
GC(actrive_class_entry)->name.
If return type hinting is unused then zend_function. return_hint should be
 `NULL` 

In PHP7 it may make sense to embed fields of zend_return_hint (zend_string
return_class_name and zend_uchar return_type) directly into zend_function.
It may keep the same memory usage for cases without return type hinting and
decrease it with return type hinting.

Thanks. Dmitry.


On Tue, Aug 19, 2014 at 8:23 AM, Levi Morrison <morrison.levi@gmail.com>
wrote:

> 
> > […]
> years
> > […]
>
> Joe was able to get it mostly completed in a really short period of
> time, but there is some issue going on with opcache. I have forgotten
> the details now, but I think it had to deal with the fact that the
> types need to have delayed binding. Joe or Anthony, can you maybe give
> more information here?
>
> Additionally, the implementation was built off of master because it
> was created before PHPNG; I think I probably want to target PHP 7
> instead of 5.7 (again, PHP 7 was only being dreamed of then) so it
> would need rebased at least. Here's the work by Joe and Anthony:
> https://github.com/krakjoe/php-src/compare/returntypehinting
