Skip to content

Outputting data

Chung Leong edited this page Nov 17, 2026 · 3 revisions

Use print() to send a formatted string to PHP's output stream:

const php = @import("php/root.zig");

pub fn @"call show"(_: *@This(), args: struct {
    string: []const u8,
    int: u32,
    float: f64,
    bool: bool,
    point: struct { x: f64, y: f64 },
}) !void {
    php.print("\"{s}\", 0x{x} {d} {} {}\n", .{
        args.string,
        args.int,
        args.float,
        args.bool,
        args.point,
    });
}
<?php

show("Hello world", 0xDEAD_BEEF, M_PI, false, [ 'x' => 123, 'y' => 456 ]);
"Hello world", 0xdeadbeef 3.141592653589793 false .{ .x = 123, .y = 456 }

Use write() to write a block of data and flush() to flush the output stream:

const php = @import("php/root.zig");

pub fn @"call write"(_: *@This(), args: struct {
    bytes: []const u8,
}) !void {
    const written = try php.write(args.bytes);
    php.print("written = {d}\n", .{written});
    php.flush();
}
<?php

write("Hello world\n");
Hello world
written = 12

Clone this wiki locally