3 คะแนน โดย smartbosslee 2020-07-16 | 3 ความคิดเห็น | แชร์ทาง WhatsApp

// Before

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 or DELETE');

    break;

}

// After

$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 or DELETE'),

};

3 ความคิดเห็น

 
kunggom 2020-07-17

ใน Java เองก็มีคำสั่ง Switch ที่พัฒนาความสามารถมากขึ้นถูกเพิ่มเข้ามาในเวอร์ชันใหม่เช่นกัน ดูเหมือนว่านี่จะเป็นเทรนด์ในช่วงนี้นะครับ

https://th.news.hada.io/topic?id=1130

 
xguru 2020-07-16

ฟีเจอร์ใหม่ของ PHP 8 https://th.news.hada.io/topic?id=1438

ตอนโพสต์ข่าวนี้เหมือนจะยังไม่มี แต่ในต้นฉบับของบทความฝั่งนี้ก็อัปเดตล่าสุดและเพิ่ม Match เข้าไปแล้วครับ

 
smartbosslee 2020-07-16

ครับ มีการยืนยันแน่ชัดแล้วว่าจะเพิ่มเข้ามา แต่ดูเหมือนว่า Match เองก็ยังมีโอกาสที่จะถูกเปลี่ยนแปลงเพิ่มเติมได้อยู่ครับ

ขอบคุณสำหรับลิงก์ครับ