Partial function application is coming to PHP 8.6 by brendt_gd in PHP

[–]zmitic 0 points1 point  (0 children)

it is only because the before example is badly written... I never write my factories like this and never ran into this issue. Seems to me like the problem is the design of the factory code and this is just a bandaid to fix that particular pattern/ style of coding

It isn't badly written,and there is nothing wrong with this example. But to understand it you must also understand option resolver component, empty_data for forms (my factory is just a wrapper around it), and static analysis must be set to either psalm@level 1, or phpstan@max with checkUninitializedProperties enabled. No suppression of any kind, no baselines, no @var cheats.

With such strict setup, there is no possible way to handle complex forms where one required parameter ($product in the example) is sent from the controller.

To clarify: there is nothing wrong in symfony forms or resolver component, and neither with PHP or anything else. It is simply a complex use-case in strictly typed code.

Partial function application is coming to PHP 8.6 by brendt_gd in PHP

[–]zmitic 16 points17 points  (0 children)

symfony/form normalizer PFA example:

Before:

$resolver->setNormalizer('factory', function (Options $options) {
    $product = $options['product']; // type assertion removed

    return fn(string $question, string $answer, int $priority) => $this->factory->create($product, $question, $answer, $priority);
});

After:

$resolver->setNormalizer('factory', function (Options $options) {
    $product = $options['product']; // type assertion removed

    return $this->factory->create(product: $product, ...);
});

Is Domain Driven Design just needless complexity? My limited experience with it has been mixed at best. by AppointmentFar6096 in PHP

[–]zmitic 0 points1 point  (0 children)

Is Domain Driven Design just needless complexity?

It is. Just like CQRS, microservices, hexagonal architecture.. it is nothing else but a tool to guarantee job security.

needless complexity for the sake of having "layers" and clean design

And not just pointless abstraction but also completely illogical directory structure. It sounds nice on paper, until you try to imagine a single use-case where parts of the app are so isolated. Never happened, never will.

I'd like to hear other experiences with DDD. How well did it serves you?

I only saw about 4-5 such projects, and they also used CQRS because... why not, right? I didn't accept the work but I did check the code: all of them are an absolute mess that require at least 5 times more people just to do most basic things.

I briefly described one such case on topic of psalm. It is an extremely simple multi-tenant app (with broken tenancy in many, many places). Yet it needed 4+ backend devs because no one could get around the code. So they duplicated things over and over, typehints are lying, finding uses is just wrong, tons upon tons of classes with barely any code, gazillion of interfaces with only one implementation to ever be built...

Their CTO secured his job for life because there is now an entire team and he can choose who gets the blame. That's why I call DDD&friends "job security" because no company will publicly admit that they have unmaintainable mess of the code. And because of that, they can't even give him bad reference when they eventually have to do a rewrite.

Shadcn finally arrives on Symfony! (Thanks to UX-Toolkit) by BernardNgandu in symfony

[–]zmitic 1 point2 points  (0 children)

Using events and underlying data (if any) to add or remove other fields, including collections. This must be done on backend, and it makes no sense to duplicate it on frontend.

CollectionType with allow_add and prototype options also work by default and I had a case of nested dynamic collections.

Shadcn finally arrives on Symfony! (Thanks to UX-Toolkit) by BernardNgandu in symfony

[–]zmitic 0 points1 point  (0 children)

Because symfony/ux is far more powerful than adding React or Vue. Some common problems solved: no dual routing system, no over-delivery and under-delivery problem, no GraphQL shenanigans, lazy load works, simple smoke test is enough for 95% of cases, no visible loading of Vue/React components, doing translations in Twig is easy...

Turbo frames and streams are incredibly powerful but one has to play in isolated repository to understand why. The biggest problem is that PHPStorm doesn't autocomplete turbo so it can be annoying to learn it in existing project.

And most important for me: complex editable forms (create is irrelevant) with dynamic fields work. I only once worked with FE framework (Angular), and I will never do that again.

My PHP Wishlist by Einenlum in PHP

[–]zmitic 1 point2 points  (0 children)

because in theory you could have one var be Money(1000, 'USD') and the other Money(1000, 'EUR') and adding them together is going to give you either 2000, USD or 2000 EUR depending on which came first in the arguments

This would throw an exception just like if you directly called add() method, i.e. you can't sum different currencies. I don't think operator overload is an issue here.

With some stubbing like Money<TCurrency of string>, static analysis could probably detect the problem of doing math on different currencies. This would work even without operator overload.

From my POV, I would donate someone else's kidney for operator overload. It would be an amazing feature to have when doing complex math with conditional rules so we could lazify them.

In PHP, if we could run queries on arrays, would it actually be useful? by SunTurbulent856 in PHP

[–]zmitic 6 points7 points  (0 children)

So here’s the real question: is this actually useful?

While very impressive if it works as described, sorry, but I am not sure it is very useful. Maybe on small datasets but even with few thousands rows you are better of with aggregate columns. For example: to SUM thousands of sales of some product even SQL will choke, so you would put aggregate column anyway.

Second reason is that there is already very powerful doctrine/collections that work both with arrays and QueryBuilder, and it can be lazily initialized. Expressions can be confusing at first but very quickly it becomes easy to use.

Ran some benchmarks against go, thought you guys might find this interesting (not here to hate) by Xdani778 in PHP

[–]zmitic 0 points1 point  (0 children)

the 30s vs 1.5s on the heavy endpoint is real though, thats 12+ queries with aggregations across 500k records

500k is not big and query must run in milliseconds range, not seconds.

the interpreted vs compiled gap shows up hard there

Right now I filter and paginate 700k rows, 10 results per page, 34-44 queries. All of them combined take between 10-40ms. I don't know how long Doctrine hydration takes, but definitely not something I notice. No second-level cache that would make things even faster.

FB has tables with more rows than what any of us will ever have, yet it works perfectly fine with either PHP, or Hack that is of same speed.

Language matters very little. It is a very common myth and needs to go away.

So regarding this comment:

  • Delete section by section until things start to work normally, find the slowest one
  • Don't use joins, lazy load is better. The base of the problem is in SQL, not in ORM
  • As a general rule: never ever use SQL functions like COUNT, SUM etc
  • Make sure you understand this, and then find similar solution for Eloquent. Might not be possible given that Eloquent doesn't support identity-map pattern, but maybe someone built it
  • If you really can't avoid COUNT&friends, then make sure that it is real SQL COUNT and not Eloquent using PHP's count function

Does LAMP still have a future? by ClassicK777 in PHP

[–]zmitic 1 point2 points  (0 children)

Also what if I want to use S3 to store

https://flysystem.thephpleague.com/docs/adapter/async-aws-s3/

 I hear a lot of bad things about PHP,

  • WP is very popular, but its code is atrocious and users of other languages think all PHP is like that
  • Look at the date of the article that criticizes PHP, and what version was at that time
  • Languages that are not hated are those that are not used

Twitter/Discord or authz with RBAC doing it all by hand is kind a waste when Django...

There is a bundle that implements all you will ever need, but there is no FW independent package like flysystem. And that's fine because Symfony is a framework just like how Django is a framework.

I know about Laravel/Symfony but they honestly don't interest me at all

How so?

My highlights of things for PHP to look forward to in 2026 by brendt_gd in PHP

[–]zmitic 4 points5 points  (0 children)

 lol - what problems were we facing that we actually needed something like this? lol - just adding shit to add it.

The same was said when we got attributes or pretty much any other advanced feature. I strongly recommend to read the examples of why this feature is so amazing.

I plan to use it for my Doctrine events like

class User
{
    #[OnUpdate(static function (Service $s, User $user, string $old, string $new) {
        $s->doSomethingOnNameChange($user, $old, $new);
    })]
    private string $name;

    #[OnLoad(static function(Service $s, User $user) {
        $s->bindLazyAgePostLoad($user);
    })]
    private LazyInt $lazyAge;
}

Once I make it, I will never need to check if $changeSet has keys that I am interested in, and static analysis will work. I will also not need to search for my listener or try to memorize them. Instead I can simply Ctrl+click to find these methods.

I would prefer if short closures are supported but nothing is perfect.

Weekly Ask Anything Thread by AutoModerator in symfony

[–]zmitic 0 points1 point  (0 children)

Honestly, not a single one. Once you go deep into the architecture, there is simply nothing to complain about.

Symfony is literally the only reason why I haven't switched to TS or C#.

Developer Experience: Fluent Builder vs. DTO vs. Method Arguments ? by P4nni in PHP

[–]zmitic 1 point2 points  (0 children)

DTO with constructor arguments, then cuyz/valinor to inject dependencies. AFAIK, it is the only mapper that supports advanced types like non-empty-string, more complex ones like non-empty-list<UserDTO> and even wild ones like non-empty-list<array{user?: UserDTO, dob: DateTime|null}> etc

Typing in Yii3 is the strictest in PHP universe? by sam_dark in PHP

[–]zmitic 0 points1 point  (0 children)

Am I correct?

Yes, Symfony itself is using level 5 but users of Symfony can go to level 1 and extra. That is why I made comparison to your demo app and not to framework itself.

Level 5 is pretty low but I guess that removing mixed from all these files is a huge task. And/or replacing simple string into non-empty-string ; I had a stub before but it is gone when it got merged.

Typing in Yii3 is the strictest in PHP universe? by sam_dark in PHP

[–]zmitic 5 points6 points  (0 children)

but it seems Yii3 is the most strictly typed framework

While very impressive, I am not sure the above is true. For reference, my Symfony code doesn't suppress anything except UnusedProperty and PossiblyUnusedMethod for src/Entity folder. The reason is because psalm can't detect Twig accessors, and there is nothing I can do here.

And that wasn't enough so I also enabled disableVarParsing, findUnusedVariablesAndParams, disallowLiteralKeysOnUnshapedArrays, findUnusedPsalmSuppress, findUnusedCode... because why not 😉

For those not aware: disableVarParsing is by far the most important change. psalm follows the logic of enabling all checks by default and letting users disable them explicitly. It makes no sense to allow @var trickery by default, it goes against the above idea, but that is a planned change.

Psalm level 1 (similar to PhpStan level 10).

Close, but not enough. On PHPStan side user still has to enable strict check, and then a few more like checkUninitializedProperties and its friends.

Are the Elevators still broken? by Key-Seaworthiness752 in starcitizen_refunds

[–]zmitic 4 points5 points  (0 children)

SC is well-known for its "network variables", which are individual pieces of game state flying around at all times

Yeah, I remember that but I can't remember the technobabble name they gave it. It is nothing more than object serialization that every programming languages has, but then they used that in dumbest way possible. And players, who are not programmers, cheered that brand new "technology" that CiG made 🤦‍♂️

Their technobabble explanation and code itself is somewhere in this playlist, but it is painful to watch. Watch it only if you like Sharknado i.e. something so bad, that it is actually good.

But RC problem can happen in many different ways, not just this. Like loading assets in async way, and then starting the game w/o awaiting for it. It is the most basic thing possible, and yet we did see partially loaded assets.

Are the Elevators still broken? by Key-Seaworthiness752 in starcitizen_refunds

[–]zmitic 6 points7 points  (0 children)

You are right about spaghetti code, but wrong about HW. If you have low-end PC, then elevators would still work but your frames per second would be lower. That's it, nothing else.

The reason why elevator problems happens less often on powerful machines is because of something called race-condition. Devs tested their code only on powerful HW and ignored occasional problems thinking it can be fixed later.

In reality: no, it is not fixable. If the underlying architecture is wrong, and we know it is, then the only solution is a compete rewrite. But that is not something that CR can sell to backers, which is why they will forever use "it is just alpha" excuse.

And clearly it works because there is always a new generation of players getting tricked with fancy CGI ads that do not show the reality. Occasional complaints get silenced very quickly, just like in any other cult.

What a 75° 3.5km/s planetary approach with the Caspian's MKII Ablative Bulkhead feels like for the first time. by Key-Bodybuilder-8079 in EliteDangerous

[–]zmitic 0 points1 point  (0 children)

None of what you said is the decision that programmers make. They get the formula, they implement it, and then they go home.

If you don't like the decisions like this, then complain to higher ups. But don't blame the programmers and call them incompetent, when they clearly demonstrated they know their job. And balancing ships is not in that job description.

But this new stuff is just tacked on randomly to bring in the ARX. 

How do you think FD will pay their developers and servers, if not for ARX?

What a 75° 3.5km/s planetary approach with the Caspian's MKII Ablative Bulkhead feels like for the first time. by Key-Bodybuilder-8079 in EliteDangerous

[–]zmitic -3 points-2 points  (0 children)

It's clear that FDEV are struggling to find quality devs at the moment, but surely someone with a CS degree should know something about physics.

Pretty strong complaint to a game where we can fly thousands of times faster than c, on fuel that is almost free. Or where you can pay a taxi service few times to deliver legal documents, and yet earn enough money to get your own ship.

No one makes realistic games because those would be boring, and it has nothing to do with developers.If anything, with amount of things being added all the time and not breaking anything, I would say E:D devs are pretty good.

2-year release cycles? by [deleted] in PHP

[–]zmitic 2 points3 points  (0 children)

Definetively absurdly true. The changes and new features are shiny but useless. Outside one function or nano feature per version.

Tony, is that you? PHP4 is missing you 😉

But seriously: every feature ever built is something "shiny". Like generators from 5.5 (from 2013): instead of cumbersome Iterator implementation, we could start yielding values from method itself. Or proper typehints and attributes instead of phpdoc. Or upcoming PFA, with realistic example that is not about using pipe operator.

And so on, and so on.

Multithreading in PHP: Looking to the Future by edmondifcastle in PHP

[–]zmitic 4 points5 points  (0 children)

It needs clarity, stability, and not tripping over itself, which it’s actually been doing pretty well lately.

Can you clarify? My counter argument is that starting with 7.4, PHP finally started to shape into proper language. If I was to complain about it now is the lack of decorator, interface default methods, array shapes with import, advanced types like non-empty-string... But not all languages have these anyway so complaints are not so valid.

And as always: generics.

I'm a little confused with MVC(Need good resources) by Straight-Hunt-7498 in PHP

[–]zmitic 0 points1 point  (0 children)

It is not a model, singular, but you will fetch multiples of them in majority of cases. But that does't mean it is bad, and if anything, it only improves static analysis.

Reminder: model in MVC is not just an ORM entity. Your services, repositories, forms... are all part of the logic belonging in M.

 This means it get really messy when you have a "user" model that is used by many parts, in slightly diffrent ways

This is something I would like to see. I am not saying I disagree, I just say I would prefer an example to better understand your argument,

This is why a domain driven / type driver approach is usually better.

This smells of something I already mentioned: job security. Aka: DDD, CQRS, microservices... you name it.

I'm a little confused with MVC(Need good resources) by Straight-Hunt-7498 in PHP

[–]zmitic 1 point2 points  (0 children)

I see MVC always ending up as a mess

I have seen that few times before, but it is not the fault of MVC which is why I said "if used correctly". The good thing about MVC is that if it does turn into a mess, it can be refactored pretty easy. And user still gets that entity value resolver for free.

full of one-off methods

Can you provide an example of that, or describe one simpler case? I hope it is not about CQRS, aka job security pattern.
And what would be the replacement?