phpctx

package
v0.0.0-...-5ceddf5 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: BSD-3-Clause Imports: 32 Imported by: 15

Documentation

Index

Constants

View Source
const (
	BufferWrite     = 0
	BufferStart     = 0x0001
	BufferClean     = 0x0002
	BufferFlush     = 0x0004
	BufferFinal     = 0x0008
	BufferCleanable = 0x0010
	BufferFlushable = 0x0020
	BufferRemovable = 0x0040

	// Status flags (reported by ob_get_status, not user-settable)
	BufferTypeUser  = 0x0001 // bit 0 in type field; also set in flags for user handlers
	BufferStarted   = 0x1000
	BufferDisabled  = 0x2000
	BufferProcessed = 0x4000
)
View Source
const (
	PHP_OUTPUT_HANDLER_START     = phpv.ZInt(BufferStart)
	PHP_OUTPUT_HANDLER_WRITE     = phpv.ZInt(BufferWrite)
	PHP_OUTPUT_HANDLER_FLUSH     = phpv.ZInt(BufferFlush)
	PHP_OUTPUT_HANDLER_CLEAN     = phpv.ZInt(BufferClean)
	PHP_OUTPUT_HANDLER_FINAL     = phpv.ZInt(BufferFinal)
	PHP_OUTPUT_HANDLER_CONT      = phpv.ZInt(BufferWrite)
	PHP_OUTPUT_HANDLER_END       = phpv.ZInt(BufferFinal)
	PHP_OUTPUT_HANDLER_CLEANABLE = phpv.ZInt(BufferCleanable)
	PHP_OUTPUT_HANDLER_FLUSHABLE = phpv.ZInt(BufferFlushable)
	PHP_OUTPUT_HANDLER_REMOVABLE = phpv.ZInt(BufferRemovable)
)

> const

View Source
const (
	PHP_OUTPUT_HANDLER_STARTED   = phpv.ZInt(BufferStarted)
	PHP_OUTPUT_HANDLER_DISABLED  = phpv.ZInt(BufferDisabled)
	PHP_OUTPUT_HANDLER_PROCESSED = phpv.ZInt(BufferProcessed)
)

> const

Variables

View Source
var Compile func(parent phpv.Context, t *tokenizer.Lexer) (phpv.Runnable, error)
View Source
var ErrOpenBasedir = &phpv.PhpError{Code: phpv.E_WARNING}

ErrOpenBasedir is returned when an open_basedir restriction blocks file access.

View Source
var PHP_OUTPUT_HANDLER_STDFLAGS = phpv.ZInt(BufferCleanable | BufferFlushable | BufferRemovable)

> const

Functions

func GetConstantExtName

func GetConstantExtName(name string) string

GetConstantExtName returns the name of the extension that defines the given constant, or "" if the constant was not registered by any extension.

func HasExt

func HasExt(name string) bool

func NewBufContext

func NewBufContext(ctx phpv.Context, b io.Writer) phpv.Context

func ParseQueryToArray

func ParseQueryToArray(ctx phpv.Context, q string, a *phpv.ZArray) error

ParseQueryToArray will parse a given query string into a ZArray with PHP parsing rules

func RegisterExt

func RegisterExt(e *Ext)

func WithConfig

func WithConfig(parent phpv.Context, name phpv.ZString, v *phpv.ZVal) phpv.Context

func WithFuncName

func WithFuncName(parent phpv.Context, name string) phpv.Context

WithFuncName creates a context wrapper that overrides GetFuncName().

Types

type BufContext

type BufContext struct {
	phpv.Context
	// contains filtered or unexported fields
}

func (*BufContext) Parent

func (b *BufContext) Parent(n int) phpv.Context

func (*BufContext) Write

func (b *BufContext) Write(d []byte) (int, error)

type Buffer

type Buffer struct {
	ImplicitFlush bool
	ChunkSize     int
	CB            phpv.Callable
	Flags         int // capability flags (cleanable/flushable/removable)
	// contains filtered or unexported fields
}

func (*Buffer) CallbackName

func (b *Buffer) CallbackName() string

CallbackName returns the display name of the callback for ob_get_status/ob_list_handlers.

func (*Buffer) Clean

func (b *Buffer) Clean() error

func (*Buffer) ClearCaller

func (b *Buffer) ClearCaller()

ClearCaller removes the calling function context.

func (*Buffer) Close

func (b *Buffer) Close() error

func (*Buffer) CloseClean

func (b *Buffer) CloseClean() error

CloseClean closes and discards the buffer (ob_end_clean behavior). Invokes callback with CLEAN|FINAL, discards result, removes buffer.

func (*Buffer) CloseWithFlags

func (b *Buffer) CloseWithFlags(flag int, writeOutput bool) error

CloseWithFlags closes the buffer with the given flags. If writeOutput is true, writes the callback result to the underlying writer.

func (*Buffer) Flush

func (b *Buffer) Flush() error

func (*Buffer) Get

func (b *Buffer) Get() []byte

func (*Buffer) IsCleanable

func (b *Buffer) IsCleanable() bool

func (*Buffer) IsFlushable

func (b *Buffer) IsFlushable() bool

func (*Buffer) IsRemovable

func (b *Buffer) IsRemovable() bool

func (*Buffer) Level

func (b *Buffer) Level() int

func (*Buffer) Parent

func (b *Buffer) Parent() *Buffer

func (*Buffer) SetCaller

func (b *Buffer) SetCaller(ctx phpv.Context, funcName string)

SetCaller stores the calling function context for deprecation warnings. The location is captured at call time so it doesn't change during callback execution.

func (*Buffer) StatusFlags

func (b *Buffer) StatusFlags() int

StatusFlags returns the combined flags for ob_get_status reporting.

func (*Buffer) Type

func (b *Buffer) Type() int

Type returns 0 for internal (no callback) or 1 for user callback.

func (*Buffer) Write

func (b *Buffer) Write(d []byte) (int, error)

type ErrClassRedeclare

type ErrClassRedeclare struct {
	Kind         string       // "class", "interface", or "trait"
	ExistingName phpv.ZString // original name of existing class
	RegisterName phpv.ZString // name being registered
	PrevLoc      string       // " (previously declared in ...)" or ""
	IsAlias      bool         // existing name differs from registered name (class_alias case)
}

ErrClassRedeclare is returned when a class name is already registered. IsAlias indicates the existing registration was under a different name (i.e. via class_alias).

func (*ErrClassRedeclare) Error

func (e *ErrClassRedeclare) Error() string

func (*ErrClassRedeclare) IsAliasConflict

func (e *ErrClassRedeclare) IsAliasConflict() bool

func (*ErrClassRedeclare) RedeclareKind

func (e *ErrClassRedeclare) RedeclareKind() string

func (*ErrClassRedeclare) RedeclarePrevLoc

func (e *ErrClassRedeclare) RedeclarePrevLoc() string

type Ext

type Ext struct {
	Name      string
	Version   string
	Functions map[string]*ExtFunction
	Constants map[phpv.ZString]phpv.Val
	Classes   []*phpobj.ZClass
	// OnGlobalCreate is an optional callback invoked when a new Global context is created.
	// Extensions can use it to register per-Global resources such as stream handlers.
	OnGlobalCreate func(g *Global)
}

func GetExt

func GetExt(name string) *Ext

type ExtFunction

type ExtFunction struct {
	phpv.CallableVal

	Ext      string // extension name, populated by RegisterExt
	Func     func(ctx phpv.Context, args []*phpv.ZVal) (*phpv.ZVal, error)
	Args     []*ExtFunctionArg
	MinArgs  int  // minimum required arguments (0 = no check)
	MaxArgs  int  // maximum allowed arguments (0 = no check, -1 = variadic/unlimited)
	ZeroArgs bool // if true, the function accepts exactly 0 arguments (MaxArgs=0 special case)
	// contains filtered or unexported fields
}

func (*ExtFunction) Call

func (e *ExtFunction) Call(ctx phpv.Context, args []*phpv.ZVal) (*phpv.ZVal, error)

func (*ExtFunction) GetArgs

func (e *ExtFunction) GetArgs() []*phpv.FuncArg

GetArgs implements phpv.FuncGetArgs, returning cached parameter metadata. Returns nil for functions without declared Args (most built-in functions), which signals to callZValImpl that Go-side argument handling applies.

func (*ExtFunction) GetExt

func (e *ExtFunction) GetExt() string

func (*ExtFunction) Name

func (e *ExtFunction) Name() string

type ExtFunctionArg

type ExtFunctionArg struct {
	ArgName   string // without the $ sign
	Ref       bool
	PreferRef bool // like Ref but silently accepts non-ref values (ZEND_SEND_PREFER_REF)
	Optional  bool // is this argument optional?
	Variadic  bool // is this a variadic parameter? (applies to all remaining args)
}

type Flusher

type Flusher interface {
	Flush() error
}

type FuncContext

type FuncContext struct {
	phpv.Context

	Args []*phpv.ZVal
	// contains filtered or unexported fields
}

func GetFuncContext

func GetFuncContext() *FuncContext

GetFuncContext retrieves a FuncContext from the pool

func (*FuncContext) AsVal

func (c *FuncContext) AsVal(ctx phpv.Context, t phpv.ZType) (phpv.Val, error)

func (*FuncContext) CallSiteLoc

func (c *FuncContext) CallSiteLoc() *phpv.Loc

CallSiteLoc returns the frozen location (file/line) from which this function was called, as set during callZValImpl setup. This differs from Loc() which returns the current execution position in the parent context. Implements phpv.CallSiteLocProvider.

func (*FuncContext) Callable

func (c *FuncContext) Callable() phpv.Callable

func (*FuncContext) CalledClass

func (c *FuncContext) CalledClass() phpv.ZClass

func (*FuncContext) Class

func (c *FuncContext) Class() phpv.ZClass

func (*FuncContext) ClosureStaticVarKey

func (c *FuncContext) ClosureStaticVarKey() uintptr

ClosureStaticVarKey returns the per-closure-instance key for static variable storage. This implements phpv.ClosureStaticVarKeyProvider. Returns 0 when not running inside a closure instance (e.g. named functions, class methods).

func (*FuncContext) Count

func (c *FuncContext) Count(ctx phpv.Context) phpv.ZInt

func (*FuncContext) Deprecated

func (ctx *FuncContext) Deprecated(format string, a ...any) error

func (*FuncContext) Error

func (ctx *FuncContext) Error(err error, t ...phpv.PhpErrorType) error

func (*FuncContext) Errorf

func (ctx *FuncContext) Errorf(format string, a ...any) error

func (*FuncContext) Func

func (c *FuncContext) Func() phpv.FuncContext

func (*FuncContext) FuncError

func (ctx *FuncContext) FuncError(err error, t ...phpv.PhpErrorType) error

func (*FuncContext) FuncErrorf

func (ctx *FuncContext) FuncErrorf(format string, a ...any) error

func (*FuncContext) GetFuncName

func (ctx *FuncContext) GetFuncName() string

func (*FuncContext) GetFuncNameForTrace

func (ctx *FuncContext) GetFuncNameForTrace() string

GetFuncNameForTrace returns the function name using the actual method type (-> or ::) for stack traces

func (*FuncContext) GetType

func (c *FuncContext) GetType() phpv.ZType

func (*FuncContext) InternalLoc

func (c *FuncContext) InternalLoc() *phpv.Loc

InternalLoc returns the "internal" location (Unknown:0) for internal calls, or nil for regular calls. Used by deprecation/warning logic to report the correct location for engine-invoked callbacks.

func (*FuncContext) Loc

func (c *FuncContext) Loc() *phpv.Loc

Loc returns the current source-code location. It always delegates to the parent context which tracks the current execution position via Tick(). The isInternal flag only affects stack trace formatting (showing "[internal function]"), not Loc().

func (*FuncContext) NewIterator

func (c *FuncContext) NewIterator() phpv.ZIterator

func (*FuncContext) Notice

func (ctx *FuncContext) Notice(format string, a ...any) error

func (*FuncContext) OffsetCheck

func (c *FuncContext) OffsetCheck(ctx phpv.Context, name phpv.Val) (*phpv.ZVal, bool, error)

func (*FuncContext) OffsetExists

func (c *FuncContext) OffsetExists(ctx phpv.Context, name phpv.Val) (bool, error)

func (*FuncContext) OffsetGet

func (c *FuncContext) OffsetGet(ctx phpv.Context, name phpv.Val) (*phpv.ZVal, error)

func (*FuncContext) OffsetSet

func (c *FuncContext) OffsetSet(ctx phpv.Context, name phpv.Val, v *phpv.ZVal) error

func (*FuncContext) OffsetUnset

func (c *FuncContext) OffsetUnset(ctx phpv.Context, name phpv.Val) error

func (*FuncContext) Parent

func (ctx *FuncContext) Parent(n int) phpv.Context

func (*FuncContext) RegisterForeachRefCleanup

func (c *FuncContext) RegisterForeachRefCleanup(fn func())

RegisterForeachRefCleanup registers a cleanup function to be called when this function context is released, for cleaning up foreach-by-reference iterator references.

func (*FuncContext) Release

func (c *FuncContext) Release() error

Release returns the FuncContext to the pool after clearing it. It returns an error if any destructor triggered during scope cleanup throws an exception.

func (*FuncContext) SetUseParentScope

func (c *FuncContext) SetUseParentScope(v bool)

SetUseParentScope sets whether this FuncContext should delegate variable access (OffsetGet/OffsetSet/OffsetCheck/OffsetUnset/OffsetExists) to the parent context. Used by eval() so that variables are accessible in the calling scope while the eval FuncContext remains visible in stack traces.

func (*FuncContext) SuppressCalledIn

func (c *FuncContext) SuppressCalledIn() bool

SuppressCalledIn reports whether the "called in X on line Y" suffix should be suppressed from argument-count and type error messages for this call.

func (*FuncContext) This

func (c *FuncContext) This() phpv.ZObject

func (*FuncContext) UserDeprecated

func (ctx *FuncContext) UserDeprecated(format string, a ...any) error

func (*FuncContext) Warn

func (ctx *FuncContext) Warn(format string, a ...any) error

func (*FuncContext) WarnDeprecated

func (ctx *FuncContext) WarnDeprecated() error

func (*FuncContext) ZVal

func (c *FuncContext) ZVal() *phpv.ZVal

type Global

type Global struct {
	context.Context

	IniConfig phpv.IniConfig

	StreamFilterRegistry *stream.FilterRegistry

	ImplicitFlush bool

	DefaultStreamContext *stream.Context

	// Last error tracked for error_get_last() / error_clear_last()
	LastError *phpv.PhpError

	// Serialize recursion detection across nested serialize calls
	// (especially Serializable::serialize() calling serialize() internally)
	SerializeSeenObjects map[phpv.ZObject]bool
	// SerializeContext stores a pointer to the current outermost serializeSeen
	// so that nested serialize() calls (from Serializable::serialize()) can share it.
	SerializeContext interface{}

	// StrictTypes tracks whether the currently executing file has declare(strict_types=1).
	// This is a per-file flag that affects type coercion at call sites.
	StrictTypes bool
	// contains filtered or unexported fields
}

func NewGlobal

func NewGlobal(ctx context.Context, p *Process, config phpv.IniConfig) *Global

func NewGlobalReq

func NewGlobalReq(req *http.Request, p *Process, config phpv.IniConfig) *Global

func (*Global) AppendBuffer

func (g *Global) AppendBuffer() *Buffer

func (*Global) ApplyMaxMemoryLimit

func (g *Global) ApplyMaxMemoryLimit()

ApplyMaxMemoryLimit should be called after INI parsing to enforce max_memory_limit on the initial memory_limit value and sync the MemMgr limit.

func (*Global) Argv

func (g *Global) Argv() []string

func (*Global) Buffer

func (g *Global) Buffer() *Buffer

func (*Global) Call

func (c *Global) Call(ctx phpv.Context, f phpv.Callable, args []phpv.Runnable, optionalThis ...phpv.ZObject) (*phpv.ZVal, error)

perform call in new context

func (*Global) CallDestructors

func (g *Global) CallDestructors()

CallDestructors calls __destruct on all remaining tracked objects. Exceptions thrown by destructors are passed to handleUncaughtException.

func (*Global) CallTickFunctions

func (g *Global) CallTickFunctions(ctx phpv.Context) error

CallTickFunctions invokes all registered tick functions

func (*Global) CallZVal

func (c *Global) CallZVal(ctx phpv.Context, f phpv.Callable, args []*phpv.ZVal, optionalThis ...phpv.ZObject) (*phpv.ZVal, error)

func (*Global) CallZValInternal

func (c *Global) CallZValInternal(ctx phpv.Context, f phpv.Callable, args []*phpv.ZVal, optionalThis ...phpv.ZObject) (*phpv.ZVal, error)

CallZValInternal is like CallZVal but marks the call as internal (e.g., from output buffer callbacks). This causes the stack trace entry to show "[internal function]" instead of the filename.

func (*Global) CallZValNoCalledIn

func (c *Global) CallZValNoCalledIn(ctx phpv.Context, f phpv.Callable, args []*phpv.ZVal, optionalThis ...phpv.ZObject) (*phpv.ZVal, error)

CallZValNoCalledIn is like CallZVal but suppresses the "called in" suffix in type error messages. Used when invoking closures via __invoke method dispatch, where PHP does not append "called in" to type error messages.

func (*Global) Chdir

func (g *Global) Chdir(d phpv.ZString) error

func (*Global) CheckOpenBasedir

func (g *Global) CheckOpenBasedir(ctx phpv.Context, path string, funcName string) error

CheckOpenBasedir checks if the given path is within the open_basedir restriction. Returns nil if access is allowed, or a sentinel error (ErrOpenBasedir) if restricted. A warning is emitted when access is blocked. The funcName parameter is used in the warning message (e.g. "file_exists").

func (*Global) Class

func (g *Global) Class() phpv.ZClass

func (*Global) CleanBuffers

func (g *Global) CleanBuffers()

CleanBuffers discards buffered content in all active output buffers without closing them. The buffers remain active so subsequent writes (like fatal error messages) still pass through their callbacks.

func (*Global) ClearAutoloadFunctions

func (g *Global) ClearAutoloadFunctions()

func (*Global) ClearLastCallable

func (g *Global) ClearLastCallable()

func (*Global) Close

func (g *Global) Close() error

func (*Global) ConstantForceSet

func (g *Global) ConstantForceSet(k phpv.ZString, v phpv.Val)

ConstantForceSet sets a constant value, overwriting any existing value. Used for __COMPILER_HALT_OFFSET__ which is per-file.

func (*Global) ConstantGet

func (g *Global) ConstantGet(name phpv.ZString) (phpv.Val, bool)

func (*Global) ConstantGetAttributes

func (g *Global) ConstantGetAttributes(k phpv.ZString) []*phpv.ZAttribute

func (*Global) ConstantSet

func (g *Global) ConstantSet(k phpv.ZString, v phpv.Val) bool

func (*Global) ConstantSetAttributes

func (g *Global) ConstantSetAttributes(k phpv.ZString, attrs []*phpv.ZAttribute)

func (*Global) ConsumeNoDiscardPending

func (g *Global) ConsumeNoDiscardPending() bool

func (*Global) Count

func (c *Global) Count(ctx phpv.Context) phpv.ZInt

func (*Global) Deadline

func (g *Global) Deadline() (time.Time, bool)

func (*Global) Deprecated

func (g *Global) Deprecated(format string, a ...any) error

func (*Global) DiscardBuffers

func (g *Global) DiscardBuffers()

DiscardBuffers discards all output buffer content without flushing. Used on fatal errors to prevent buffered output from leaking.

func (*Global) DoString

func (c *Global) DoString(ctx phpv.Context, strCode phpv.ZString) (*phpv.ZVal, error)

func (*Global) DrainTempObjects

func (g *Global) DrainTempObjects()

DrainTempObjects checks all registered temporary objects and releases any that are still unreferenced (refcount == 0). Called at statement boundaries.

func (*Global) Error

func (g *Global) Error(err error, t ...phpv.PhpErrorType) error

func (*Global) ErrorPrefix

func (g *Global) ErrorPrefix() string

ErrorPrefix returns "\n" if prior output exists and didn't end with a newline, matching PHP's behavior of separating inline output from error messages. Returns "" when the error is the first output.

func (*Global) Errorf

func (g *Global) Errorf(format string, a ...any) error

func (*Global) Exists

func (g *Global) Exists(fn phpv.ZString) (bool, error)

func (*Global) Flush

func (g *Global) Flush()

func (*Global) Func

func (g *Global) Func() phpv.FuncContext

func (*Global) FuncError

func (g *Global) FuncError(err error, t ...phpv.PhpErrorType) error

func (*Global) FuncErrorf

func (g *Global) FuncErrorf(format string, a ...any) error

func (*Global) GetAllConstants

func (g *Global) GetAllConstants() map[phpv.ZString]phpv.Val

GetAllConstants returns all defined constants.

func (*Global) GetAllEnv

func (g *Global) GetAllEnv(ctx phpv.Context) *phpv.ZArray

GetAllEnv returns all environment variables as a ZArray.

func (*Global) GetAutoloadExtensions

func (g *Global) GetAutoloadExtensions() string

func (*Global) GetAutoloadFunctions

func (g *Global) GetAutoloadFunctions() []phpv.Callable

func (*Global) GetClass

func (g *Global) GetClass(ctx phpv.Context, name phpv.ZString, autoload bool) (phpv.ZClass, error)

func (*Global) GetCompilingClass

func (g *Global) GetCompilingClass() phpv.ZClass

func (*Global) GetConfig

func (g *Global) GetConfig(name phpv.ZString, def *phpv.ZVal) *phpv.ZVal

func (*Global) GetConfigEntry

func (g *Global) GetConfigEntry(name phpv.ZString) *phpv.IniValue

GetConfigEntry returns the raw IniValue for a config entry, or nil if the config option doesn't exist. Unlike GetConfig, this allows callers to distinguish between "not set" and "set to empty".

func (*Global) GetDeclaredClasses

func (g *Global) GetDeclaredClasses() []phpv.ZString

func (*Global) GetDefinedFunctions

func (g *Global) GetDefinedFunctions(ctx phpv.Context, excludeDisabled bool) (*phpv.ZArray, error)

func (*Global) GetFilterRegistry

func (g *Global) GetFilterRegistry() *stream.FilterRegistry

GetFilterRegistry returns the per-request stream filter registry. Implements stream.FilterRegistryProvider.

func (*Global) GetFuncName

func (g *Global) GetFuncName() string

func (*Global) GetFunction

func (g *Global) GetFunction(ctx phpv.Context, name phpv.ZString) (phpv.Callable, error)

func (*Global) GetGlobalConfig

func (g *Global) GetGlobalConfig(name phpv.ZString, def *phpv.ZVal) *phpv.ZVal

func (*Global) GetIncludedFiles

func (g *Global) GetIncludedFiles() []string

GetIncludedFiles returns a list of all included/required file paths.

func (*Global) GetLoadedExtensions

func (g *Global) GetLoadedExtensions() []string

func (*Global) GetRequestBody

func (g *Global) GetRequestBody() []byte

GetRequestBody returns the raw request body for php://input

func (*Global) GetScriptFile

func (g *Global) GetScriptFile() phpv.ZString

func (*Global) GetSerializeContext

func (g *Global) GetSerializeContext() interface{}

GetSerializeContext returns the current serialize context (may be nil).

func (*Global) GetSerializeSeenObjects

func (g *Global) GetSerializeSeenObjects() map[phpv.ZObject]bool

GetSerializeSeenObjects returns the current serialize object tracking map (may be nil).

func (*Global) GetStackTrace

func (g *Global) GetStackTrace(ctx phpv.Context) []*phpv.StackTraceEntry

func (*Global) GetStdin

func (g *Global) GetStdin() *stream.Stream

GetStdin returns the custom stdin stream if set, or nil.

func (*Global) GetStreamHandler

func (g *Global) GetStreamHandler(scheme string) (stream.Handler, bool)

GetStreamHandler returns the registered stream handler for a scheme.

func (*Global) GetStreamHandlers

func (g *Global) GetStreamHandlers() []string

GetStreamHandlers returns all registered stream handler scheme names.

func (*Global) GetStrictTypes

func (g *Global) GetStrictTypes() bool

GetStrictTypes returns the current strict_types flag.

func (*Global) GetUserErrorHandler

func (g *Global) GetUserErrorHandler() (phpv.Callable, phpv.PhpErrorType, *phpv.ZVal)

func (*Global) GetUserExceptionHandler

func (g *Global) GetUserExceptionHandler() phpv.Callable

func (*Global) Getenv

func (g *Global) Getenv(key string) (string, bool)

func (*Global) Getwd

func (g *Global) Getwd() phpv.ZString

func (*Global) Global

func (g *Global) Global() phpv.GlobalContext

func (*Global) HandleUncaughtException

func (g *Global) HandleUncaughtException(err error) error

HandleUncaughtException handles an uncaught exception by calling the user exception handler if one is registered. Returns nil if the exception was handled, or the (possibly new) error if it wasn't.

PHP behavior:

  • The exception handler is temporarily removed during invocation to prevent re-entrancy.
  • After the handler completes (successfully or not), the handler is restored.
  • If the handler throws a new exception, check if the handler registered a new handler during its execution; if so, use the new handler for the new exception (recursively).
  • If no handler is available for a thrown exception, return it as-is.

func (*Global) HasStreamHandler

func (g *Global) HasStreamHandler(scheme string) bool

HasStreamHandler checks if a scheme has a registered stream handler.

func (*Global) HasTickFunctions

func (g *Global) HasTickFunctions() bool

HasTickFunctions returns true if any tick functions are registered

func (*Global) HeaderContext

func (g *Global) HeaderContext() *phpv.HeaderContext

func (*Global) Include

func (c *Global) Include(ctx phpv.Context, fn phpv.ZString) (*phpv.ZVal, error)

func (*Global) IncludeOnce

func (c *Global) IncludeOnce(ctx phpv.Context, fn phpv.ZString) (*phpv.ZVal, error)

func (*Global) InitBaselineMemory

func (g *Global) InitBaselineMemory()

InitBaselineMemory records the current memory usage as the baseline for this Global context, so Tick() can measure per-script usage.

func (*Global) IsFunctionDisabled

func (g *Global) IsFunctionDisabled(name phpv.ZString) bool

IsObDisabled returns whether the OB system has been disabled. IsFunctionDisabled returns true if the named function is disabled via disable_functions INI.

func (*Global) IsJsonEncoding

func (g *Global) IsJsonEncoding(obj phpv.ZObject) bool

IsJsonEncoding reports whether the object is currently being json-encoded via JsonSerializable (without marking it).

func (*Global) IsObDisabled

func (g *Global) IsObDisabled() bool

func (*Global) IsUploadedFile

func (g *Global) IsUploadedFile(path string) bool

IsUploadedFile checks if the given path was registered as an uploaded file.

func (*Global) IsWithinOpenBasedir

func (g *Global) IsWithinOpenBasedir(path string) bool

IsWithinOpenBasedir checks if the given path is within the open_basedir restriction without emitting any warnings. Returns true if access would be allowed.

func (*Global) IterateConfig

func (g *Global) IterateConfig() iter.Seq2[string, phpv.IniValue]

func (*Global) LastCallable

func (g *Global) LastCallable() phpv.Callable

func (*Global) Loc

func (g *Global) Loc() *phpv.Loc

func (*Global) LogError

func (g *Global) LogError(err *phpv.PhpError, optionArg ...logopt.Data)

func (*Global) MarkJsonEncoding

func (g *Global) MarkJsonEncoding(obj phpv.ZObject) bool

MarkJsonEncoding marks an object as currently being json-encoded. Returns true if the object was already being encoded (recursion detected).

func (*Global) MemAlloc

func (g *Global) MemAlloc(ctx phpv.Context, s uint64) error

func (*Global) MemLimit

func (g *Global) MemLimit() uint64

MemLimit returns the current memory limit in bytes (0 = unlimited).

func (*Global) MemMgrTracker

func (g *Global) MemMgrTracker() phpv.MemTracker

MemMgr returns the memory manager, which implements phpv.MemTracker.

func (*Global) MemPeakUsage

func (g *Global) MemPeakUsage() int64

MemPeakUsage returns the peak tracked PHP memory usage in bytes.

func (*Global) MemResetPeak

func (g *Global) MemResetPeak()

MemResetPeak sets peak = current tracked usage.

func (*Global) MemUsage

func (g *Global) MemUsage() int64

MemUsage returns the current tracked PHP memory usage in bytes.

func (*Global) NewIterator

func (c *Global) NewIterator() phpv.ZIterator

func (*Global) NextObjectID

func (g *Global) NextObjectID() int

func (*Global) NextResourceID

func (g *Global) NextResourceID() int

func (*Global) Notice

func (g *Global) Notice(format string, a ...any) error

func (*Global) OffsetCheck

func (c *Global) OffsetCheck(ctx phpv.Context, name phpv.Val) (*phpv.ZVal, bool, error)

func (*Global) OffsetExists

func (c *Global) OffsetExists(ctx phpv.Context, name phpv.Val) (bool, error)

func (*Global) OffsetGet

func (c *Global) OffsetGet(ctx phpv.Context, name phpv.Val) (*phpv.ZVal, error)

func (*Global) OffsetSet

func (c *Global) OffsetSet(ctx phpv.Context, name phpv.Val, v *phpv.ZVal) error

func (*Global) OffsetUnset

func (c *Global) OffsetUnset(ctx phpv.Context, name phpv.Val) error

func (*Global) Open

func (g *Global) Open(ctx phpv.Context, fn phpv.ZString, mode phpv.ZString, useIncludePath bool, streamContext ...phpv.Resource) (phpv.Stream, error)

Open opens a file using PHP stream wrappers and returns a handler to said file.

func (*Global) OpenFile

func (g *Global) OpenFile(ctx phpv.Context, path string) (io.ReadCloser, error)

OpenFile opens a file for reading through the global file access layer. This centralizes file access so it can later be scoped to an fs.FS.

func (*Global) Parent

func (c *Global) Parent(n int) phpv.Context

func (*Global) Random

func (g *Global) Random() *random.State

func (*Global) RegisterAutoload

func (g *Global) RegisterAutoload(handler phpv.Callable, prepend bool)

func (*Global) RegisterClass

func (g *Global) RegisterClass(name phpv.ZString, c phpv.ZClass) error

func (*Global) RegisterDestructor

func (g *Global) RegisterDestructor(obj phpv.ZObject)

func (*Global) RegisterFunction

func (g *Global) RegisterFunction(name phpv.ZString, f phpv.Callable) error

func (*Global) RegisterLazyClass

func (g *Global) RegisterLazyClass(name phpv.ZString, r phpv.Runnables, p int)

func (*Global) RegisterLazyFunc

func (g *Global) RegisterLazyFunc(name phpv.ZString, r phpv.Runnables, p int)

func (*Global) RegisterShutdownFunction

func (g *Global) RegisterShutdownFunction(f phpv.Callable)

func (*Global) RegisterStreamHandler

func (g *Global) RegisterStreamHandler(scheme string, handler stream.Handler)

func (*Global) RegisterTempFile

func (g *Global) RegisterTempFile(path string)

RegisterTempFile registers a temporary file path for cleanup when the request ends. Used for uploaded file temp files.

func (*Global) RegisterTempObject

func (g *Global) RegisterTempObject(id int, isFree func() bool)

RegisterTempObject registers an object ID as a "temporary" that should be released if it has refcount 0 at the next statement boundary.

func (*Global) RegisterTickFunction

func (g *Global) RegisterTickFunction(cb phpv.Callable, args []*phpv.ZVal)

RegisterTickFunction adds a tick function to be called every N statements

func (*Global) RegisterUploadedFile

func (g *Global) RegisterUploadedFile(path string)

RegisterUploadedFile registers a file path as an uploaded file for is_uploaded_file() and move_uploaded_file() checks.

func (*Global) ReinitSuperglobals

func (g *Global) ReinitSuperglobals()

ReinitSuperglobals re-initializes superglobals ($_GET, $_POST, $_SERVER, etc.) based on current INI settings. Call this after changing INI settings like variables_order or register_argc_argv that affect superglobal population.

func (*Global) ReleaseObjectID

func (g *Global) ReleaseObjectID(id int)

func (*Global) Require

func (c *Global) Require(ctx phpv.Context, fn phpv.ZString) (*phpv.ZVal, error)

func (*Global) RequireOnce

func (c *Global) RequireOnce(ctx phpv.Context, fn phpv.ZString) (*phpv.ZVal, error)

func (*Global) ResetDeadline

func (g *Global) ResetDeadline()

func (*Global) RestoreConfig

func (g *Global) RestoreConfig(name phpv.ZString)

func (*Global) RestoreUserErrorHandler

func (g *Global) RestoreUserErrorHandler()

func (*Global) RestoreUserExceptionHandler

func (g *Global) RestoreUserExceptionHandler()

func (*Global) RunFile

func (g *Global) RunFile(fn string) error

func (*Global) RunShutdownFunctions

func (g *Global) RunShutdownFunctions()

func (*Global) SetAutoloadExtensions

func (g *Global) SetAutoloadExtensions(exts string)

func (*Global) SetCompilingClass

func (g *Global) SetCompilingClass(c phpv.ZClass)

func (*Global) SetDeadline

func (g *Global) SetDeadline(t time.Time)

func (*Global) SetLocalConfig

func (g *Global) SetLocalConfig(name phpv.ZString, value *phpv.ZVal) (*phpv.ZVal, bool)

func (*Global) SetNextCallSuppressCalledIn

func (g *Global) SetNextCallSuppressCalledIn(v bool)

func (*Global) SetNoDiscardPending

func (g *Global) SetNoDiscardPending(v bool)

func (*Global) SetObDisabled

func (g *Global) SetObDisabled()

SetObDisabled marks the OB system as disabled (after re-entrant fatal error).

func (*Global) SetOutput

func (g *Global) SetOutput(w io.Writer)

func (*Global) SetSerializeContext

func (g *Global) SetSerializeContext(c interface{})

SetSerializeContext sets the serialize context.

func (*Global) SetSerializeSeenObjects

func (g *Global) SetSerializeSeenObjects(m map[phpv.ZObject]bool)

SetSerializeSeenObjects sets the serialize object tracking map.

func (*Global) SetSkipNextDynPropDeprecation

func (g *Global) SetSkipNextDynPropDeprecation(v bool)

func (*Global) SetStdin

func (g *Global) SetStdin(r io.Reader)

SetStdin replaces the default stdin with a custom reader (useful for testing).

func (*Global) SetStrictTypes

func (g *Global) SetStrictTypes(v bool)

SetStrictTypes sets the strict_types flag for the current execution context.

func (*Global) SetUserErrorHandler

func (g *Global) SetUserErrorHandler(handler phpv.Callable, filter phpv.PhpErrorType, originalVal *phpv.ZVal)

func (*Global) SetUserExceptionHandler

func (g *Global) SetUserExceptionHandler(handler phpv.Callable, originalVal *phpv.ZVal) *phpv.ZVal

SetUserExceptionHandler sets the exception handler and returns the original ZVal of the previous handler (so that set_exception_handler can return it).

func (*Global) Setenv

func (g *Global) Setenv(key, value string) error

func (*Global) ShownDeprecated

func (g *Global) ShownDeprecated(key string) bool

func (*Global) TakeSkipNextDynPropDeprecation

func (g *Global) TakeSkipNextDynPropDeprecation() bool

func (*Global) This

func (g *Global) This() phpv.ZObject

func (*Global) Tick

func (g *Global) Tick(ctx phpv.Context, l *phpv.Loc) error

func (*Global) UnmarkJsonEncoding

func (g *Global) UnmarkJsonEncoding(obj phpv.ZObject)

UnmarkJsonEncoding removes the json-encoding mark from an object.

func (*Global) UnregisterAutoload

func (g *Global) UnregisterAutoload(handler phpv.Callable) bool

func (*Global) UnregisterAutoloadByName

func (g *Global) UnregisterAutoloadByName(name string) bool

func (*Global) UnregisterClass

func (g *Global) UnregisterClass(name phpv.ZString)

func (*Global) UnregisterDestructor

func (g *Global) UnregisterDestructor(obj phpv.ZObject)

func (*Global) UnregisterStreamHandler

func (g *Global) UnregisterStreamHandler(scheme string) bool

func (*Global) UnregisterTickFunction

func (g *Global) UnregisterTickFunction(cb phpv.Callable)

UnregisterTickFunction removes a tick function by callable identity

func (*Global) UnregisterUploadedFile

func (g *Global) UnregisterUploadedFile(path string)

UnregisterUploadedFile removes a file from the uploaded files set (after move).

func (*Global) Unsetenv

func (g *Global) Unsetenv(key string) error

func (*Global) UserDeprecated

func (g *Global) UserDeprecated(format string, a ...any) error

func (*Global) Warn

func (g *Global) Warn(format string, a ...any) error

func (*Global) WarnDeprecated

func (g *Global) WarnDeprecated() error

func (*Global) Write

func (g *Global) Write(v []byte) (int, error)

func (*Global) WriteErr

func (g *Global) WriteErr(v []byte) (int, error)

func (*Global) WriteStartupWarning

func (g *Global) WriteStartupWarning(msg string)

WriteStartupWarning buffers a warning message emitted during request startup (before output is configured). These warnings are flushed on first Write.

type MemMgr

type MemMgr struct {
	// contains filtered or unexported fields
}

func NewMemMgr

func NewMemMgr(limit int64) *MemMgr

func (*MemMgr) Alloc

func (m *MemMgr) Alloc(size int64) error

Alloc tracks a new PHP-level allocation of size bytes. Returns a fatal PhpError if the allocation would exceed the memory limit.

func (*MemMgr) Copy

func (m *MemMgr) Copy(dst io.Writer, src io.Reader) (written int64, err error)

Copy copies data from src to dst while tracking memory usage.

func (*MemMgr) Free

func (m *MemMgr) Free(size int64)

Free releases a previously tracked allocation.

func (*MemMgr) Limit

func (m *MemMgr) Limit() int64

Limit returns the current memory limit in bytes (0 = unlimited).

func (*MemMgr) MemAlloc

func (m *MemMgr) MemAlloc(size int64) error

MemAlloc implements phpv.MemTracker interface.

func (*MemMgr) MemFree

func (m *MemMgr) MemFree(size int64)

MemFree implements phpv.MemTracker interface.

func (*MemMgr) PeakUsage

func (m *MemMgr) PeakUsage() int64

PeakUsage returns the peak tracked memory usage in bytes.

func (*MemMgr) ResetPeak

func (m *MemMgr) ResetPeak()

ResetPeak sets peak = current tracked usage.

func (*MemMgr) SetLimit

func (m *MemMgr) SetLimit(limit int64)

SetLimit updates the memory limit. A limit of 0 or -1 means unlimited.

func (*MemMgr) Usage

func (m *MemMgr) Usage() int64

Usage returns the current tracked memory usage in bytes.

type OpenContext

type OpenContext int

type Process

type Process struct {
	ScriptFilename string
	Argv           []string
	Options        *ProcessOptions
	// contains filtered or unexported fields
}

func NewProcess

func NewProcess(sapi string) *Process

NewProcess instanciates a new instance of Process, which represents a running PHP process.

func (*Process) CommandLine

func (p *Process) CommandLine(args []string) error

CommandLine will parse arguments from the command line and configure the process accordingly. If nil is passed, then the actual command line will be parsed. In case of error, messages will be sent to stderr by default.

func (*Process) Handler

func (p *Process) Handler(docroot string, iniCfg phpv.IniConfig) http.Handler

Hander returns a http.Handler object suitable for use with golang standard http servers and similar.

func (*Process) SetConstant

func (p *Process) SetConstant(name, value phpv.ZString)

SetConstant sets a global constant, typically used to set PHP_SAPI.

func (*Process) SetEnv

func (p *Process) SetEnv(key, value string)

SetEnv sets an environment variable on the process before a Global is created.

type ProcessOptions

type ProcessOptions struct {
	RunCode    string
	NoIniFile  bool
	IniFile    string
	IniEntries map[string]string
}

Jump to

Keyboard shortcuts

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