Why I don't like/use PHP's empty() function


PHP has a function called empty() which can only return a boolean value, which is good at this point. The purpose of the function is to check if a variable "is empty" ...

You can check out it's documentation or try this example to see what is all considered as "empty".

<?php
echo 'empty(true):'       . (empty(true)       ? 'true': 'false') . PHP_EOL;
echo 'empty(false):'      . (empty(false)      ? 'true': 'false') . PHP_EOL;
echo 'empty(0):'          . (empty(0)          ? 'true': 'false') . PHP_EOL;
echo 'empty((float)0.0):' . (empty((float)0.0) ? 'true': 'false') . PHP_EOL;
echo 'empty(null):'       . (empty(null)       ? 'true': 'false') . PHP_EOL;
echo 'empty():'           . (empty('')         ? 'true': 'false') . PHP_EOL;
echo 'empty("foo"):'      . (empty('foo')      ? 'true': 'false') . PHP_EOL;
echo 'empty(object):'     . (empty(new stdclass()) ? 'true': 'false') . PHP_EOL;

With 7.4.21 I'm getting this result:
empty(true):false
empty(false):true
empty(0):true
empty((float)0.0):true
empty(null):true
empty():true
empty("foo"):false
empty(object):false

And hopefully with other versions of #PHP you get the same result. But if not, then there is the problem. Users can have a variety of versions installed, even those being marked as End-Of-Life (which as a software developer you should never support, get your system updated, lazy arse!!!).

So do you want ...
1) Your coder relies on a PHP function that has a change of behavior (other returned result than before updating PHP)?
2) Don't/Can't update PHP and get stuck with a EOL version?
3) Or maybe rewrite it in a way that when an incompatible update happens you only have to change a little bit?

Sure empty() is maybe not changing so fast in the near future, but who knows? Surely you and me don't have a magic orb at home where you can see it coming ... LOL

For the last option, I had introduced DBA::isResult() which does this exactly for you. It keeps your code easily upgradeable because you might only have to change that method (if properly used everywhere). But there is a drawback in Friendica's code:

- If a boolean is present in $array (mixed type parameter of it), it simply returns it (even when it is true, so your code "thinks" that the record is found ...
- On successful retrieval of the record either an object or array can be present in $array. So they both need to be checked individually.

What I found troubling (confusing) here is that why so many different types can be returned from the DAL (the class Database/Database|DBA is some kind of DAL) and not always a single result class, e.g. QueryResult which contains the whole result, how many records have been found or being affected and so on.

This is a WAY much cleaner approach and you are more object-oriented and not lesser. If it was me, I would rewrite the entire code of #Friendica around this issue towards that class.

And if it was me, I would make sure that (no matter how important the table is) method invocations are correct, means e.g. no null for an id column or valid id number (you can always call DBA::exists() before!). And if this causes to much redundant queries, you can always cache the result and just return the cache instead.

Sure this increases memory footprint, that's the deal you have to make: More cache or more SQL queries.

Von Solidarität faseln aber dann keine echte zeigen?


Ich habe mir gerade das aktuelle Video von #DashcamDriversGermany angesehen und bin geschockt - auch was ich manchmal in den Konnentaren lesen darf, wie viele nicht anhalten, selbst wenn sie einen #Unfall direkt vor dem Fahrzeug haben.

Von #Solidarität kann man viel faseln, wenn es um Randgruppen geht, gerade dann ganz besonders viel. Wenn aber Unfaelle sich direkt vor der eigenen Motorhaube abspielen, weiterfahren ....

Zu Kotzen:
invidio.us/watch?v=xKZtMwFb3yA

Beim Unfall keinen Solidarität aber das letzte Hemd der Ukraine spenden und sich toll finden... Peinlich solche Menschen!
ganz ehrlich wenn da 10 helfer vor Ort sind muss man da nicht als 11. auch noch mit wurschteln🙄 man kann es auch echt maßlos übertreiben


Ja? Haben dort 10 bereits gestanden? Nein, Fehlanzeige. Sagt einer was davon, dass ein 11ter anhalten soll? Nein, auch Fehlanzeige. Die Menschheit ist so arm dran!

Wie sich Umweltaktivisten laecherlich machen


Beim Sascha #Fahrnünftig 's "Eure Videos" Nr. 152 sieht man ab 02:14 wie sich Umweltaktivisten laecherlich machen: Lassen sich von der Bruecker herab, um gegen #VW zu demonstrieren, das bei Kaelte, wo alle wartenden hunderten von Autos den Motor laufen lassen, damit sie nicht erfrieren muessen ...

invidio.us/watch?v=8w5ZZANCREU



Firefox führt vollständigen Cookie-Schutz als Standard für alle Nutzer*innen weltweit ein – Mozilla Presse-Center


Das kann mir gut gefallen #firefox #cockie #secuity

Jedes Mal, wenn eine Website – oder ein in eine Website eingebetteter Inhalt eines Drittanbieters – ein Cookie in deinem Browser hinterlegt, wird dieses Cookie auf die Cookie-Sammelstelle beschränkt, die nur dieser Website zugewiesen ist. Keine andere Website kann also in die Keks-Dose greifen, die nicht zu ihr gehört – und ergo nicht herausfinden, was die Cookies der anderen Websites über dich wissen. Das befreit dich von invasiven Anzeigen und verringert die Menge an Informationen, die Unternehmen über dich sammeln.


Firefox führt vollständigen Cookie-Schutz als Standard für alle Nutzer*innen weltweit ein – Mozilla Presse-Center