有没有办法保护$ _SERVER全局不被修改?

I would like to prevent php scripts from being able to modify the contents of the $_SERVER global.

Specifically I don't want to allow

unset $_SERVER['foo'];

but it would be nice to forbid any modification, e.g. a module or php.ini declaration.

Is there one?

If you're in control of the root level script you could just copy it:

$_my_server = $_SERVER;

I think it would be helpful to know your reason for this; the $_SERVER variable shouldn't be modified by included scripts, because there's rarely a reason for someone to need to modify it. It's generated at run-time so any changes aren't persisted to subsequent runs of the script.

Also your extra point about php.ini declarations is a bit more confusing - the point of many componentes of $_SERVER is to inform scripts about those declarations, so having it send fake data would seem a very odd use case and maybe not possible.

Not as far as i'm aware. If you are relying on the contents of $_SERVER throughout you code, and dont want other code (plugin?) to modify it, your best option is to make a copy during the bootstrap stage of your application, then use that copy throughout your code:

$serverDetails = $_SERVER;

$foo = $serverDetails['foo'];