-
-
Notifications
You must be signed in to change notification settings - Fork 205
Open
Description
Analysis
Recap of existing PHP 8.2 behavior based on the RFC:
class DatePeriod
{
// Signature 1: can be called with 3 or 4 arguments.
public function __construct(DateTimeInterface $start, DateInterval $interval, int $recurrences, int $options = 0) {}
// Signature 2: can be called with 3 or 4 arguments.
public function __construct(DateTimeInterface $start, DateInterval $interval, DateTimeInterface $end, int $options = 0) {}
// Signature 3: can be called with 1 or 2 arguments.
public function __construct(string $isostr, int $options = 0) {}
}Updated behavior for each version:
class DatePeriod
{
// Signature 1: unchanged behavior, signature 4 will merely merge 1 and 2.
// Signature 2: unchanged behavior, signature 4 will merely merge 1 and 2.
// Signature 3: deprecated in 8.4, removed in a future (TBD) major version.
// Signature 4: unchanged behavior, merges signatures 1 and 2 in a future (TBD) major version.
// From the user's perspective, this is only a documentation update.
public function __construct(DateTimeInterface $start, DateInterval $interval, DateTimeInterface|int $end, int $options = 0) {}
// Named constructor: replaces signature 3, added in PHP 8.3
public static function createFromISO8601String(string $specification, int $options = 0): static {}
}Detection in PHP 8.2
DatePeriod::createFromISO8601Stringis invalid.- Any form of
new DatePeriod(...)is unchanged and out of scope for this version, see "Syntax Variations" below.
Detection in PHP 8.3
DatePeriod::createFromISO8601Stringis valid.- Any form of
new DatePeriod(...)is unchanged and out of scope for this version, see "Syntax Variations" below.
Detection in PHP 8.4
new DatePeriod(...)with 1 or 2 arguments is deprecated, add warning. See "Syntax Variations" below.
Syntax Variations
new DatePeriod(...)✅ Can be handled by PHPCompatibility.$className = 'DatePeriod'; new $className();❌ Unreliable, as $className could be defined anywhere.new SomeClassWhichExtendsDatePeriod(...)❌ Can't be handled.class Foo extends DatePeriod { ... parent::__construct(...) ... }✅ Should be doable.
3v4l.org
- DatePeriod::createFromISO8601String - named constructor forbidden in PHP <=8.2
- DatePeriod::__construct - signature 3 deprecated in PHP >=8.4
- Child of DatePeriod - parent::__construct - 2nd level inheritance out of scope, no need to snuff
References
jrfnl