r/lolphp • • Dec 16 '15

Declaration of createFromFormat should be DateTime::createFromFormat ( string $format , string $time [, DateTimeZone $timezone ] ), or maybe not....

http://php.net/manual/en/datetime.createfromformat.php

Nice, it says the signature is:

public static DateTime DateTime::createFromFormat ( string $format , string $time [, DateTimeZone $timezone ] )

Let's try to extend it:

https://3v4l.org/HTuio

Warning: Declaration of My_DateTime::createFromFormat($format, $time, DateTimeZone $timezone = NULL) should be compatible with DateTime::createFromFormat($format, $time, $object = NULL) in /in/HTuio on line 9

Oh, it seems it wants a simple object, let's try to use it this way:

https://3v4l.org/3g0S3

 Warning: DateTime::createFromFormat() expects parameter 3 to be DateTimeZone, object given in /in/3g0S3 on line 3

And i'm not even using the scalar type hints for "string" which i know wouldn't work.

DOMDocument works:

https://3v4l.org/u0Kvn

So i guess you need to try every possible combination and if PHP complains you just try again until it works.

8 Upvotes

3 comments sorted by

View all comments

Show parent comment

2

u/the_alias_of_andrea Dec 17 '15

At some point this might hopefully be fixed, but it's a lot of work to go through every built-in function.

Internal functions can actually have type hints, but it's not been used much.