PHP Core Roundup 14
Marcos Marcolin β’ June 30, 2023 β’ 1 min read
php phpfoundation opensource php-core-roundupπ The next PHP version, 8.3, is scheduled for release on November 23rd. With that, the feature freeze is getting close.
While we wait, the core keeps bringing new features, internal improvements, and bug and security fixes. π
PHP Core Roundup #14 highlights a few RFCs (Request for Comments) and recent discussions on the PHP mailing list. Some of these RFCs include introducing the #[\Override] attribute to mark overridden methods, improvements to the range() function, introducing the mb_str_pad() function for multibyte string handling, and proposals to deprecate certain less consistent PHP features.
On the new #[\Override] attribute, if this attribute is added to a method, the engine will validate that a method with the same name exists in a parent class or in any of the implemented interfaces. If no such method exists, a compile error will be raised.
// Valid example
class P {
protected function p(): void {}
}
class C extends P {
#[\Override]
public function p(): void {}
}
// Valid example
class Foo implements IteratorAggregate
{
#[\Override]
public function getIterator(): Traversable
{
yield from [];
}
}
// Invalid example
class C
{
#[\Override]
public function c(): void {} // Fatal error: C::c() has #[\Override] attribute, but no matching parent method exists
}
// Invalid example
interface I {
public function i(): void;
}
class P {
#[\Override]
public function i(): void {} // Fatal error: P::i() has #[\Override] attribute, but no matching parent method exists
}
class C extends P implements I {}
To check out everything new this month, click here.