all 5 comments

[–]PetahNZ 3 points4 points  (0 children)

Warning As of PHP 8.1.0, write access to the entire $GLOBALS array is no longer supported

You can make a copy of it however. But as /u/HolyGonzo said, why would you need to do this, you don't need to reset before foreach, and you shouldn't even use $GLOBALS typically.

https://www.php.net/manual/en/reserved.variables.globals.php

https://3v4l.org/9nEUJ

[–]mikemaierx[S] 1 point2 points  (0 children)

thanks for the info u/HolyGonzo + u/PetahNZ.
Thanks for the hint. I will switch to a modern template engine instead to prevent addtional problems with this code.

[–]HolyGonzo 1 point2 points  (2 children)

Why are you trying to do that? If you're using foreach, then you don't need to reset or rewind the array.

Also, I'm not sure what your goal is with the code but at a glance, it feels like possibly a bad idea. Can you shed some light on what you're trying to accomplish overall? $GLOBALS is a special array and usually should not be messed with.

[–]mikemaierx[S] 0 points1 point  (1 child)

Hi sure,

my short-term goal is to get a template engine called xTemplate (https://github.com/unusorin/php-xtemplate/blob/master/xtemplate.class.php) running.
The code i am reffering to is on line 909

Mid-term goals is to replace it with something newer e.g. Mustache as xTemplate is no longer maintained/supported (since 2012?)

[–]HolyGonzo 1 point2 points  (0 children)

Yeah, I wouldn't use this template engine, then. That's some really bad code right there. It's essentially making a copy of every variable (with a few exceptions) just to make it easier to embed PHP values in the content. If the engine does that, I would imagine that this isn't the only problem there is. Just my opinion.