php_uname

php_uname(string $mode = "a"): string

System identity: modes 's'/'n'/'r'/'v'/'m' mirror the POSIX utsname fields sysname/nodename/release/version/machine; with no argument it returns the five glued together. Use PHP_OS_FAMILY for a simple OS-family check.

C C23

C23
#include <stdio.h>
#include <string.h>
#include <sys/utsname.h>

int main(void) {
    /* uname(2) fills the utsname struct - exactly the five php_uname() modes */
    struct utsname u;
    uname(&u);
    const char *vals[5] = {u.sysname, u.nodename, u.release, u.version, u.machine};
    const char *labels[5] = {"sysname", "nodename", "release", "version", "machine"};
    int all = 1;
    for (int i = 0; i < 5; i++) {
        int ne = strlen(vals[i]) > 0;
        all = all && ne;
        printf("%s: non-empty=%s\n", labels[i], ne ? "true" : "false");
    }
    printf("all5: %s\n", all ? "true" : "false");
    return 0;
}
Output
sysname: non-empty=true
nodename: non-empty=true
release: non-empty=true
version: non-empty=true
machine: non-empty=true
all5: true

C++ C++26

C++26
#include <cstdio>
#include <cstring>
#include <sys/utsname.h>

int main() {
    // uname(2) fills the utsname struct - exactly the five php_uname() modes
    struct utsname u;
    uname(&u);
    const char* vals[5] = {u.sysname, u.nodename, u.release, u.version, u.machine};
    const char* labels[5] = {"sysname", "nodename", "release", "version", "machine"};
    bool all = true;
    for (int i = 0; i < 5; i++) {
        bool ne = std::strlen(vals[i]) > 0;
        all = all && ne;
        std::printf("%s: non-empty=%s\n", labels[i], ne ? "true" : "false");
    }
    std::printf("all5: %s\n", all ? "true" : "false");
}
Output
sysname: non-empty=true
nodename: non-empty=true
release: non-empty=true
version: non-empty=true
machine: non-empty=true
all5: true

C# v11.0.100

v11.0.100
// Environment / RuntimeInformation expose the OS identity .NET knows
using System.Runtime.InteropServices;
var fields = new (string Name, string? Value)[] {
    ("osversion", Environment.OSVersion.ToString()),
    ("machine", Environment.MachineName),
    ("osdescription", RuntimeInformation.OSDescription),
    ("arch", RuntimeInformation.OSArchitecture.ToString()),
};
foreach (var (name, value) in fields)
    Console.WriteLine($"{name}: non-empty={!string.IsNullOrEmpty(value)}");
Console.WriteLine($"all{fields.Length}: {fields.All(f => !string.IsNullOrEmpty(f.Value))}");
Output
osversion: non-empty=True
machine: non-empty=True
osdescription: non-empty=True
arch: non-empty=True
all4: True

Go v1.27.4

v1.27.4
package main

import (
	"fmt"
	"os"
	"runtime"
)

func main() {
	// std exposes GOOS/GOARCH as constants; the full utsname record needs x/sys/unix
	host, _ := os.Hostname()
	fmt.Println("goos: non-empty=", runtime.GOOS != "")
	fmt.Println("goarch: non-empty=", runtime.GOARCH != "")
	fmt.Println("hostname: non-empty=", host != "")
}
Output
goos: non-empty= true
goarch: non-empty= true
hostname: non-empty= true

Java v27.0.1

v27.0.1
import java.net.InetAddress;

public class Main {
    public static void main(String[] args) throws Exception {
        // os.* properties come from uname(2); the JDK has no kernel "release" field
        String[] fields = {
            System.getProperty("os.name"),
            InetAddress.getLocalHost().getHostName(),
            System.getProperty("os.version"),
            System.getProperty("java.version"), // JVM build stands in for the kernel version
            System.getProperty("os.arch"),
        };
        String[] labels = {"sysname", "nodename", "release", "version", "machine"};
        boolean all = true;
        for (int i = 0; i < fields.length; i++) {
            boolean ne = fields[i] != null && !fields[i].isEmpty();
            all = all && ne;
            System.out.println(labels[i] + ": non-empty=" + ne);
        }
        System.out.println("all5: " + all);
    }
}
Output
sysname: non-empty=true
nodename: non-empty=true
release: non-empty=true
version: non-empty=true
machine: non-empty=true
all5: true

JavaScript v26.13.1

v26.13.1
// the os module wraps uname(2); assert the derived fact only (no field values are printed)
const os = require("os");
const fields = [os.type(), os.hostname(), os.release(), os.version(), os.machine()];
const labels = ["sysname", "nodename", "release", "version", "machine"];
labels.forEach((name, i) => console.log(`${name}: non-empty=${fields[i] !== ""}`));
console.log(`all5: ${fields.every((f) => f !== "")}`);
Output
sysname: non-empty=true
nodename: non-empty=true
release: non-empty=true
version: non-empty=true
machine: non-empty=true
all5: true

PHP v8.6.0

v8.6.0
// the five php_uname modes mirror the POSIX utsname fields; values are machine-specific,
// so only "every field is non-empty" is asserted
$labels = ["s" => "sysname", "n" => "nodename", "r" => "release", "v" => "version", "m" => "machine"];
$all = true;
foreach ($labels as $mode => $label) {
    $ne = php_uname($mode) !== "";
    $all = $all && $ne;
    echo "$label: non-empty=", var_export($ne, true), PHP_EOL;
}
echo "all5: ", var_export($all, true), PHP_EOL;
Output
sysname: non-empty=true
nodename: non-empty=true
release: non-empty=true
version: non-empty=true
machine: non-empty=true
all5: true

Python v3.15.2

v3.15.2
import platform

# platform probes uname(2) for you; assert the derived fact only
fields = [platform.system(), platform.node(), platform.release(),
          platform.version(), platform.machine()]
labels = ["sysname", "nodename", "release", "version", "machine"]
for name, val in zip(labels, fields):
    print(f"{name}: non-empty={val != ''}")
print(f"all5: {all(fields)}")
Output
sysname: non-empty=True
nodename: non-empty=True
release: non-empty=True
version: non-empty=True
machine: non-empty=True
all5: True

Rust v1.99.1

v1.99.1
use std::env::consts;

fn main() {
    // std exposes OS identity as compile-time constants; libc::uname is the direct match
    let fields = [("family", consts::FAMILY), ("os", consts::OS), ("arch", consts::ARCH)];
    for (name, val) in fields {
        println!("{name}: non-empty={}", !val.is_empty());
    }
    println!("all{}: {}", fields.len(), fields.iter().all(|(_, v)| !v.is_empty()));
}
Output
family: non-empty=true
os: non-empty=true
arch: non-empty=true
all3: true

TypeScript v26.13.1

v26.13.1
// the os module wraps uname(2); assert the derived fact only (no field values are printed)
import * as os from "os";
const fields: string[] = [os.type(), os.hostname(), os.release(), os.version(), os.machine()];
const labels: string[] = ["sysname", "nodename", "release", "version", "machine"];
labels.forEach((name, i) => console.log(`${name}: non-empty=${fields[i] !== ""}`));
console.log(`all5: ${fields.every((f) => f !== "")}`);
Output
sysname: non-empty=true
nodename: non-empty=true
release: non-empty=true
version: non-empty=true
machine: non-empty=true
all5: true

Language differences

C: uname(2) fills struct utsname (<sys/utsname.h>) with five fields - a 1:1 match for php_uname's five modes; the GNU-extension sixth field domainname needs _GNU_SOURCE.

C++: the same syscall as C.

C#: Environment.OSVersion (a Version object), Environment.MachineName, RuntimeInformation.OSDescription/OSArchitecture; since .NET 5+ OSVersion reports the real version instead of impersonating an old one.

Go: runtime.GOOS/GOARCH are compile-time constants (under cross-compilation they describe the TARGET platform); the hostname comes from os.Hostname(); kernel versions live outside std - use Uname from golang.org/x/sys/unix.

Java: the System.getProperty("os.*") trio plus InetAddress.getLocalHost().getHostName(); the JDK has no kernel release/version fields, so the example substitutes java.version and says so.

JavaScript: Node's os.type()/hostname()/release()/version()/machine() map 1:1 to the five fields; browser JS sits in a security sandbox with no system-information API at all.

PHP: php_uname('s'/'n'/'r'/'v'/'m') reads one field; with no argument it glues "sysname release version machine nodename" into one space-separated string; to detect just the OS family use PHP_OS_FAMILY ('Linux'/'Darwin'/'Windows'...) or DIRECTORY_SEPARATOR - don't parse the php_uname string.

Python: platform.system()/node()/release()/version()/machine() map 1:1; platform.uname() fetches all at once (a namedtuple); platform.processor() adds the CPU model.

Rust: std::env::consts::{OS, ARCH, FAMILY} are compile-time constants (the TARGET platform, not a runtime probe); runtime uname goes through libc::uname or the uname crate.

TypeScript: same as JavaScript.