I've been writing PHP for 20 years now. It's my bread and butter.
The one thing I really wish PHP would add is structurally typed objects. I really miss it when moving back and forth between PHP and TypeScript.
They could call them anonymous objects if they want to (that would be a more culturally correct analogue to anonymous classes).
Like, I wish it was possible to do
{
string $mystring = $myvar,
}
and have it be equivalent to
new class($myvar) {
public function __construct(
readonly public string $mystring,
) {}
}
and then be able to typehint it like
function ({ string $mystring } $myobj) {
echo $myobj->mystring;
}
and honestly, why not go all the way and allow type definitions/aliases, something like
type myobj_type = { string $mystring };
That'd be great.
The one thing I really wish PHP would add is structurally typed objects. I really miss it when moving back and forth between PHP and TypeScript.
They could call them anonymous objects if they want to (that would be a more culturally correct analogue to anonymous classes).
Like, I wish it was possible to do
and have it be equivalent to and then be able to typehint it like and honestly, why not go all the way and allow type definitions/aliases, something like That'd be great.