test-env.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. require_once __DIR__.'/_executor.php';
  3. return function() {
  4. $var = 'MY_VAR_' . ($_GET['var'] ?? '');
  5. // Setting an environment variable
  6. $result = putenv("$var=HelloWorld");
  7. if ($result) {
  8. echo "Set MY_VAR successfully.\n";
  9. echo "MY_VAR = " . getenv($var) . "\n";
  10. } else {
  11. echo "Failed to set MY_VAR.\n";
  12. }
  13. // Unsetting the environment variable
  14. $result = putenv($var);
  15. if ($result) {
  16. echo "Unset MY_VAR successfully.\n";
  17. $value = getenv($var);
  18. if ($value === false) {
  19. echo "MY_VAR is unset.\n";
  20. } else {
  21. echo "MY_VAR = " . $value . "\n";
  22. }
  23. } else {
  24. echo "Failed to unset MY_VAR.\n";
  25. }
  26. $result = putenv("$var=");
  27. if ($result) {
  28. echo "MY_VAR set to empty successfully.\n";
  29. $value = getenv($var);
  30. if ($value === false) {
  31. echo "MY_VAR is unset.\n";
  32. } else {
  33. echo "MY_VAR = " . $value . "\n";
  34. }
  35. } else {
  36. echo "Failed to set MY_VAR.\n";
  37. }
  38. // Attempt to unset a non-existing variable
  39. $result = putenv('NON_EXISTING_VAR' . ($_GET['var'] ?? ''));
  40. if ($result) {
  41. echo "Unset NON_EXISTING_VAR successfully.\n";
  42. } else {
  43. echo "Failed to unset NON_EXISTING_VAR.\n";
  44. }
  45. };