PHP 8 erhält den Match-Ausdruck
(laravel-news.com)// Vorher
switch ($this->lexer->lookahead['type']) {
case Lexer::T_SELECT:
$statement = $this->SelectStatement();
break;
case Lexer::T_UPDATE:
$statement = $this->UpdateStatement();
break;
case Lexer::T_DELETE:
$statement = $this->DeleteStatement();
break;
default:
$this->syntaxError('SELECT, UPDATE oder DELETE');
break;
}
// Nachher
$statement = match ($this->lexer->lookahead['type']) {
Lexer::T_SELECT => $this->SelectStatement(),
Lexer::T_UPDATE => $this->UpdateStatement(),
Lexer::T_DELETE => $this->DeleteStatement(),
default => $this->syntaxError('SELECT, UPDATE oder DELETE'),
};
3 Kommentare
Auch in Java wurde in den neuesten Versionen eine funktional verbesserte
switch-Anweisung eingeführt. Scheint wohl gerade der Trend zu sein.https://de.news.hada.io/topic?id=1130
Neue Funktionen in PHP 8 https://de.news.hada.io/topic?id=1438
Als ich diese News damals gepostet habe, war das wohl noch nicht enthalten, aber im Original dieses Artikels wurde es inzwischen aktualisiert und
matchwurde hinzugefügt.Ja. Dass es hinzugefügt wird, steht fest, aber offenbar gibt es auch bei
matchselbst noch Spielraum für weitere Änderungen.Danke für den Link.