Die Typumwandlung könnte scheitern, wenn wirklich NULL im Datenfeld steht. Da er modernes PHP einsetzt,
Hm. Ich wohl auch. Ich hatte das wie folgt getestet:
<?php
error_reporting( E_ALL );
print phpversion() . "\n";
$row['bewertung'] = null;
print "„" . htmlentities( (string)$row['bewertung'], ENT_QUOTES ) .'“' . PHP_EOL;
print "Meldung erwartet: „" . htmlentities( $row['bewertung'], ENT_QUOTES ) .'“' . PHP_EOL;
Ausgaben:
$ php /tmp/test.php
8.4.27
„“
PHP Deprecated: htmlentities(): Passing null to parameter #1 ($string) of type string is deprecated in /tmp/test.php on line 7
Meldung erwartet: „“
auf der anderen Maschine:
$ php /tmp/test.php
8.5.12
„“
PHP Deprecated: htmlentities(): Passing null to parameter #1 ($string) of type string is deprecated in /tmp/test.php on line 7
Meldung erwartet: „“
Die erzwungene Typumwandlung funktioniert also. An der von Dir erwähnten Stelle steht:
The expression (expr1) ?? (expr2) evaluates to expr2 if expr1 is null, and expr1 otherwise.
„In particular, this operator does not emit a notice or warning if the left-hand side value does not exist, just like isset(). This is especially useful on array keys.“
Das würde also dann eine Fehlermeldung unterdrücken, wenn $row['bewertung'] nicht besetzt (false === isset( $row['bewertung'] ) ) wäre - was vorliegend nicht der Fall und gerade nicht gefordert ist: Deine Lösung tut also zu viel.