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 ¶
Register installs the 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. The filesystem shims come in that way too, rooted at the process working directory; use RegisterFS to bind them to another root.
func RegisterFS ¶
RegisterFS installs filesystem IO shims rooted at dir. A path from PHP is treated as relative to dir and cannot climb out of it, mirroring how the upstream engine runs inside its project checkout. An absolute path is taken as the script wrote it.
Writes are held to the runtime's writable_paths when it configures any; see files.RegisterRoot.
The shims live in stdlib/files and Register already installs them, rooted at the process working directory; this rebinds them to dir.
Types ¶
type Exception ¶ added in v0.0.3
type Exception struct {
Message string `json:"message"`
Code int `json:"code"`
Class string `json:"class"`
}
Exception holds an error code and error message.
Every PHP throwable class is this one Go type. Class records the name the script constructed, so get_class() can answer it and a catch clause can filter on it; no two of them stand in a subclass relation, because phpscript has no inheritance. See docs/design.md.
func NewException ¶ added in v0.0.3
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) GetMessage ¶ added in v0.0.3
GetMessage returns the error message of the exception.
func (*Exception) ThrowableClass ¶ added in v0.3.4
ThrowableClass returns the PHP class the exception was constructed as, implementing runner.Throwable.
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 core holds the part of PHP's standard library that computes: strings, arrays, json, the language constructs exposed as functions, the tokenizer, the environment and the platform surface a program expects to find before it does anything interesting.
|
Package core holds the part of PHP's standard library that computes: strings, arrays, json, the language constructs exposed as functions, the tokenizer, the environment and the platform surface a program expects to find before it does anything interesting. |
|
Package crypto holds the password hashing a script cannot write for itself.
|
Package crypto holds the password hashing a script cannot write for itself. |
|
Package database holds the named sql connections a phpscript runtime resolves through.
|
Package database holds the named sql connections a phpscript runtime resolves through. |
|
Package files provides the filesystem shims phpscript exposes to PHP: path helpers, reads, writes, streams, and the uploaded-file functions that go with $_FILES.
|
Package files provides the filesystem shims phpscript exposes to PHP: path helpers, reads, writes, streams, and the uploaded-file functions that go with $_FILES. |
|
Package http provides the HTTP\Client and HTTP\Request bindings, the outbound HTTP surface a script reaches instead of PHP's curl_* family.
|
Package http provides the HTTP\Client and HTTP\Request bindings, the outbound HTTP surface a script reaches instead of PHP's curl_* family. |
|
Package internals provides PHP internal memory and runtime introspection bindings.
|
Package internals provides PHP internal memory and runtime introspection bindings. |
|
Package logger writes a log line and fails the span the work runs in when that line reports an error.
|
Package logger writes a log line and fails the span the work runs in when that line reports an error. |
|
Package session implements Session\Manager and the Session\Storage\* family: an HTTP-only cookie carrying an opaque, randomly generated session ID, and the storage the data behind that ID lives in.
|
Package session implements Session\Manager and the Session\Storage\* family: an HTTP-only cookie carrying an opaque, randomly generated session ID, and the storage the data behind that ID lives in. |
|
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. |