Doeke Norg

5.1K posts

Doeke Norg banner
Doeke Norg

Doeke Norg

@doekenorg

PHP Architect, spouse to @Renatenorg and father of 3. Follow me for more on vanilla PHP and useful patterns.

Vries, The Netherlands Katılım Mart 2009
130 Takip Edilen840 Takipçiler
Doeke Norg
Doeke Norg@doekenorg·
Without looking it up... What is the result here? *Spoiler, it is _not_ 2024-12-31*
Doeke Norg tweet media
English
2
0
4
345
Nick e/code
Nick e/code@nicksdot·
PHP `str_remove($​search, $​subject)` when?
English
1
0
1
67
Doeke Norg
Doeke Norg@doekenorg·
@nicksdot @sandersjj That might be thought of as premature optimization, but I don't actually build that; I only allow for that, just in case. It doesn't require a new major or updates on the user's end.
English
1
0
1
29
Doeke Norg
Doeke Norg@doekenorg·
@nicksdot @sandersjj It isn't always bad, but it is part of the public API for the code. When it comes to your own code, that's obviously fine, but when working with packages, you can't easily rename that variable or change the logic for that path to be overwritten with an event or a different base.
English
1
0
1
33
Jigal Sanders
Jigal Sanders@sandersjj·
#laravel tip. I used this in a Filament action. Soo much cleaner 🔥🔥🔥
Jigal Sanders tweet media
English
6
1
40
4.9K
Doeke Norg
Doeke Norg@doekenorg·
@nicksdot @sandersjj Also, no more encapsulation. When readonly was intoduced, everyone just started exposing internals, making changes more difficult. Whats wrong with adding a semantic method?! 😐
English
1
0
0
32
Nick e/code
Nick e/code@nicksdot·
@sandersjj No more automatic refactoring. Changing to stringy apis is never a good idea.
English
1
0
4
315
Nick e/code
Nick e/code@nicksdot·
Touched stones and grass today. 🥰
Nick e/code tweet mediaNick e/code tweet media
English
1
0
2
67
Nick e/code
Nick e/code@nicksdot·
BREAKING: only the size of the database and me being fast enough to k*ll the `mysqldump` process rescued me from piping dev to production instead of production to dev. gm!
English
1
0
4
97
Doeke Norg
Doeke Norg@doekenorg·
@agustingomes When they are available to me; I might as well. But I also like to "hide" away the parameters so I can change implementation details without changing the API. This is why I like accessor methods instead. I guess that you can use property hooks, but I don't see an advantage there.
English
0
0
0
23
Agustin Gomes
Agustin Gomes@agustingomes·
@doekenorg Nowadays with the property accessors I just tend to do a readonly class instead. There may be cases in which private constructor still better, though
English
1
0
1
32
Doeke Norg
Doeke Norg@doekenorg·
Quick PHP Tip💡 If your class is meant to be immutable, don't use a public constructor; you can call it like any other public method. Use a private constructor with a static named constructor instead.
Doeke Norg tweet media
English
7
0
10
585
Doeke Norg
Doeke Norg@doekenorg·
@Hundinnenstein It's not great, but I'll admit to having abused this at least once or twice in my career, when I don't own the code. You gotta do what you gotta do to make shit work.
English
0
0
1
42
Иван Котофеевич
Иван Котофеевич@Hundinnenstein·
@doekenorg Wow! This is a whole new level of shitcoding I couldn't even imagine. I would like to see somebody who would call a constructor method like this.
English
2
0
1
59
Israel Viana
Israel Viana@_israel_viana_·
@doekenorg IMO, immutability is great for keeping state consistent. But addding a static named constructor for every class just to prevent using __construct() on an existing object shows a bit of lack of trust in your fellow programmers 🤔 ? (readonly params/classes are the best solution)
English
1
0
2
59
Tijmen Wierenga
Tijmen Wierenga@TijmenWierenga·
@doekenorg Using the readonly keyword you can protect against this. Might be a nice addition to your post :).
English
1
0
1
46
Doeke Norg
Doeke Norg@doekenorg·
Here is one that *is* immutable. Alternatively, you can also use `readonly` parameters (8.1) or classes (8.2).
Doeke Norg tweet media
English
0
0
4
291