Namespace

Runtime\PS\Compat

Package compat implements the PHP language surface a script reaches for directly, and no library it calls: functions whose behaviour follows from what the...

Description

Package compat implements the PHP language surface a script reaches for directly, and no library it calls: functions whose behaviour follows from what the interpreter does, not from what they compute.

Importing it wires it in, the way a program imports a database/sql driver:

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

stdlib does that for you (see stdlib/imports.go). A host needing 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". MiniTPL\Template::get() builds on exactly that.

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

ob_start pushes a buffer onto the runtime with runner.PushOutput and 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, and no 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 and both \1 and a linear-time guarantee are available where they apply.

Package
stdlib/ps/compatgodoc