Alle 28 Kommentare

[–]d645b773b320997e1540 19 Punkte20 Punkte  (2 Kinder)

one could take such an example and ponder about giving strings shape. OR, one could ponder if something like that should be a string in the first place...

[–]MorphineAdministered 1 Punkt2 Punkte  (1 Kind)

It probably has to be a string at some point (like cli command), but not for long enough to warrant informing everyone about its "shape". The only entity that should need this information is parser and, if some library is used, might simply be a passed argument*

*) The reason for this meta-directive programming and why passing arguments is such a problem is called auto-wired instantiation, which was a cancer of software development before AI took the lead.

[–]d645b773b320997e1540 1 Punkt2 Punkte  (0 Kinder)

It doesn't have to be a string, whatsoever. all Laravel really does is pass it down to Symfony anyway, and Symfony has a much nicer way of doing this these days.

[–]mkopinsky 9 Punkte10 Punkte  (1 Kind)

s/PHP/Laravel/

Symfony does this fine. Laravel paints itself into this corner by making things "easier" and now it has to finger-paint its way back out of the corner with silliness like this blog post.

[–]obstreperous_troll 1 Punkt2 Punkte  (0 Kinder)

Laravel even extends Symfony's command base class, but since it can't properly support Symfony's attributes, it's far less useful.

[–]WesamMikhail 2 Punkte3 Punkte  (0 Kinder)

It really irks me. I don't understand why people do this. Maybe the problem is that we have a too rigid of a class system that doesnt enable sufficient flexibility. But still, I don't for the life of me understand why this needs to be a damn string to begin with...

[–]thejoyofbeing1 1 Punkt2 Punkte  (5 Kinder)

IMO this is mainly because of how the module system (or lack of) works.

No one wants to create and import 20 files for 20 DTOs, it creates a lot of indirection. I would use DTOs for everything if I could do:

// foo.php
final readonly class Options
{
    public function __construct(public string $foo) {}
}

final class SomethingWhatever
{
    public function doSomething(Options $options) {}
}

// bar.php
// somehow import the whole module, instead of just one class

$something = new Module.SomethingWhatever();
$something->doSomething(new Module.Options("no one wants to import 20 files for DTOs"));

[–]Crell 6 Punkte7 Punkte  (4 Kinder)

My IDE handles all the use statements for me. I... don't see the problem. I use classes for bloody well everything. 😄

[–]thejoyofbeing1 1 Punkt2 Punkte  (3 Kinder)

Yeah, I don't think anyone is writing use statements manually in 2026, that's not was botters me.

I just feel like keeping DTOs and their use cases together would be really neat from a code organization POV.

[–]riggiddyrektson 1 Punkt2 Punkte  (2 Kinder)

The php police totally allows organizing your code into modules.
Also you can just import the outer namespace so you can easily reference the inner classes without reimporting.
Instead of

use Foo\Bar\Class1;
use Foo\Bar\Class2;

new Class1();
new Class2();

you can do

use Foo\Bar;

new Bar\Class1();
new Bar\Class2();

[–]thejoyofbeing1 0 Punkte1 Punkt  (1 Kind)

Still requires that you write one class per file, or use require which nobody should be doing outside of index.php.

[–]Teszzt 2 Punkte3 Punkte  (0 Kinder)

Not really. It's rather straightforward to create a custom autoload that can load multiple classes from a single "module" file. One file per class is PSR, not PHP.

Other than having less files, what is the advantage of putting multiple classes in the same file?

[–]rafark 1 Punkt2 Punkte  (0 Kinder)

If that’s true it might be a sign that there are better ways to do things and that classes are not the holly gray and a one thing fits all solution especially with the standards of one class per file. 

[–]ElectronicGarbage246 -1 Punkte0 Punkte  (0 Kinder)

I always say this to devs: classes are free

[–]inotee -2 Punkte-1 Punkte  (0 Kinder)

Haha exactly my thought! I think it's an artifact from frontend devs attempting backend stuff.

[–]deliciousleopard 10 Punkte11 Punkte  (0 Kinder)

This is just Laravel being Laravel.

Symfony (which Laravel wraps) has a lot saner API for this and AFAIK it works just fine for Laravel commands.

https://symfony.com/doc/current/console/input.html

[–]Sn0wCrack7 4 Punkte5 Punkte  (1 Kind)

While not solving the same problem exactly it does remind me of this C# feature: https://steven-giesel.com/blogPost/d2b2fc18-ca4c-4879-b87f-a1d36f435805

[–]TheHelgeSverre[S] 1 Punkt2 Punkte  (0 Kinder)

Ooo, that is neat, have not seen this before.

[–]exqueezemenow 5 Punkte6 Punkte  (0 Kinder)

I have been needing a rhombus shaped string for a long time.

[–]obstreperous_troll 2 Punkte3 Punkte  (0 Kinder)

TypeScript has template string literals (example). Useful in some cases, but overall a pretty marginal feature. Might be able to write it for PHPStan or Psalm, but not the slightest chance such a feature would land in the language proper.

[–]s1gidi 1 Punkt2 Punkte  (3 Kinder)

Set aside all the other comments about the approach of using strings is the wrong one in the first place. Which it is..

You seem to go through a lot of trouble to avoid having to use regular expressions. Though regex can give you the same thing, be more powerful, provide validation at the same time and instead of learning a new "language" in a language you could use an existing one that is also useful outside of this use case.

[–]obstreperous_troll 0 Punkte1 Punkt  (1 Kind)

I love me some regexes, wrote them day in and day out for both hobby hacking and my day job, but I wouldn't want to make them the DX for parsing command line options. Regexes are great background knowledge to have, but they're the beginning of writing real parsers, not the end.

[–]liljefelt 0 Punkte1 Punkt  (0 Kinder)

Slightly related;
I don't recall the source but I always loved this phrase: "plural of regex is regrets"

[–]TheHelgeSverre[S] -1 Punkte0 Punkte  (0 Kinder)

Overcomplicating simple problems is more fun though.

[–]Pakspul 0 Punkte1 Punkt  (0 Kinder)

How about objects?