diff options
| author | Nikita Popov <nikita.ppv@gmail.com> | 2020-11-30 16:45:48 +0100 |
|---|---|---|
| committer | Nikita Popov <nikita.ppv@gmail.com> | 2021-02-11 21:46:13 +0100 |
| commit | b10416a652d26577a22fe0b183b2258b20c8bb86 (patch) | |
| tree | 3b79102286b2307575f487bf97d572ffc292631d /ext/date | |
| parent | f06895488a5fabd27ac4c2e66a9d311f14d8594e (diff) | |
| download | php-git-b10416a652d26577a22fe0b183b2258b20c8bb86.tar.gz | |
Deprecate passing null to non-nullable arg of internal function
This deprecates passing null to non-nullable scale arguments of
internal functions, with the eventual goal of making the behavior
consistent with userland functions, where null is never accepted
for non-nullable arguments.
This change is expected to cause quite a lot of fallout. In most
cases, calling code should be adjusted to avoid passing null. In
some cases, PHP should be adjusted to make some function arguments
nullable. I have already fixed a number of functions before landing
this, but feel free to file a bug if you encounter a function that
doesn't accept null, but probably should. (The rule of thumb for
this to be applicable is that the function must have special behavior
for 0 or "", which is distinct from the natural behavior of the
parameter.)
RFC: https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg
Closes GH-6475.
Diffstat (limited to 'ext/date')
| -rw-r--r-- | ext/date/tests/bug54283.phpt | 3 | ||||
| -rw-r--r-- | ext/date/tests/bug73858.phpt | 10 | ||||
| -rw-r--r-- | ext/date/tests/date_interval_create_from_date_string_nullparam.phpt | 2 | ||||
| -rw-r--r-- | ext/date/tests/date_timestamp_set_nullparam2.phpt | 3 | ||||
| -rw-r--r-- | ext/date/tests/microtime_error.phpt | 56 |
5 files changed, 11 insertions, 63 deletions
diff --git a/ext/date/tests/bug54283.phpt b/ext/date/tests/bug54283.phpt index 65669b6b39..cadedd8691 100644 --- a/ext/date/tests/bug54283.phpt +++ b/ext/date/tests/bug54283.phpt @@ -10,5 +10,6 @@ try { } ?> ---EXPECT-- +--EXPECTF-- +Deprecated: DatePeriod::__construct(): Passing null to parameter #1 ($start) of type string is deprecated in %s on line %d string(51) "DatePeriod::__construct(): Unknown or bad format ()" diff --git a/ext/date/tests/bug73858.phpt b/ext/date/tests/bug73858.phpt index fb41390b0f..b6074ff01a 100644 --- a/ext/date/tests/bug73858.phpt +++ b/ext/date/tests/bug73858.phpt @@ -15,8 +15,8 @@ $e = new DateTime($es); $d= $e->diff($s); var_dump($d->days); // 0 ... but should be 30 -$s = (new DateTime(null))->setTimestamp(strtotime($ss)); // verbose setup method -$e = (new DateTime(null))->setTimestamp(strtotime($es)); // verbose setup method +$s = (new DateTime("now"))->setTimestamp(strtotime($ss)); // verbose setup method +$e = (new DateTime("now"))->setTimestamp(strtotime($es)); // verbose setup method $d = $e->diff($s); var_dump($d->days); // 30 ... and should be 30 @@ -24,13 +24,13 @@ var_dump($d->days); // 30 ... and should be 30 Next we will try mix/match the code to see what happens, surprisingly it seems that the end date ($e) is the important one, if it uses the verbose method it returns the correct values. */ -$s = (new DateTime(null))->setTimestamp(strtotime($ss)); // verbose setup method +$s = (new DateTime("now"))->setTimestamp(strtotime($ss)); // verbose setup method $e = new DateTime($es); $d= $e->diff($s); var_dump($d->days); // 0 ... but should be 30 $s = new DateTime($ss); -$e = (new DateTime(null))->setTimestamp(strtotime($es)); // verbose setup method +$e = (new DateTime("now"))->setTimestamp(strtotime($es)); // verbose setup method $d= $e->diff($s); var_dump($d->days); // 30 ... and should be 30 @@ -39,7 +39,7 @@ This test just proves that the $e date is important BUT NOT because it's the one on, that's just coincidental that seems to imply that the "- 1 second" in the date string is the problem. */ $s = new DateTime($ss); -$e = (new DateTime(null))->setTimestamp(strtotime($es)); // verbose setup method +$e = (new DateTime("now"))->setTimestamp(strtotime($es)); // verbose setup method $d= $s->diff($e); var_dump($d->days); // 30 ... and should be 30 diff --git a/ext/date/tests/date_interval_create_from_date_string_nullparam.phpt b/ext/date/tests/date_interval_create_from_date_string_nullparam.phpt index e03386ad3c..afac12b7a3 100644 --- a/ext/date/tests/date_interval_create_from_date_string_nullparam.phpt +++ b/ext/date/tests/date_interval_create_from_date_string_nullparam.phpt @@ -8,5 +8,7 @@ $i = date_interval_create_from_date_string(null); var_dump($i); ?> --EXPECTF-- +Deprecated: date_interval_create_from_date_string(): Passing null to parameter #1 ($datetime) of type string is deprecated in %s on line %d + Warning: date_interval_create_from_date_string(): Unknown or bad format () at position 0 ( ): Empty string in %sdate_interval_create_from_date_string_nullparam.php on line 2 bool(false) diff --git a/ext/date/tests/date_timestamp_set_nullparam2.phpt b/ext/date/tests/date_timestamp_set_nullparam2.phpt index c22dc3011a..2e5894bc24 100644 --- a/ext/date/tests/date_timestamp_set_nullparam2.phpt +++ b/ext/date/tests/date_timestamp_set_nullparam2.phpt @@ -13,7 +13,8 @@ $dtms021 = date_create(); var_dump(date_timestamp_set($dtms021, null)); ?> ---EXPECT-- +--EXPECTF-- +Deprecated: date_timestamp_set(): Passing null to parameter #2 ($timestamp) of type int is deprecated in %s on line %d object(DateTime)#1 (3) { ["date"]=> string(26) "1970-01-01 00:00:00.000000" diff --git a/ext/date/tests/microtime_error.phpt b/ext/date/tests/microtime_error.phpt deleted file mode 100644 index ce13875e67..0000000000 --- a/ext/date/tests/microtime_error.phpt +++ /dev/null @@ -1,56 +0,0 @@ ---TEST-- -Test wrong number of arguments for microtime() ---FILE-- -<?php -/* - * Function is implemented in ext/standard/microtime.c -*/ - -echo "\n-- Bad Arg types --\n"; - -$bad_args = array(null, - 1.5, - "hello", - array('k'=>'v', array(0)), - new stdClass, - 1); -foreach ($bad_args as $bad_arg) { - echo "\n--> bad arg: "; - var_dump($bad_arg); - try { - var_dump(microtime($bad_arg)); - } catch (TypeError $e) { - echo $e->getMessage(), "\n"; - } -} - -?> ---EXPECTF-- --- Bad Arg types -- - ---> bad arg: NULL -string(%d) "%s %s" - ---> bad arg: float(1.5) -float(%s) - ---> bad arg: string(5) "hello" -float(%s) - ---> bad arg: array(2) { - ["k"]=> - string(1) "v" - [0]=> - array(1) { - [0]=> - int(0) - } -} -microtime(): Argument #1 ($as_float) must be of type bool, array given - ---> bad arg: object(stdClass)#%d (0) { -} -microtime(): Argument #1 ($as_float) must be of type bool, stdClass given - ---> bad arg: int(1) -float(%s) |
