Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Enumeration’s Cases Comparisons

By Frederic Bouchery

<?php

enum A: string
{
    case Foo = 'bar';
}

enum B: string
{
    case Foo = 'bar';
}

echo A::Foo === B::Foo ? 'Yes' : 'No';

Enumeration cases are different when the enumeration are different, not when the value of the case is different. It is a difference with using constants for enumerations.

To compare their value, the comparison must be done with the ‘value’ property, not the object.

See Also

PHP Features

Last updated: 09 November 2026