stdlib

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package stdlib provides the forwarded "bring your own standard library" shims (the README's register_function mechanism). PHP's stdlib is not reimplemented in the VM; instead a curated set of Go functions is registered on a Runtime so transpiled PHP can call them by name. This set is sized to run the minitpl template engine (the T1 compatibility target).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(rt *runner.Runtime, bindings ...func(*runner.Runtime))

Register installs the pure (non-filesystem) shims, PHP constants, every binding contributed by an imported binding package (see runner.RegisterBinding and imports.go), and any additional bindings passed by the caller. Use RegisterFS to add filesystem IO bound to a root directory.

func RegisterFS

func RegisterFS(rt *runner.Runtime, dir string)

RegisterFS installs filesystem IO shims rooted at dir. Reads and writes are confined to that directory tree, mirroring how the upstream engine runs inside its project checkout. Paths from PHP are treated as relative to dir.

Go's fs.FS is read-only, so the engine's writes (fopen/fwrite/mkdir) use the os package against the same root; the runner's include resolution still uses the fs.FS abstraction passed to runner.New.

Types

type Exception added in v0.0.3

type Exception struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

Exception holds an error code and error message.

func NewException added in v0.0.3

func NewException(message string, code int) (*Exception, error)

NewException will return a new allocation for an exception. A nil error is returned so a new exception is not thrown immediately whenever a `new Exception` call is made in the runtime.

The exception is returned as a pointer. Returning the struct by value boxed a copy into the interface the VM holds, which costs the same allocation but loses reference semantics: the boxed copy is not addressable, so `$e->message = "..."` could not write to it and a method could not mutate the instance the script holds.

func (*Exception) Error added in v0.0.3

func (e *Exception) Error() string

Error is implemented to satisfy an error interface.

func (*Exception) GetCode added in v0.0.3

func (e *Exception) GetCode() int

GetCode returns the error code of the exception.

func (*Exception) GetMessage added in v0.0.3

func (e *Exception) GetMessage() string

GetMessage returns the error message of the exception.

Directories

Path Synopsis
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.
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.
Package span exposes telemetry spans to PHP as the start_span() binding, so a script can measure a region of its own work next to the spans the interpreter records for it.
Package span exposes telemetry spans to PHP as the start_span() binding, so a script can measure a region of its own work next to the spans the interpreter records for it.

Jump to

Keyboard shortcuts

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