Interface Default Methods
Closed this issue · 4 comments
thekid commented
Can we support the features shown in https://wiki.php.net/rfc/interface-default-methods?
interface Value {
public function toString();
public function compareTo($value) {
return $this <=> $value;
}
}
class Listing implements Value {
public function toString() {
// Needs to be implemented
}
public function compareTo($value) {
// Can be implemented
}
}
Test cases can be found here: php/php-src@master...morrisonlevi:php-src:interface-default-methods
thekid commented
Could be implemented by a) emitting this as a trait method, b) including this trait in the class:
interface Value {
public function toString();
public function compareTo($value);
}
trait __Value_Defaults {
public function compareTo($value) {
return $this <=> $value;
}
}
class Listing implements Value {
use __Value_Defaults;
public function toString() {
// Needs to be implemented
}
public function compareTo($value) {
// Can be implemented
}
}
...and c) changing the reflection API to suppress "magic" classes starting with __
.
thekid commented
There's now a PR for this @ php/php-src#11467
thekid commented
Discussion on PHP internals mailing list @ https://externals.io/message/120582
thekid commented
RFC has been declined