@zimzat@mastodon.social avatar

zimzat

@zimzat@mastodon.social

Software Architect (deprecated: use Staff Engineer), Casual Gamer ⌨️🖱️+🎮️, Sci-Fi & Fantasy 📚️🎥️

🏳️‍🌈️

This profile is from a federated server and may be incomplete. Browse more on the original instance.

doefom, to php
@doefom@mastodon.social avatar

After the last few things I've learned about 8.4 by accident I thought why not look into it and see what else there is. So, here's an example of the four new rounding modes PHP 8.4 will introduce to the 'round' function:

  • PHP_ROUND_CEILING
  • PHP_ROUND_FLOOR
  • PHP_ROUND_TOWARD_ZERO
  • PHP_ROUND_AWAY_FROM_ZERO

I rarely use anything else than 'ceil' and 'floor' in my daily work but this is still good to know.

What do you think?

zimzat,
@zimzat@mastodon.social avatar

@doefom Sounds useful at first glance but is more likely to encourage using floats inaccurately for decimal / monetary calculations. bcmath is also getting a new bcround and related methods which should be used instead, or one of the libraries specifically for decimal or money calculations.

oliver, to php
@oliver@phpc.social avatar

If you were about to start a medium-sized project, what would you choose as an , and why? It should be something stable and well maintained. If the business takes off, then there should be no need to replace that layer.

Caveat: imagine that Doctrine and Eloquent haven't been invented yet.

zimzat,
@zimzat@mastodon.social avatar

@oliver I'm with @Crell , I'd write my own. I don't like how opinionated Doctrine is and how it keeps projects beholden to yester-decade standards, nor the magic for loading foreign key objects from within another object. A few common helpers for things like findById. Some value objects for UUID primary keys, JSON, DateTimeImmutable, etc.

I'd effectively reinvent what I did at my last greenfield job.

Yeah, it won't come pre-built with a migration generator but that's a secondary concern.

nixCraft, to random
@nixCraft@mastodon.social avatar

this

zimzat,
@zimzat@mastodon.social avatar

@nixCraft Experience should mean recognizing ways of mitigating bugs before they happen. Writing good tests, for starters, which means learning how to write testable code.

Code that will bind, parameterize, or escape by default. Patterns that prevent invalid input. Avoiding a static global state. Consistent and predictable naming. Favoring explicit over implicit behavior.

Being able to predict a future bug before it happens.

It's not perfect, but it's not the Wild West either.

ramsey, to php
@ramsey@phpc.social avatar

A friend was telling me about guidelines for developing and deploying new services in their company, and one of the guidelines is “new services must not use .”

I’m not making this up, and this isn’t hyperbole. They actually have this listed on their company documentation.

zimzat,
@zimzat@mastodon.social avatar

@ramsey Yeah 😞 Companies do one thing, very poorly, in a language early on and then decide to throw out the entire stack instead of addressing the elephant in the room.

It's like the only way they can justify putting effort into something is if they can make the case it's not worth the effort necessary to fix it incrementally.

anubhav, to php

Could anyone suggest an for 7.2 & MariaDB 10 (Rocky Linux 8, Apache 2.4)? So far I have only used raw SQL in PHP.

I found <https://www.doctrine-project.org/projects.html>, <https://github.com/propelorm/Propel2/releases>, & <https://github.com/bcosca/fatfree> "F3". I have zero familiarity with all of those.

I noticed that Doctrine 3 documentation mentions 7.4 & latest stable versions of PHP, ALONG WITH "7.1+" <https://www.doctrine-project.org/projects/doctrine-orm/en/3.1/tutorials/getting-started.html#guide-assumptions>. What would I be missing with PHP 7.2?

zimzat,
@zimzat@mastodon.social avatar

@anubhav PHP 7.2 hasn't received any security updates in years. The general PHP community tends to drop support for versions no longer officially maintained so you won't find many maintained libraries supporting unsupported versions of the language.

https://www.php.net/supported-versions.php

Sometimes distribution maintainers will unofficially fix security problems, but still lagging far behind on new features the language supports, e.g. 8.1 introduced a ton of really nice features https://www.php.net/releases/8.1/en.php

zimzat,
@zimzat@mastodon.social avatar

@anubhav To directly answer your ORM question: it depends.

In my personal view, Doctrine is the least bad ORM out there but I'm still not exactly thrilled with it. It's a safe default.

Anything that is Active Record is to be Actively Avoided. It makes code brittle and hard to test.

I prefer to roll my own Repository and Query pattern. Or at least heavily customize the doctrine defaults first.

dantleech, (edited ) to php
@dantleech@fosstodon.org avatar

Blog post: things that annoy me in #PHP (but I still like it): https://www.dantleech.com/blog/2024/02/18/my-php-problems

zimzat,
@zimzat@mastodon.social avatar

@dantleech I really appreciate that this isn't a list of esoteric gotchas.

We really could use iterator_map/etc functions. The hard part will be convincing people whether to match callback vs iterable first parameter ordering 🙃 or if it should be lazy or immediate. I'd probably go with iterable first and lazy. They'd probably be shortcuts to creating FilterIterator/etc instances.

dseguy, to php French
@dseguy@phpc.social avatar

The #PHP code below produces a float, although it seems to produce an integer.

This is due to (int) having higher precedence than multiplication: it is applied to $c, without effect.

https://php-tips.readthedocs.io/en/latest/tips/cast_precedence.html

#phptip #phptrick

zimzat,
@zimzat@mastodon.social avatar

@dseguy This is why I think cast operators should not have a space after them.

echo (int)$c * 0.12345;

nixCraft, to random
@nixCraft@mastodon.social avatar

which one are you?

zimzat,
@zimzat@mastodon.social avatar

@nixCraft

Primary key: id
Foreign key: userId
Multiple foreign key: userIdAuthor userIdReader etc
Table name: User

I guess that makes me unaligned? ¯_(ツ)_/¯

nyamsprod, to php French
@nyamsprod@phpc.social avatar

#questionfotheday #php When getting an Iterator as returned by a function/method do you expect the Iterator to already be rewinded or not ? Asking because in #php this assumption is never guaranteed by any contract 🤔

zimzat,
@zimzat@mastodon.social avatar

@nyamsprod I generally avoid that consideration by using IteratorAggregate, which returns a new instance or fresh position context for each usage, instead of manually maintaining state. Beyond that I would agree with @ocramius ; "it just works".

zimzat,
@zimzat@mastodon.social avatar

@nyamsprod @ocramius How are you starting off in an unrewound state? From the user's perspective (based on the example in the issue) the csv hasn't been interacted with yet, so it should be in position 0 still.

If that's an internal implementation detail then perhaps switching out Iterator for IteratorAggregate would be a future change.

janriemer, to bevy

First baby steps with #bevy / #BevyEngine #UI :awesome:

This was way harder for me to implement than it might seem. I might write about it in the future... 🤞

#Graphics #Learning #Rust #RustLang

zimzat,
@zimzat@mastodon.social avatar

@janriemer Nice. 👍

Considering mouse drag is one of the next behaviors I need to implement for a game concept I have in mind, I realized how spoiled we are with libraries that do all the heavy lifting. Frame-by-frame state management, yup.

dseguy, (edited ) to php French
@dseguy@phpc.social avatar

I'm still struggling to pick a #PHP side.

@ is too slow, because it merely hides the error.

?? looks dumb: it reads : if it is null, use null as default.

the if() command is long to type.

#phptip #phptrick

zimzat,
@zimzat@mastodon.social avatar

@dseguy

The 'if' variant is more commonly done using a ternary.

$x = isset($foo) ? $foo : null;

This is what ?? is compared against as succinct.

And, added bonus, then there's a default when falsy:

$x = $unknown ?? null ?: 1;

Either way, it looks weird at first but you'll get used to it.

merms, to php
@merms@mastodon.social avatar

The string|int in array keys is killing me again these days. It leads to so many corner-cases a.k.a. bugs waiting to happen.

I know exactly how it works, but, in many places, there is so much effort involved in coding around this.

Here’s what I recently added as a test to our Symfony JSON API using JMS Serializer:

https://3v4l.org/1A2hc

How do you deal with it?

#php

zimzat,
@zimzat@mastodon.social avatar

@merms I'm not sure I understand the specific problem (haven't looked at the serializer test linked), but as long as the first key isn't 0 or they're not contiguous then it works like you seem to want. If it literally looks and acts like a list array, but you want it to serialize and unserialize as an object, then the input must also be an object. (object)['0' =&gt; 'foo']

Crell, (edited ) to php
@Crell@phpc.social avatar

I'm noodling with a data storage layer library in #PHP. #Postgresql specific. There's 2 options:

  1. Auto-generate SQL tables/views/queries off of PHP data types (with attributes)
  2. Auto-generate PHP classes off of SQL tables/views/queries.

Which would you prefer? The goal is fully typed interaction in PHP space, but I'm not sure which side should be canonical.

Which would you rather work with, and why? Assuming a "good" DX in either case.

Answer why in replies, boost for reach, etc.

zimzat,
@zimzat@mastodon.social avatar

@Crell Why do you say it's not an ORM? What is the problem space this is solving for if not that?

I strongly prefer to write SQL because PHP code is rarely expressive enough to handle all the cases that SQL does, at least not without marrying the library to a specific validation implementation or doubling the amount of code or config necessary to get equivalent functionality. That also means my models are "anemic", but then I consider that a benefit.

zimzat,
@zimzat@mastodon.social avatar

@Crell Ahh, yeah; my models are 1-to-1 data-wise.

I made a model library that was SQL-canonical but it was very opinionated: the name of the field determined its type (e.g. isXyz/hasXyz/etc = bool, dateCreated = DateTimeImmutable) and it autogenerated the phpdoc @ method bloc for every field fallback (getX, setX, putX) if custom logic wasn't needed, tables = Pascal, fields = camelCase, etc.

Internally it was stored as an array but it validated or massaged the types on set / load.

zimzat,
@zimzat@mastodon.social avatar

@Crell I also made a Query Builder library that is both expressive and parameterize-by-default: https://github.com/zimzat/query-builder-mysql#select

The main thing I find missing in the space is handling migrations. Most approaches are very naive about pre- or post-migration expectations (an extra field is found, an expected field is missing, etc), or don't take into account whether it would bring down production while the migration is running.

michael, to php
@michael@thms.uk avatar

Huh. Just had a look at sleep functions in PHP, and came across this nugget in the docs for time_nanosleep().

What sort of absolute mess is this?! Can time_nanosleep() seriously return a boolean or an array?!

And then thye wonder why PHP has a bad reputation.

(Before you tell me that PHP is best, or whatever: I agree. I like PHP. But this still seems like a terrible implementation.)

#PHP

zimzat,
@zimzat@mastodon.social avatar

@michael https://www.man7.org/linux/man-pages/man2/nanosleep.2.html

> If the call is interrupted by a signal handler, nanosleep() returns -1, sets errno to EINTR, and [...]

Anywhere you see something returning false it's likely because the underlying function it wraps returns -1 back in the day.

hightechredneck, (edited ) to random
@hightechredneck@phpc.social avatar

I need to print out this quote from the morning keynote by @funkatron and put it in every room of my house. Maybe if I saw it everywhere, I would stop being so mean to myself.

zimzat,
@zimzat@mastodon.social avatar

@hightechredneck @funkatron This reminds me of https://mastodon.social/@BethanyBlack/111187235934938921

"If you were actually lazy, you’d be enjoying it. You’d be having fun."

Not quite the same vein but it hits a similar response note.

awoodsnet, to linux
@awoodsnet@phpc.social avatar

What’s your favorite Linux Distro? and favorite Desktop Environment?

#Linux #PHP #SoftwareDevelopment

zimzat,
@zimzat@mastodon.social avatar

@awoodsnet

MATE, via Linux Mint.

I'm not particularly attached to Linux Mint but it was the only way to get MATE as a desktop manager for a while.

I used to use KDE until they came out with Plasma that bloated the padding on everything, switched to Gnome until they came out with Gnome 3 that bloated the padding on everything (plus changed the core desktop), then switched to MATE.

zimzat,
@zimzat@mastodon.social avatar

@awoodsnet It's a fork of Gnome 2; both young and old. It is now supported by a dozen or so other distributions and a separate Ubuntu MATE flavor. ¯_(ツ)_/¯

dseguy, to php French
@dseguy@phpc.social avatar

I know there is no such a function as empty(), as it is a language construct.

#PHP 8.0 brought an improvement to this, as this is now a Fatal Error, rather than a Parse Error.

But, that aside, come on...

#phptip #phptrick

https://3v4l.org/ML6cX

zimzat,
@zimzat@mastodon.social avatar

@askonomm @dseguy

Micro Optimizations: https://tideways.com/profiler/blog/compiler-optimized-php-functions

There was a big repeat loop of articles like this one a month or so ago. (basically blogger A sees it mentioned by blogger B on reddit so they go write the same thing and then post it to Mastodon, blogger C sees it then blogs about it and posts it to Twitter, repeat until Reddit deletes the link for Blogger R as "Repost" then gets called caustic for not being welcoming ¯_(ツ)_/¯)

zimzat,
@zimzat@mastodon.social avatar

@askonomm @dseguy

PHP is (in?)famous for the string " vs ' micro optimization. That reason no longer applies but we still use ' by default. It is the better default for most other reasons.

Tabs vs Spaces. Align vs Wrap vs Chop. Namespace prefix. Private vs Protected vs Public. The list goes on.

There are answers, better answers, and right answers, but since programming lacks empirical research everyone thinks their opinion is right by default & the bombastic endures.

https://blog.glowforge.com/strong-opinions-loosely-held-might-be-the-worst-idea-in-tech/

augieray, (edited ) to random
@augieray@mastodon.social avatar

It's frustrating to be "the #COVID19 guy" when everyone should be COVID-aware. I had a friend ask if we could get together for the holidays on December 16. I said sure, if they could be safe for the week beforehand and wouldn't mind socializing at our home. He declined. 😢

This is not the life I expected in my 60s. I expected concerts, professional public speaking, and fun events. But I refuse to risk my life or the lives of people I love. I'll make the best of what this world sensibly allows.

zimzat,
@zimzat@mastodon.social avatar

@augieray If you don't mind the question, what does it mean to "be safe for the week beforehand"? I ask because I'm curious if it differs from my own regular behavior or if there is something more I should be doing before meeting up with anyone. My standard practice is N95 masking in crowds or indoors. I haven't done much 1-on-1 socializing lately so not sure where to draw the line. Does it include some form of quarantine before, or masking up while socializing in your home, or ...? Thanks!

zimzat,
@zimzat@mastodon.social avatar

@augieray Thanks for the details; that's very helpful to compare notes.

I wear a mask when going to a outdoor Farmer's Market, for instance. It's not a large crowd (e.g. Concert) but there's frequent closer interactions.

This seems like a reasonable request. I can see how some folks may feel like it's insinuating they're not normally being safe or it's a inconvenience, but... 🤷️ At least they said no instead of lying.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • JUstTest
  • InstantRegret
  • magazineikmin
  • modclub
  • Durango
  • Youngstown
  • rosin
  • khanakhh
  • slotface
  • ngwrru68w68
  • mdbf
  • thenastyranch
  • kavyap
  • DreamBathrooms
  • megavids
  • tester
  • everett
  • normalnudes
  • GTA5RPClips
  • osvaldo12
  • ethstaker
  • cisconetworking
  • tacticalgear
  • anitta
  • provamag3
  • cubers
  • Leos
  • lostlight
  • All magazines