3 ms·
Yes, that's been brilliant. Read-only properties too. A typical PHP file now includes: <?php declare(strict_types=1); namespace App\Something;
by blowski 4y ago
Yes, that's been brilliant. Read-only properties too.
A typical PHP file now includes:
<?php
declare(strict_types=1);
namespace App\Something;
use App\Services\Bar;
final class Foo
{
public function __construct(private readonly Bar $bar) {}
public function doSomething(): string
{
return $this->bar->baz();
}
}
And I end up with a lot of PHP files that look very simlar. I'd love some defaults here.
* strict types
* namespaces to be autocalculated (since PSR-4 means it has to be in that namespace anyway)
* private, final and readonly both default to true
* The opening PHP tag
* Relative namespace
* Plus all those brackets and words that duplicate information. If it has brackets, it's a function. An empty function body doesn't need curly brackets.
I recognise this is a backwards-compatbility thing, so it's not as easy as "just do it". But I'd love a PHP file that looked lke:
class Bar
{
__construct(Services\Baz $baz)
public doSomething(): string
{
return $this->baz->bar();
}
}
But again, this is me waxing lyrical. I still prefer PHP to Python, but I do like Python's expressiveness.