Metoniem
Metoniem

Reputation: 249

Nullable string type hinting gives syntax error in PHP 7.2

I'm using PHP 7.2 and trying to type hint this variable:

class TestClass
{
    public static ?string $test = null;

But PHP gives me the following error:

syntax error, unexpected '?', expecting function (T_FUNCTION) or const (T_CONST)

And I'm absolutely clueless why! Am I doing something wrong?

Upvotes: 0

Views: 787

Answers (1)

El_Vanja
El_Vanja

Reputation: 3983

Typed properties were not included until PHP 7.4.

Upvotes: 5

Related Questions