新版本的变更 / PHP 8.1

// *** before: ***
class Suit {
    const HEARTS = 'hearts';
    const SPADES = 'spades';
    const CLUBS = 'clubs';
    const DIAMONDS = 'diamonds';
    // nothing stops passing an arbitrary string instead of a valid suit
}

function play(string $suit) { /* ... */ }
play('bananas'); // accepted, even though it makes no sense

// *** in version 8.1: ***
enum Suit {
    case Hearts;
    case Spades;
    case Clubs;
    case Diamonds;
}

function play(Suit $suit) { /* ... */ }
play(Suit::Hearts);
// play('bananas'); // TypeError: must be of type Suit, string given