Une expression Match arrive dans PHP 8
(laravel-news.com)<p>// Avant<br />
switch ($this->lexer->lookahead['type']) {<br />
case Lexer::T_SELECT:<br />
$statement = $this->SelectStatement();<br />
break;<br />
<br />
case Lexer::T_UPDATE:<br />
$statement = $this->UpdateStatement();<br />
break;<br />
<br />
case Lexer::T_DELETE:<br />
$statement = $this->DeleteStatement();<br />
break;<br />
<br />
default:<br />
$this->syntaxError('SELECT, UPDATE or DELETE');<br />
break;<br />
}<br />
<br />
// Après<br />
$statement = match ($this->lexer->lookahead['type']) {<br />
Lexer::T_SELECT => $this->SelectStatement(),<br />
Lexer::T_UPDATE => $this->UpdateStatement(),<br />
Lexer::T_DELETE => $this->DeleteStatement(),<br />
default => $this->syntaxError('SELECT, UPDATE or DELETE'),<br />
};</p>
3 commentaires