Help us shape the future of Go! Take the 2026 Go Developer Survey

compat

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package compat implements PHP language surface that a script expects to be there rather than a library it calls: functions whose behaviour is defined by what the interpreter does, not by what they compute.

It is wired in by importing it, the way a program imports a database/sql driver:

import _ "github.com/titpetric/phpscript/stdlib/compat"

stdlib does that for you (see stdlib/imports.go). A host that wants a different set builds its Runtime without stdlib.

Output buffering

PHP's ob_* family redirects everything echo would emit into a stack of in-memory buffers, and template engines lean on it: rendering to a string is "start a buffer, include the compiled template, take the contents". That is what MiniTPL\Template::get() is built on.

ob_start();
include $compiled;
$html = ob_get_clean();

The buffers are pushed onto the runtime with runner.PushOutput, so the capture covers everything that reaches Runtime.Output: echo, inline HTML, and builtins that emit text of their own, such as die() with a message.

A function that reports "no buffer is active" returns false, as PHP does, rather than an empty string; the two are distinguishable with ===.

Regular expressions

PHP's preg_* family is PCRE; Go's regexp is RE2, which cannot express backreferences or lookaround. regex.go compiles each pattern with whichever engine can express it, so both `\1` and a linear-time guarantee are available where they apply.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(rt *runner.Runtime)

Register installs symbols into the runtime. Each runtime gets its own buffer stack, so concurrent requests capture their own output.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL