The Allergies PHP exercise can't find the Allergies class (online editor)

This is what I’ve got in the online editor:

<?php

declare(strict_types=1);

class Allergies
{
    const ALLERGEN_LIST = [ Allergen::EGGS,
                            Allergen::PEANUTS,
                            Allergen::SHELLFISH,
                            Allergen::STRAWBERRIES,
                            Allergen::TOMATOES,
                            Allergen::CHOCOLATE,
                            Allergen::POLLEN
                            Allergen::CATS ];
    
    private $allergens = [];
    
    public function __construct(int $score)
    {
        echo "\n---- Constructing an Allergies class ----\n";
        
        $scores = array_reverse( str_split( decbin($score) ) );
        foreach ( $scores as $index => $this_score ) {
            if ( $this_score > 0 && $index < 8 ) {
                $this->allergens[] = self::ALLERGEN_LIST[$index];
            }
        }
    }

    public function isAllergicTo(Allergen $allergen): bool
    {
        return false;
    }

    public function getList(): array
    {
        return $this->allergens;
    }
}

class Allergen
{
    const EGGS = 1;
    const PEANUTS = 2;
    const SHELLFISH = 4;
    const STRAWBERRIES = 8;
    const TOMATOES = 16;
    const CHOCOLATE = 32;
    const POLLEN = 64;
    const CATS = 128;
    
    public static function allergenList(): array
    {
        return [ self::EGGS,
                 self::PEANUTS,
                 self::SHELLFISH,
                 self::STRAWBERRIES,
                 self::TOMATOES,
                 self::CHOCOLATE,
                 self::POLLEN,
                 self::CATS ];
    }
}

When I run the tests, I get the same result for every test:

AllergiesTest::testAllergicToEggsInAdditionToOtherStuff
Error: Class "Allergies" not found

/mnt/exercism-iteration/AllergiesTest.php:83
                            Allergen::CHOCOLATE,
                            Allergen::POLLEN
                            Allergen::CATS ];

Looks like you’re missing a , after POLLEN, which I imagine means it can’t parse the code.

1 Like

Yep, that was it. Damn commas. Thanks!

1 Like

No problem. It’s a shame PHP doesn’t give a clearer error message!