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:
But it doesn't in 8.2 (or 8.3).
And this:
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.10 Replies
you can try to use reflection to get access to the values
or just use
eval
That worked and I learned a new thing, thank you
you're welcome
it's overcomplicated, but, im assuming this is just to use once
This is ultimately what I ended up doing because I did end up using it twice, so I just made a function:
made things more readable
i might need to do that same thing elsewhere, i don't know yet, but for now it's living in the item class
hey, it's good that it works
i would assume it was a lot more complicated, but i only worked with reflection in 7.4
I've only ever glanced at it on php.net and didn't really understand what it was for or when I would need something like that, until now I guess lol
I also thought it would be a lot more complicated, I had to try a couple different enum related reflection classes until I found that one
lol i used it mostly to get information about functions that are public and private, and change from private to public to run those private functions
lol i never would've even thought to try something like that, i figured private meant that it belongs to the class and there's nothing you can do to use it somewhere else
that's good to know though
it was fun to use, not gonna lie
sounds that way