Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Wow, someone really wanted to avoid writing a generic path-based getter for arrays.
-
function getMenuPath(array $menu, int ...$indexPath) {
$reduce = function(array $elements, $idx) {
return $elements[$idx] ?? null;
};
return array_reduce($indexPath, $reduce, $menu);
}
Splat Operator for variadic args with strict type hinting, should be array.
array reduce approach explained e.g. here : https://baohx2000.medium.com/reachi...
Just a bit neater without array_key_exist.
You could make the variadic arg a string of course.qk
By the way: I'm drunk, 10 hours of work and my brain is shrooms shrooms.
Might be wrong. I dunno. -
@IntrusionCM Nah, it'll be fine! Gonna use your code in Prod tomorrow!
kthxbye โค๏ธ
In all seriousness though, the array_reduce is a great idea, but I have actual anxiety to refactor this method for now... There are about 150k LOC more of such utter shit. The thing is beyond saving. For now my job is just to fix the bugs that appear, until I replace the whole thing in summer with a new software using mircoservices. -
@PonySlaystation
Yeah. Variadic args are imho a nicer approach.
getMenuPath($menu, 1, $menu['path'][0], $menu['path'][1])
as an example.
Of course you can push to production.
See the image.xD
Regarding microservices: Again, see the image. ๐คฃ๐คฃ๐คฃ -
@IntrusionCM Thank you so mucg! This image fits perfectly in my current situation...
-
C0D4669023y@IntrusionCM this hits home right now.
3rd party vendor gave incorrect documentation and now I don't know whether to cry or laugh at this insanity of fixing their shit. -
The fuck is the point in using a null coalesce with a null as the second argument? ๐คจ
-
@kwilliams The null-coalescing operator is there to catch non-existing array index access. Without this operator, an error would be thrown.
-
@C0D4 Yeah... I installed and configured 5 proxmox nodes, 22 VMs, and had a few meetings...
Meetings were like: Why is this darker shade of green it needs to be less darker shade of green?
Why is the number there different from the number here (one order - one from a shop, the other from the booking system that interacts with the shop...)
Why does this not work?
- me having a look -
Never mind, restarted everything. Do you know why it didn:t work?
- yeah... When you restart things I can look back in the past and find out what happened, of course. Naarf.
Yesterday was the epitome of "If I stop laughing, I'll drive a shotgun up my arse to feel alive again". -
hjk10156963yI'm more surprised by the PHP 7+ ??
You just don't expect someone to be aware of such code shortening operators at that line count and left hand... -
hjk10156963y@IntrusionCM
I would expect the original style ternary here
isset($menu [1]...) ? $menu [1]... : null;
Instead of the null coalescing ternary that specifically deduplicates the item you are testing for existence.
In code like that you just don't expect any kind of efficiency
Related Rants
[CMS of Doom™]
Ah yes, when you find a beautifully written array access at line 3187... ๐๐๐
rant
php
phptsd
cmsofdoom