ini_set

ini_set(string $option, string|int|float|bool|null $value): string|false

Modifies a runtime config directive and returns its old value; only PHP_INI_ALL directives can change, false when it can't.

C C23

C23
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    /* Runtime config-change counterpart: setenv (POSIX; mutates this process's environment block) */
    setenv("CODEABC_MODE", "fast", 1);
    printf("mode: %s\n", getenv("CODEABC_MODE"));
    unsetenv("CODEABC_MODE");
    printf("restored: %s\n", getenv("CODEABC_MODE") ? getenv("CODEABC_MODE") : "none");
    return 0;
}
Output
mode: fast
restored: none

C++ C++26

C++26
#include <cstdlib>
#include <iostream>

int main() {
    // Runtime config-change counterpart: setenv (POSIX; mutates this process's environment block)
    setenv("CODEABC_MODE", "fast", 1);
    std::cout << "mode: " << std::getenv("CODEABC_MODE") << "\n";
    unsetenv("CODEABC_MODE");
    const char *m = std::getenv("CODEABC_MODE");
    std::cout << "restored: " << (m ? m : "none") << "\n";
    return 0;
}
Output
mode: fast
restored: none

C# v11.0.100

v11.0.100
// Runtime config-change counterpart: process environment variables (mutates this process's view, never persisted)
Environment.SetEnvironmentVariable("CODEABC_MODE", "fast");
Console.WriteLine($"mode: {Environment.GetEnvironmentVariable("CODEABC_MODE")}");
Environment.SetEnvironmentVariable("CODEABC_MODE", null); // null means deletion
string? mode = Environment.GetEnvironmentVariable("CODEABC_MODE");
Console.WriteLine($"restored: {mode ?? "none"}");
Output
mode: fast
restored: none

Go v1.27.4

v1.27.4
package main

import (
	"fmt"
	"os"
)

func main() {
	// Runtime config-change counterpart: os.Setenv (mutates this process's view, never persisted)
	os.Setenv("CODEABC_MODE", "fast")
	fmt.Println("mode:", os.Getenv("CODEABC_MODE"))
	os.Unsetenv("CODEABC_MODE")
	if v := os.Getenv("CODEABC_MODE"); v != "" {
		fmt.Println("restored:", v)
	} else {
		fmt.Println("restored: none")
	}
}
Output
mode: fast
restored: none

Java v27.0.1

v27.0.1
public class Main {
    public static void main(String[] args) {
        // Runtime config-change counterpart: system properties (Java's true runtime-mutable config, the nearest equivalent of ini_set)
        System.setProperty("codeabc.mode", "fast");
        System.out.println("mode: " + System.getProperty("codeabc.mode"));
        System.clearProperty("codeabc.mode");
        String v = System.getProperty("codeabc.mode");
        System.out.println("restored: " + (v != null ? v : "none"));
    }
}
Output
mode: fast
restored: none

JavaScript v26.13.1

v26.13.1
// Runtime config-change counterpart: process.env (mutates this process's view, never persisted)
process.env.CODEABC_MODE = "fast";
console.log(`mode: ${process.env.CODEABC_MODE}`);
delete process.env.CODEABC_MODE;
console.log(`restored: ${process.env.CODEABC_MODE ?? "none"}`);
Output
mode: fast
restored: none

PHP v8.6.0

v8.6.0
// ini_set: changes PHP_INI_ALL directives at runtime, returning the old value; PHP_INI_SYSTEM directives are untouchable (returns false)
echo ini_get("display_errors"), "\n";        // 0 (forced by the -d startup argument)
$old = ini_set("display_errors", "1");
echo $old, "\n";                             // The return value is the old value
echo ini_get("display_errors"), "\n";        // 1 now in effect
ini_set("display_errors", $old);             // Restore
echo ini_get("display_errors"), "\n";        // 0
// extension_dir is PHP_INI_SYSTEM: only php.ini/startup arguments can change it; runtime changes return false
var_export(ini_set("extension_dir", "/nowhere"));
echo "\n";
echo ini_get("display_errors"), "\n";        // 0 remains untouched
Output
0
0
1
0
false
0

Python v3.15.2

v3.15.2
import os

# Runtime config-change counterpart: process environment variables (mutates this process's view, never persisted)
os.environ["CODEABC_MODE"] = "fast"
print("mode:", os.environ.get("CODEABC_MODE"))
del os.environ["CODEABC_MODE"]
print("restored:", os.environ.get("CODEABC_MODE") or "none")
Output
mode: fast
restored: none

Rust v1.99.1

v1.99.1
use std::env;

fn main() {
    // Runtime config-change counterpart: process environment variables (mutates this process's view, never persisted)
    env::set_var("CODEABC_MODE", "fast");
    println!("mode: {}", env::var("CODEABC_MODE").unwrap_or_default());
    env::remove_var("CODEABC_MODE");
    println!("restored: {}", env::var("CODEABC_MODE").unwrap_or_else(|_| "none".into()));
}
Output
mode: fast
restored: none

TypeScript v26.13.1

v26.13.1
// Runtime config-change counterpart: process.env (mutates this process's view, never persisted)
process.env.CODEABC_MODE = "fast";
console.log(`mode: ${process.env.CODEABC_MODE}`);
delete process.env.CODEABC_MODE;
console.log(`restored: ${process.env.CODEABC_MODE ?? "none"}`);
Output
mode: fast
restored: none

Language differences

C: setenv/unsetenv (POSIX, needs feature test macros; _putenv on Windows) mutate this process's environment block; file config means manual read/write.

C++: same as C; hot config reload is usually hand-built or via toml++-style libraries.

C#: Environment.SetEnvironmentVariable mutates process env (null deletes); app config hot reload goes through IOptionsMonitor.

Go: os.Setenv/os.Unsetenv mutate this process's env (concurrent goroutine access to the environment is a data race).

Java: System.setProperty/clearProperty on system properties — the JVM's real runtime-changeable config; env vars can't change at runtime.

JavaScript: process.env.X = ... mutates this process's view; the parent/system environment can't change.

PHP: ini_set only affects PHP_INI_ALL directives (like display_errors); PHP_INI_SYSTEM directives (like extension_dir) can only come from php.ini/startup and return false at runtime; it returns the old value for easy restore; in CLI the change is instant, on the web it scopes to the current request.

Python: no ini_set equivalent — os.environ["X"]=... mutates process env (inherited by children); hot config is manual re-reads or dynaconf.

Rust: env::set_var/remove_var (unsafe since edition 2024 — race-prone under threads); env vars aren't the usual hot-config channel.

TypeScript: same as JavaScript.