Kevin Powell - CommunityKP-C
Kevin Powell - Communityโ€ข6mo agoโ€ข
16 replies
Ray

PHP Syntax Issue.

I wrote a script while running PHP 8.4. The server this is going to run on is using 8.2. I can't change it, it's not my website.

There is, apparently, a syntax difference between 8.4 and 8.2 when it comes to dynamically filling in both which Enum type and which case of that Enum it is I'm wanting to use, and now chunks of what I wrote no longer work. I didn't realize this would happen at the time.

All of that to say, this works in 8.4:
$tierlevel::{$itemname}->getBenefits(); 
// this could be: Items\Enums\Tier0::Copycat->getBenefits();
// or it could be some other Tier/Item combo

But it doesn't in 8.2 (or 8.3).

And this:
$test = constant($tierlevel::class . "::$itemname");

did not fix it, it just gave me a different fatal error.

The original error:
Fatal error: Uncaught Error: Access to undeclared static property Items\Enums\Tier0::$itemname
is not helpful because it's not a static property in the first place, it's an Enum case. The interpreter is misinterpreting.

Anybody know what I'm meant to do here? Or am I just SOL? I do have an alternative in mind that'll probably work, but I'd prefer doing this to that if I can.

Thanks.
Was this page helpful?