However this way a car parking can only allow one type of vehicles to use the parking. If you want to enable the parking to allow more types of vehicles you’ll have to use boolean properties, one for each type, on the parking:

Adding a new vehicle type would imply significant modification to the code: you need to extend the Parking class for each type you want to add and everywhere you check or set the types on a parking object you’ll need to modify the code to take these booleans into account. Flags offer a rather simple solution to this problem:

Internally $parking doesn’t have single boolean properties, but it specifies a single integer which holds all the properties. Notice how this definition of VehicleTypes differs from the first time VehicleTypes was defined. It now extends Flags instead of Enum and instead of incrementing each value by 1 each value is incremented by a power of 2.

The flags VehicleTypes now has the internal value 17 (1 = Sedan, 16 = Bike). Bitwise 17 is represented as 10001. So instead of defining five separate booleans for each type, a bitwise representation for all types is used in an integer.

As you can print values of an Enum type, Flags can be printed too. Using the $parking from the last example, when echoing $parking as done below it results in the following output: