# date extension / Type Hinting

- Thread: https://externals.io/message/86997
- Original archive: https://news-web.php.net/php.internals/86997
- Started by Philip Hofstetter on 2015-07-02T13:34:33+00:00
- Messages: 6
- 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

---

## #86997 — Philip Hofstetter — 2015-07-02T13:34:33+00:00

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

Hi,

as this probably requires some discussion, I'm coming here to ask.

I'm talking about bug 69977 and 61483: Both are about the fact that it's
currently not possible to properly type-hint descendant classes of DateTime
and friends.

The reason is the missing use ZEND_ARG_OBJ_INFO, so right now, users can
only create descendant classes without any type hinting on their methods.

Adding the ZEND_ARG_OBJ_INFO is quite trivial and in-fact, I have a branch
here that does it:

https://github.com/pilif/php-src/tree/bug-69977

Of course this is going to break a whole lot of tests because what was once
warnings is now a TypeError.

I'd be willing to update all the tests as needed, but of course changing
the behaviour like this is a BC issue in itself, hence I'm coming here.

The reason why I think this matters much more now than back when 61483 was
submitted is two-fold:

1) back in 61483, adding the (correct!) type-hints was "just" causing an
 `E_STRICT` message. But now with PHP7 it's actually an E_WARNING. So people
running without `E_STRICT` enjoyed correct type hints until now which they
now can't any more (so, there's another BC break right there :p)
2) With PHP7 type hinting becomes much more viable, so forcing users to not
type-hint something that really should be feels kind of ugly.
3) Having a new major release is as good a time as any for chaning the
behaviour, especially when the change is related to a major new feature
(the addition of much stricter typing).

So I'm asking for opinions on what should be done here.

Again: If you lean /at all/ in the direction of changing this, I volunteer
to update all the tests as required.

Philip


-- 
Sensational AG
Giesshübelstrasse 62c, Postfach 1966, 8021 Zürich
Tel. +41 43 544 09 60, Mobile  +41 79 341 01 99
info@sensational.ch, http://www.sensational.ch

---

## #87002 — Nikita Popov — 2015-07-02T14:39:43+00:00

URL: https://externals.io/message/86997#87002 · In reply to: #86997

On Thu, Jul 2, 2015 at 3:34 PM, Philip Hofstetter <
phofstetter@sensational.ch> wrote:

> Hi,
>
> as this probably requires some discussion, I'm coming here to ask.
>
> I'm talking about bug 69977 and 61483: Both are about the fact that it's
> currently not possible to properly type-hint descendant classes of DateTime
> and friends.
>
> The reason is the missing use ZEND_ARG_OBJ_INFO, so right now, users can
> only create descendant classes without any type hinting on their methods.
>
> Adding the ZEND_ARG_OBJ_INFO is quite trivial and in-fact, I have a branch
> here that does it:
>
> https://github.com/pilif/php-src/tree/bug-69977
>
> Of course this is going to break a whole lot of tests because what was once
> warnings is now a TypeError.
>
> I'd be willing to update all the tests as needed, but of course changing
> the behaviour like this is a BC issue in itself, hence I'm coming here.
>
> The reason why I think this matters much more now than back when 61483 was
> submitted is two-fold:
>
> 1) back in 61483, adding the (correct!) type-hints was "just" causing an
> `E_STRICT` message. But now with PHP7 it's actually an E_WARNING. So people
> running without `E_STRICT` enjoyed correct type hints until now which they
> now can't any more (so, there's another BC break right there :p)
> 2) With PHP7 type hinting becomes much more viable, so forcing users to not
> type-hint something that really should be feels kind of ugly.
> 3) Having a new major release is as good a time as any for chaning the
> behaviour, especially when the change is related to a major new feature
> (the addition of much stricter typing).
>
> So I'm asking for opinions on what should be done here.
>
> Again: If you lean /at all/ in the direction of changing this, I volunteer
> to update all the tests as required.
>
> Philip
>

This change is currently not possible, because it will cause a significant
BC break for everyone extending DateTime: They would now be required to
specify these typehints as well. However some libraries (including Carbon,
which is used a lot) depend on these typehint not being there, because they
overload them to e.g. allow passing a string which will then be converted
to the correct instance before passing off to DateTime.

A similar change to what you propose was reverted from PHP 7 for this
reason.

However, what we can do in PHP 7.1 (and I plan to write an RFC for this) is
allow extending classes to remove a parameter type hint, which is in
accordance with contravariance of parameter types. This is analogous to our
already existing partial covariance support for return types (which works
the other way around, by allowing to add return typehints in extending
classes).

Nikita

---

## #87003 — Anatol Belski — 2015-07-02T14:51:17+00:00

URL: https://externals.io/message/86997#87003 · In reply to: #86997

Hi Philip,

> -----Original Message-----
> From: Philip Hofstetter [mailto:phofstetter@sensational.ch]
> Sent: Thursday, July 2, 2015 3:35 PM
> To: PHP internals
> Subject: [PHP-DEV] date extension / Type Hinting
> 
> Hi,
> 
> as this probably requires some discussion, I'm coming here to ask.
> 
> I'm talking about bug 69977 and 61483: Both are about the fact that it's
> currently not possible to properly type-hint descendant classes of DateTime and
> friends.
> 
> The reason is the missing use ZEND_ARG_OBJ_INFO, so right now, users can
> only create descendant classes without any type hinting on their methods.
> 
> Adding the ZEND_ARG_OBJ_INFO is quite trivial and in-fact, I have a branch here
> that does it:
> 
> https://github.com/pilif/php-src/tree/bug-69977
> 
> Of course this is going to break a whole lot of tests because what was once
> warnings is now a TypeError.
> 
> I'd be willing to update all the tests as needed, but of course changing the
> behaviour like this is a BC issue in itself, hence I'm coming here.
> 
> The reason why I think this matters much more now than back when 61483 was
> submitted is two-fold:
> 
> 1) back in 61483, adding the (correct!) type-hints was "just" causing an `E_STRICT` 
> message. But now with PHP7 it's actually an E_WARNING. So people running
> without `E_STRICT` enjoyed correct type hints until now which they now can't any
> more (so, there's another BC break right there :p)
> 2) With PHP7 type hinting becomes much more viable, so forcing users to not
> type-hint something that really should be feels kind of ugly.
> 3) Having a new major release is as good a time as any for chaning the
> behaviour, especially when the change is related to a major new feature (the
> addition of much stricter typing).
> 
> So I'm asking for opinions on what should be done here.
> 
> Again: If you lean /at all/ in the direction of changing this, I volunteer to update
> all the tests as required.
please read this thread for more info https://github.com/php/php-src/commit/8e19705a93d785cd1ff8ba3a69699b00169fea47 . 

Regards

Anatol

---

## #87004 — Philip Hofstetter — 2015-07-02T16:00:17+00:00

URL: https://externals.io/message/86997#87004 · In reply to: #87003

Hi,





> please read this thread for more info
> https://github.com/php/php-src/commit/8e19705a93d785cd1ff8ba3a69699b00169fea47
> .
>

yeah. I also understood Nikita's response. I guess you can close the two
bugs for now as this really isn't fixable in any practical way.

Such a shame :(

Philip
-- 
Sensational AG
Giesshübelstrasse 62c, Postfach 1966, 8021 Zürich
Tel. +41 43 544 09 60, Mobile  +41 79 341 01 99
info@sensational.ch, http://www.sensational.ch

---

## #87005 — Anatol Belski — 2015-07-02T17:29:49+00:00

URL: https://externals.io/message/86997#87005 · In reply to: #87004

Hi Philip,

> -----Original Message-----
> From: Philip Hofstetter [mailto:phofstetter@sensational.ch]
> Sent: Thursday, July 2, 2015 6:00 PM
> To: Anatol Belski; PHP internals
> Subject: Re: [PHP-DEV] date extension / Type Hinting
> 
> Hi,
> 
> 
> 
> 
> 
> > […]
> src/commit/8e19705a93d785cd1ff8ba3a69699b00
> > […]
> 
> yeah. I also understood Nikita's response. I guess you can close the two bugs for
> now as this really isn't fixable in any practical way.
> 
Nope, they should be closed when it's implemented.

Regards

Anatol

---

## #87007 — Christoph Becker — 2015-07-02T18:09:50+00:00

URL: https://externals.io/message/86997#87007 · In reply to: #87005

Anatol Belski wrote:

> > […]
> Nope, they should be closed when it's implemented.

I've switched both reports to "suspended" (including a link to this
discussion).  It seems that makes the most sense for now.

-- 
Christoph M. Becker
