use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
siehe die Such-FAQ für Details.
Erweiterte Suche: nach Autor, Subreddit...
Please follow the rules
Releases: Current Releases, Windows Releases, Old Releases
Contribute to the PHP Documentation
Related subreddits: CSS, JavaScript, Web Design, Wordpress, WebDev
/r/PHP is not a support subreddit. Please visit /r/phphelp for help, or visit StackOverflow.
Account-Aktivität
What if PHP strings had shapes? (helgesver.re)
eingereicht vor 5 Tagen von TheHelgeSverre
A braindump of an idea i had while looking through some laravel code, any thoughts on this kind of thing, would it be useful, or should this go in the trash pile of stupid ideas?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
Zitierter Text
if 1 * 2 < 3: print "hello, world!"
[–]d645b773b320997e1540 19 Punkte20 Punkte21 Punkte vor 4 Tagen (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 Punkte3 Punkte vor 4 Tagen (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 Punkte3 Punkte vor 4 Tagen (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.
[–]riggiddyrektson 43 Punkte44 Punkte45 Punkte vor 4 Tagen* (14 Kinder)
PHP devs will do anything but use proper classes for data representation
[–]mkopinsky 9 Punkte10 Punkte11 Punkte vor 4 Tagen (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 Punkte3 Punkte vor 4 Tagen (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.
[–]MineDesperate8982 4 Punkte5 Punkte6 Punkte vor 4 Tagen (1 Kind)
PHP stands for Peak Haters Pissing.
[–]TheHelgeSverre[S] 9 Punkte10 Punkte11 Punkte vor 4 Tagen (0 Kinder)
Personal Hate Page
[–]WesamMikhail 2 Punkte3 Punkte4 Punkte vor 4 Tagen (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 Punkte3 Punkte vor 4 Tagen (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 Punkte8 Punkte vor 4 Tagen (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 Punkte3 Punkte vor 4 Tagen (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 Punkte3 Punkte vor 4 Tagen* (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 Punkt2 Punkte vor 4 Tagen (1 Kind)
Still requires that you write one class per file, or use require which nobody should be doing outside of index.php.
require
index.php
[–]Teszzt 2 Punkte3 Punkte4 Punkte vor 4 Tagen (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 Punkte3 Punkte vor 4 Tagen (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 Punkte1 Punkt vor 4 Tagen (0 Kinder)
I always say this to devs: classes are free
[–]inotee -2 Punkte-1 Punkte0 Punkte vor 4 Tagen (0 Kinder)
Haha exactly my thought! I think it's an artifact from frontend devs attempting backend stuff.
[–]deliciousleopard 10 Punkte11 Punkte12 Punkte vor 4 Tagen (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 Punkte6 Punkte vor 4 Tagen (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 Punkte3 Punkte vor 4 Tagen (0 Kinder)
Ooo, that is neat, have not seen this before.
[–]exqueezemenow 5 Punkte6 Punkte7 Punkte vor 4 Tagen (0 Kinder)
I have been needing a rhombus shaped string for a long time.
[–]obstreperous_troll 2 Punkte3 Punkte4 Punkte vor 4 Tagen (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 Punkte3 Punkte vor 4 Tagen (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 Punkt2 Punkte vor 4 Tagen (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 Punkt2 Punkte vor 4 Tagen (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 Punkte1 Punkt vor 4 Tagen (0 Kinder)
Overcomplicating simple problems is more fun though.
[–]Pakspul 0 Punkte1 Punkt2 Punkte vor 4 Tagen (0 Kinder)
How about objects?
π Rendered by PID 212920 on reddit-service-r2-comment-5f54b4f85b-crclt at 2026-08-11 10:08:45.939600+00:00 running 895b7ad country code: DE.
[–]d645b773b320997e1540 19 Punkte20 Punkte21 Punkte (2 Kinder)
[–]MorphineAdministered 1 Punkt2 Punkte3 Punkte (1 Kind)
[–]d645b773b320997e1540 1 Punkt2 Punkte3 Punkte (0 Kinder)
[–]riggiddyrektson 43 Punkte44 Punkte45 Punkte (14 Kinder)
[–]mkopinsky 9 Punkte10 Punkte11 Punkte (1 Kind)
[–]obstreperous_troll 1 Punkt2 Punkte3 Punkte (0 Kinder)
[–]MineDesperate8982 4 Punkte5 Punkte6 Punkte (1 Kind)
[–]TheHelgeSverre[S] 9 Punkte10 Punkte11 Punkte (0 Kinder)
[–]WesamMikhail 2 Punkte3 Punkte4 Punkte (0 Kinder)
[–]thejoyofbeing1 1 Punkt2 Punkte3 Punkte (5 Kinder)
[–]Crell 6 Punkte7 Punkte8 Punkte (4 Kinder)
[–]thejoyofbeing1 1 Punkt2 Punkte3 Punkte (3 Kinder)
[–]riggiddyrektson 1 Punkt2 Punkte3 Punkte (2 Kinder)
[–]thejoyofbeing1 0 Punkte1 Punkt2 Punkte (1 Kind)
[–]Teszzt 2 Punkte3 Punkte4 Punkte (0 Kinder)
[–]rafark 1 Punkt2 Punkte3 Punkte (0 Kinder)
[–]ElectronicGarbage246 -1 Punkte0 Punkte1 Punkt (0 Kinder)
[–]inotee -2 Punkte-1 Punkte0 Punkte (0 Kinder)
[–]deliciousleopard 10 Punkte11 Punkte12 Punkte (0 Kinder)
[–]Sn0wCrack7 4 Punkte5 Punkte6 Punkte (1 Kind)
[–]TheHelgeSverre[S] 1 Punkt2 Punkte3 Punkte (0 Kinder)
[–]exqueezemenow 5 Punkte6 Punkte7 Punkte (0 Kinder)
[–]obstreperous_troll 2 Punkte3 Punkte4 Punkte (0 Kinder)
[–]s1gidi 1 Punkt2 Punkte3 Punkte (3 Kinder)
[–]obstreperous_troll 0 Punkte1 Punkt2 Punkte (1 Kind)
[–]liljefelt 0 Punkte1 Punkt2 Punkte (0 Kinder)
[–]TheHelgeSverre[S] -1 Punkte0 Punkte1 Punkt (0 Kinder)
[–]Pakspul 0 Punkte1 Punkt2 Punkte (0 Kinder)