final class PostsController
{
#[AccessControl(fn(Request $request, Post $post)
=> $request->user === $post->getAuthor()
)]
public function update(Request $request, Post $post): Response {
// ...
}
}
Native (and optionally value-backed) enums:
enum Status
{
case Draft;
case Published;
case Archived;
}
Proper class property hooks, fully replacing getters and setters:
class Data
{
public string $fullName {
get => "{$this->firstName} {$this->lastName}";
set(string $value) {
[$first, $last] = explode(' ', $value);
$this->firstName = $first;
$this->lastName = $last;
}
}
}
And tons of other features—among them asymmetric property visibility, fibres/green threads, DNF types, lazy object instantiation, an ever-improving yet fully opt-in static type system with runtime validation, a JIT compiler, an amazing package ecosystem and -manager, annotation-backed deprecation, and more.
There is, but your example is not valid. You can't use short function syntax in constant expressions, it has to be an explicit `static function`.
The reason for this, IIRC (I can't find the GitHub issue or PR atm) is that these functions aren't allowed to close over any variables, and with fn syntax doing so is implicit. Rather than erroring they've disallowed the use of arrow functions entirely.
You’re right, of course. Still I think the point stands that PHP has very powerful runtime metaprogramming features that you can build amazing abstractions on top of.
Looks like PHP is trying to act like Elixir. And all these are very new thing which we can't implement in wordpress because you have to care about backward compatibility.
These "very new things" have, in part, been available for more than 6 years now. Not to speak of all the other PHP features WordPress chose to forgo, like PDO with prepared statements (which completely eliminates SQL injections), which came out 21 freakin' years ago.
There are many very successful and professional PHP projects with millions of users that seem to be able to migrate to newer PHP versions just fine.
Whatever the WordPress developers are claiming are the reasons for their irresponsible codebase and their inability to improve it is nobody's fault but their own.
Let me convince you! :-)
There are match expressions and arrow functions:
There is meta-programming with annotations:
Native (and optionally value-backed) enums:
Proper class property hooks, fully replacing getters and setters:
And tons of other features—among them asymmetric property visibility, fibres/green threads, DNF types, lazy object instantiation, an ever-improving yet fully opt-in static type system with runtime validation, a JIT compiler, an amazing package ecosystem and -manager, annotation-backed deprecation, and more.
> There is meta-programming with annotations:
There is, but your example is not valid. You can't use short function syntax in constant expressions, it has to be an explicit `static function`.
The reason for this, IIRC (I can't find the GitHub issue or PR atm) is that these functions aren't allowed to close over any variables, and with fn syntax doing so is implicit. Rather than erroring they've disallowed the use of arrow functions entirely.
You’re right, of course. Still I think the point stands that PHP has very powerful runtime metaprogramming features that you can build amazing abstractions on top of.
The issue isn't that they haven't added a load of modern features; it's that they never fixed the old janky broken features.
Reminds me that in the PHP5 days, there's a load of similar functions of which the parameters switch around...
1 reply →
Looks like PHP is trying to act like Elixir. And all these are very new thing which we can't implement in wordpress because you have to care about backward compatibility.
These "very new things" have, in part, been available for more than 6 years now. Not to speak of all the other PHP features WordPress chose to forgo, like PDO with prepared statements (which completely eliminates SQL injections), which came out 21 freakin' years ago.
There are many very successful and professional PHP projects with millions of users that seem to be able to migrate to newer PHP versions just fine.
Whatever the WordPress developers are claiming are the reasons for their irresponsible codebase and their inability to improve it is nobody's fault but their own.
> Nope.
Beauty is in the eye of the beholder, and I'll disagree kindly with you on that "Nope".