Skip to content

Commit

Permalink
More consistent parameter names for date/time functions
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Jul 24, 2020
1 parent 0ef8e0c commit e96e4ac
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ The default value is an integer in the parent class method's signature.
<?php
class MyDateTime extends DateTime
{
public function setTime(int $hour, int $minute, int $second = 0, bool $microseconds = false)
public function setTime(int $hour, int $minute, int $second = 0, bool $microsecond = false)
{
}
}
?>
--EXPECTF--
Fatal error: Declaration of MyDateTime::setTime(int $hour, int $minute, int $second = 0, bool $microseconds = false) must be compatible with DateTime::setTime(int $hour, int $minute, int $second = 0, int $microseconds = 0) in %s on line %d
Fatal error: Declaration of MyDateTime::setTime(int $hour, int $minute, int $second = 0, bool $microsecond = false) must be compatible with DateTime::setTime(int $hour, int $minute, int $second = 0, int $microsecond = 0) in %s on line %d
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ class MyDateTime extends DateTime
{
}
}
?>
--EXPECTF--
Fatal error: Declaration of MyDateTime::createFromFormat() must be compatible with DateTime::createFromFormat(string $format, string $time, ?DateTimeZone $timezone = null) in %s on line %d
Fatal error: Declaration of MyDateTime::createFromFormat() must be compatible with DateTime::createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null) in %s on line %d
4 changes: 2 additions & 2 deletions Zend/tests/type_declarations/variance/internal_parent.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Internal class as parent
<?php

class Test extends DateTime {
public static function createFromFormat($format, $time, Wrong $timezone = null) { }
public static function createFromFormat($format, $datetime, Wrong $timezone = null) { }
}

?>
--EXPECTF--
Fatal error: Could not check compatibility between Test::createFromFormat($format, $time, ?Wrong $timezone = null) and DateTime::createFromFormat(string $format, string $time, ?DateTimeZone $timezone = null), because class Wrong is not available in %s on line %d
Fatal error: Could not check compatibility between Test::createFromFormat($format, $datetime, ?Wrong $timezone = null) and DateTime::createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null), because class Wrong is not available in %s on line %d
60 changes: 30 additions & 30 deletions ext/date/php_date.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/** @generate-function-entries */

function strtotime(string $time, ?int $now = null): int|false {}
function strtotime(string $datetime, ?int $now = null): int|false {}

function date(string $format, ?int $timestamp = null): string {}

Expand All @@ -11,14 +11,14 @@ function idate(string $format, ?int $timestamp = null): int|false {}
function gmdate(string $format, ?int $timestamp = null): string {}

function mktime(
int $hour, ?int $min = null, ?int $sec = null,
?int $mon = null, ?int $day = null, ?int $year = null): int|false {}
int $hour, ?int $minute = null, ?int $second = null,
?int $month = null, ?int $day = null, ?int $year = null): int|false {}

function gmmktime(
int $hour, ?int $min = null, ?int $sec = null,
?int $mon = null, ?int $day = null, ?int $year = null): int|false {}
int $hour, ?int $minute = null, ?int $second = null,
?int $month = null, ?int $day = null, ?int $year = null): int|false {}

function checkdate(int $m, int $d, int $y): bool {}
function checkdate(int $month, int $day, int $year): bool {}

function strftime(string $format, ?int $timestamp = null): string|false {}

Expand All @@ -30,26 +30,26 @@ function localtime(?int $timestamp = null, bool $associative = false): array {}

function getdate(?int $timestamp = null): array {}

function date_create(string $time = "now", ?DateTimeZone $timezone = null): DateTime|false {}
function date_create(string $datetime = "now", ?DateTimeZone $timezone = null): DateTime|false {}

function date_create_immutable(
string $time = "now", ?DateTimeZone $timezone = null): DateTimeImmutable|false {}
string $datetime = "now", ?DateTimeZone $timezone = null): DateTimeImmutable|false {}

function date_create_from_format(
string $format, string $time, ?DateTimeZone $timezone = null): DateTime|false {}
string $format, string $datetime, ?DateTimeZone $timezone = null): DateTime|false {}

function date_create_immutable_from_format(
string $format, string $time, ?DateTimeZone $timezone = null): DateTimeImmutable|false {}
string $format, string $datetime, ?DateTimeZone $timezone = null): DateTimeImmutable|false {}

function date_parse(string $date): array {}
function date_parse(string $datetime): array {}

function date_parse_from_format(string $format, string $date): array {}
function date_parse_from_format(string $format, string $datetime): array {}

function date_get_last_errors(): array|false {}

function date_format(DateTimeInterface $object, string $format): string {}

function date_modify(DateTime $object, string $modify): DateTime|false {}
function date_modify(DateTime $object, string $modifier): DateTime|false {}

function date_add(DateTime $object, DateInterval $interval): DateTime {}

Expand All @@ -62,10 +62,10 @@ function date_timezone_set(DateTimeInterface $object, DateTimeZone $timezone): D
function date_offset_get(DateTimeInterface $object): int {}

function date_diff(
DateTimeInterface $object, DateTimeInterface $object2, bool $absolute = false): DateInterval {}
DateTimeInterface $object1, DateTimeInterface $object2, bool $absolute = false): DateInterval {}

function date_time_set(
DateTime $object, int $hour, int $minute, int $second = 0, int $microseconds = 0): DateTime {}
DateTime $object, int $hour, int $minute, int $second = 0, int $microsecond = 0): DateTime {}

function date_date_set(DateTime $object, int $year, int $month, int $day): DateTime {}

Expand Down Expand Up @@ -94,7 +94,7 @@ function timezone_abbreviations_list(): array {}

function timezone_version_get(): string {}

function date_interval_create_from_date_string(string $time): DateInterval|false {}
function date_interval_create_from_date_string(string $datetime): DateInterval|false {}

function date_interval_format(DateInterval $object, string $format): string {}

Expand All @@ -103,16 +103,16 @@ function date_default_timezone_set(string $timezone_identifier): bool {}
function date_default_timezone_get(): string {}

function date_sunrise(
int $time, int $retformat = SUNFUNCS_RET_STRING,
int $timestamp, int $retformat = SUNFUNCS_RET_STRING,
?float $latitude = null, ?float $longitude = null, ?float $zenith = null,
float $gmt_offset = 0): string|int|float|false {}

function date_sunset(
int $time, int $retformat = SUNFUNCS_RET_STRING,
int $timestamp, int $retformat = SUNFUNCS_RET_STRING,
?float $latitude = null, ?float $longitude = null, ?float $zenith = null,
float $gmt_offset = 0): string|int|float|false {}

function date_sun_info(int $time, float $latitude, float $longitude): array {}
function date_sun_info(int $timestamp, float $latitude, float $longitude): array {}

// NB: Adding return types to methods is a BC break!
// For now only using @return annotations here.
Expand All @@ -139,7 +139,7 @@ public function __wakeup();

class DateTime implements DateTimeInterface
{
public function __construct(string $time = "now", ?DateTimeZone $timezone = null) {}
public function __construct(string $datetime = "now", ?DateTimeZone $timezone = null) {}

public function __wakeup() {}

Expand All @@ -155,7 +155,7 @@ public static function createFromInterface(DateTimeInterface $object): DateTime
* @return DateTime|false
* @alias date_create_from_format
*/
public static function createFromFormat(string $format, string $time, ?DateTimeZone $timezone = null) {}
public static function createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null) {}

/**
* @return array|false
Expand All @@ -173,7 +173,7 @@ public function format(string $format) {}
* @return DateTime|false
* @alias date_modify
*/
public function modify(string $modify) {}
public function modify(string $modifier) {}

/**
* @return DateTime
Expand Down Expand Up @@ -209,7 +209,7 @@ public function getOffset() {}
* @return DateTime
* @alias date_time_set
*/
public function setTime(int $hour, int $minute, int $second = 0, int $microseconds = 0) {}
public function setTime(int $hour, int $minute, int $second = 0, int $microsecond = 0) {}

/**
* @return DateTime
Expand All @@ -221,7 +221,7 @@ public function setDate(int $year, int $month, int $day) {}
* @return DateTime
* @alias date_isodate_set
*/
public function setISODate(int $year, int $week, int $day = 1) {}
public function setISODate(int $year, int $week, int $day_of_week = 1) {}

/**
* @return DateTime
Expand All @@ -244,7 +244,7 @@ public function diff(DateTimeInterface $object, bool $absolute = false) {}

class DateTimeImmutable implements DateTimeInterface
{
public function __construct(string $time = "now", ?DateTimeZone $timezone = null) {}
public function __construct(string $datetime = "now", ?DateTimeZone $timezone = null) {}

public function __wakeup() {}

Expand All @@ -255,7 +255,7 @@ public static function __set_state(array $array) {}
* @return DateTimeImmutable|false
* @alias date_create_immutable_from_format
*/
public static function createFromFormat(string $format, string $time, ?DateTimeZone $timezone = null) {}
public static function createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null) {}

/**
* @return array|false
Expand Down Expand Up @@ -294,7 +294,7 @@ public function getTimestamp() {}
public function diff(DateTimeInterface $object, bool $absolute = false) {}

/** @return DateTimeImmutable|false */
public function modify(string $modify) {}
public function modify(string $modifier) {}

/** @return DateTimeImmutable */
public function add(DateInterval $interval) {}
Expand All @@ -306,13 +306,13 @@ public function sub(DateInterval $interval) {}
public function setTimezone(DateTimeZone $timezone) {}

/** @return DateTimeImmutable */
public function setTime(int $hour, int $minute, int $second = 0, int $microseconds = 0) {}
public function setTime(int $hour, int $minute, int $second = 0, int $microsecond = 0) {}

/** @return DateTimeImmutable */
public function setDate(int $year, int $month, int $day) {}

/** @return DateTimeImmutable */
public function setISODate(int $year, int $week, int $day = 1) {}
public function setISODate(int $year, int $week, int $day_of_week = 1) {}

/** @return DateTimeImmutable */
public function setTimestamp(int $timestamp) {}
Expand Down Expand Up @@ -377,7 +377,7 @@ public function __construct(string $interval_spec) {}
* @return DateInterval|false
* @alias date_interval_create_from_date_string
*/
public static function createFromDateString(string $time) {}
public static function createFromDateString(string $datetime) {}

/**
* @return string
Expand Down

3 comments on commit e96e4ac

@carusogabriel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this needs an entry on UPGRADING as per https://wiki.php.net/rfc/named_params, this is a BC, right?

@nikic
Copy link
Member

@nikic nikic commented on e96e4ac Jul 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carusogabriel This is not a BC break until PHP 8 has been released. That's exactly why everything is getting renamed now.

@carusogabriel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just saw php/php-tasks#16, thanks!

Please sign in to comment.