I think you're confused about how environments work.
The environment is an inheritable data space.
If you set an environment variable in a PHP process, the variable will be available to that process and its children.
But inheritance does not flow from child to parent. You can't set a variable in a PHP script and then have it available to a parent shell (or a shell that has no relationship).
This is not specific to PHP; it is how all environment variables are handled.