<?php
/**
* @param array<int> $values
* @return array<int, mixed>
*/
function get_random_keys(array $values, int $limit): array {
return $limit > 1 ? array_rand($values, $limit) : [array_rand($values)];
}
Another nice example baked into #PHP why having different return types for the same function is a really bad idea. It just results in way more effort to do things right everywhere this function is used.
27.10.2025 14:26
π 0
π 0
π¬ 0
π 0
$key = $reflectionProperty->isPrivate()
? "\0" . ltrim($class, '\\') . "\0" .$name
: (
$reflectionProperty->isProtected()
? "\0*\0" . $name
: $name
)
;
Would have written it something like this. Don't get why they made the parentheses mandatory though, in JavaScript I would have written it without them.
For some totally subjective reason I find switch(true) or match(true) weird π But it definitely is better than a nested ternary in a single line π
22.10.2025 10:47
π 0
π 0
π¬ 1
π 0
When they are spread over multiple lines and indented correctly they are find IMO.
22.10.2025 09:21
π 0
π 0
π¬ 1
π 0
Donβt be shy, start your own meetup!
You might think that starting your own meetup might be very hard. Let me tell you the story about the VlbgWebDev meetup, which might change your mind.
The other day I read a post about an organizer's experiences organizing a meetup. Since mine felt totally different, I thought it might make sense to write that down too. That's what I did in my blog post: danielrotter.at/2025/08/11/d...
#Meetup
01.09.2025 07:45
π 0
π 0
π¬ 0
π 0
Test creation methods on steroids with named parameters
Creation methods are a well-known pattern in testing. But they are even more powerful when used with named parameters.
Object creation in tests is tedious, especially when using the constructor, which might change and force you to update many tests.
Hence I like using creation methods to decouple tests from the constructor.
βοΈ I wrote a blog post for more details.
danielrotter.at/2025/06/29/t...
#Testing #PHP
07.07.2025 06:43
π 0
π 0
π¬ 0
π 0
I also like them to be as short and clear as possible. I don't like it when it feels like computers have a personality, I prefer them to be very blunt.
14.05.2025 06:14
π 1
π 0
π¬ 0
π 0
Batch curl requests in PHP using multi handles
Sending many requests in a PHP script might not be a straightforward task, especially if you want to do that in a performant manner.
Recently I had to send multiple #curl requests in a single #PHP script. Unfortunately the API was a bit confusing to me. Therefore I have written down how that worked, both for you and my future self
π danielrotter.at/2025/04/12/b...
16.04.2025 06:46
π 2
π 0
π¬ 0
π 0
Automatically generate changelogs with git
Generating changelogs is a rather tedious task for developers. But with a bit of discipline it becomes a one-line script.
π¬ Writing changelogs is probably not the favorite task of any developer. But instead of relying on another dependency, it's quite easy to create changelogs with command line tools.
βοΈ I have written a blog post showing how I handle this.
π danielrotter.at/2025/03/05/a...
#git #GitHub #vcs #unix
17.03.2025 07:05
π 0
π 0
π¬ 0
π 0
Using mastodon instead of bluesky would be a start π
03.03.2025 09:47
π 0
π 0
π¬ 0
π 0
Yeah, totally agree with that, that's also why I would use the AWS SDK, which handles signing the request. But I was specifically talking about elastica or elasticsearch-php, I am not aware of similar functionality in these libraries.
27.02.2025 07:10
π 0
π 0
π¬ 1
π 0
Getting started | Elasticsearch-PHP [8.17] | Elastic
Genuine question: When do you think it would be useful? I just checked the examples on www.elastic.co/guide/en/ela..., and I don't see anything that would warrant pulling in another dependency. The code shown there is not much simpler than using any HTTP client to send those requests.
26.02.2025 10:25
π 0
π 0
π¬ 1
π 0
I am also trying to avoid those SDKs as much as possible. That also includes stuff like elastica, since this is a very thin layer around the HTTP API. I don't see how these dependencies are helping, and it makes changing the actual dependency hiding behind the SDK even harder.
26.02.2025 08:38
π 1
π 0
π¬ 1
π 0
General AI nit: I'm uncomfortable with it being so agreeable, complementary, and optimistic. Sometimes I want it to be like, "I dunno about that, sounds like a bad idea, but ur the boss."
19.02.2025 03:55
π 3
π 2
π¬ 0
π 0
At least for me the problem is that many people set up something like this for every project, even if HTML+CSS (maybe with a few sprinkles of JavaScript) would have been more than good enough. And compared to that a framework is definitely complicated π
17.02.2025 10:50
π 3
π 0
π¬ 0
π 0
The problem with indirections
Indirections are invaluable for programming, since basically every programming concept makes use of one. However, we should still be careful when using them.
When developing software we use all kind of indirections. Most of the time way to early, causing code to be much more complex than the required.
βοΈ Since I ran into such situations, I decided to write them down in a blog post.
danielrotter.at/2025/02/05/t...
#Development #PHP #JavaScript #CSS
12.02.2025 12:49
π 2
π 0
π¬ 0
π 0
Just read an article claiming that users are not bothered by login screens being split into two forms (one for username and one for the password). Is it just me, or is that completely untrue? I find that pattern extremely annoying, especially when using password managers...
#UX #UI
11.02.2025 07:11
π 1
π 0
π¬ 1
π 0
And another thing I am a bit afraid of is that vim is installed on almost any server out there, so it would be nice not to lose the muscle memory of using vim...
15.01.2025 09:04
π 0
π 0
π¬ 1
π 0
I am a big proponent of using a .editorconfig file to ensure that the most basic code formatting is the same for everyone working on the same project. However, #helix does not support that yet: github.com/helix-editor...
15.01.2025 09:04
π 0
π 0
π¬ 1
π 0
Biggest issue for me is when using #helix with #phpactor auto completing variables always results in two dollar signs. I am going to write an issue about this the next days, since this is obviously a bug (not sure if in #helix or #phpactor though). But there are also other things missing.
15.01.2025 09:04
π 1
π 0
π¬ 1
π 0
Yesterday I've tried to use #helix instead of #Neovim yesteday for half a day, and even though I like quite some aspects of it (less configuration required, integrated file pickers including support git and buffers) I gave up at some point. π§΅
15.01.2025 09:04
π 2
π 0
π¬ 1
π 0
I mean I still see chatbots today, but most of the time it is just annoying that they are blocking some UI elements I would rather use π
10.01.2025 09:00
π 0
π 0
π¬ 0
π 0
That's probably the main reason why I also never understood the hype about chatbots a few years ago. For most tasks just having a boring form is still the most efficient way to handle something.
10.01.2025 08:59
π 0
π 0
π¬ 1
π 0
I've a feeling it's not working well with multiple languages⦠I'm a native German speaker, and configured it is as second content language, but both App and Primary Language as English. However, I still get lots of german politics in my discover feed, even though I click "Show less like this" a lot.
21.12.2024 14:18
π 0
π 0
π¬ 0
π 0
Is it just me, or is the "Show less like this" button in the discover #Bluesky feed not working at all? I am clicking it a lot, and I still see loads of similar messages. It's so bad that there is hardly anything I click "Show more like this" on...
16.12.2024 10:21
π 0
π 0
π¬ 0
π 0
TIL that there is a `:Rex` command in Neovim, which opens the netrw explorer and positions the cursor where it was before. That's a total game changer!
#Neovim #TIL
12.12.2024 13:24
π 2
π 0
π¬ 0
π 0
Honestly, the bad uses of useEffect, useState, and hard to debug re-renders working in the spaces I mentioned above, gave me a large amount of fatigue around React. Just dealing with a large, moving team falling on their face with too many renders in non-obvious ways. Ugh.
So yeah, good thread.
10.12.2024 21:12
π 14
π 1
π¬ 1
π 0