Documentation

Context
in package

The Shell execution context.

This class encapsulates the current variables, most recent return value and exception, and the current namespace.

Table of Contents

$boundClass  : mixed
$boundObject  : mixed
$commandScopeNames  : mixed
$commandScopeVariables  : mixed
$lastException  : mixed
$lastStdout  : mixed
$returnValue  : mixed
$scopeVariables  : mixed
$specialNames  : mixed
get()  : mixed
Get a context variable.
getAll()  : array<string|int, mixed>
Get all defined variables.
getBoundClass()  : string|null
Get the bound class (self) for the interactive shell.
getBoundObject()  : object|null
Get the bound object ($this variable) for the interactive shell.
getCommandScopeVariables()  : array<string|int, mixed>
Get command-scope magic variables: $__class, $__file, etc.
getLastException()  : null|Exception
Get the most recent Exception.
getLastStdout()  : null|string
Get the most recent output from evaluated code.
getReturnValue()  : mixed
Get the most recent return value.
getSpecialVariables()  : array<string|int, mixed>
Get all defined magic variables: $_, $_e, $__out, $__class, $__file, etc.
getUnusedCommandScopeVariableNames()  : array<string|int, mixed>
Get unused command-scope magic variables names: __class, __file, etc.
isSpecialVariableName()  : bool
Check whether a variable name is a magic variable.
setAll()  : mixed
Set all scope variables.
setBoundClass()  : mixed
Set the bound class (self) for the interactive shell.
setBoundObject()  : mixed
Set the bound object ($this variable) for the interactive shell.
setCommandScopeVariables()  : mixed
Set command-scope magic variables: $__class, $__file, etc.
setLastException()  : mixed
Set the most recent Exception.
setLastStdout()  : mixed
Set the most recent output from evaluated code.
setReturnValue()  : mixed
Set the most recent return value.

Properties

$boundClass

private mixed $boundClass

$boundObject

private mixed $boundObject

$commandScopeNames

private static mixed $commandScopeNames = ['__function', '__method', '__class', '__namespace', '__file', '__line', '__dir']

$commandScopeVariables

private mixed $commandScopeVariables = []

$lastException

private mixed $lastException

$lastStdout

private mixed $lastStdout

$returnValue

private mixed $returnValue

$scopeVariables

private mixed $scopeVariables = []

$specialNames

private static mixed $specialNames = ['_', '_e', '__out', '__psysh__', 'this']

Methods

get()

Get a context variable.

public get(string $name) : mixed
Parameters
$name : string
Tags
throws
InvalidArgumentException

If the variable is not found in the current context

Return values
mixed

getAll()

Get all defined variables.

public getAll() : array<string|int, mixed>
Return values
array<string|int, mixed>

getBoundClass()

Get the bound class (self) for the interactive shell.

public getBoundClass() : string|null
Return values
string|null

getBoundObject()

Get the bound object ($this variable) for the interactive shell.

public getBoundObject() : object|null
Return values
object|null

getCommandScopeVariables()

Get command-scope magic variables: $__class, $__file, etc.

public getCommandScopeVariables() : array<string|int, mixed>
Return values
array<string|int, mixed>

getLastException()

Get the most recent Exception.

public getLastException() : null|Exception
Tags
throws
InvalidArgumentException

If no Exception has been caught

Return values
null|Exception

getLastStdout()

Get the most recent output from evaluated code.

public getLastStdout() : null|string
Tags
throws
InvalidArgumentException

If no output has happened yet

Return values
null|string

getReturnValue()

Get the most recent return value.

public getReturnValue() : mixed
Return values
mixed

getSpecialVariables()

Get all defined magic variables: $_, $_e, $__out, $__class, $__file, etc.

public getSpecialVariables() : array<string|int, mixed>
Return values
array<string|int, mixed>

getUnusedCommandScopeVariableNames()

Get unused command-scope magic variables names: __class, __file, etc.

public getUnusedCommandScopeVariableNames() : array<string|int, mixed>

This is used by the shell to unset old command-scope variables after a new batch is set.

Return values
array<string|int, mixed>

Array of unused variable names

isSpecialVariableName()

Check whether a variable name is a magic variable.

public static isSpecialVariableName(string $name) : bool
Parameters
$name : string
Return values
bool

setAll()

Set all scope variables.

public setAll(array<string|int, mixed> $vars) : mixed

This method does not set any of the magic variables: $_, $_e, $__out, $__class, $__file, etc.

Parameters
$vars : array<string|int, mixed>
Return values
mixed

setBoundClass()

Set the bound class (self) for the interactive shell.

public setBoundClass(string|null $boundClass) : mixed

Note that this unsets the bound object, if any exists.

Parameters
$boundClass : string|null
Return values
mixed

setBoundObject()

Set the bound object ($this variable) for the interactive shell.

public setBoundObject(object|null $boundObject) : mixed

Note that this unsets the bound class, if any exists.

Parameters
$boundObject : object|null
Return values
mixed

setCommandScopeVariables()

Set command-scope magic variables: $__class, $__file, etc.

public setCommandScopeVariables(array<string|int, mixed> $commandScopeVariables) : mixed
Parameters
$commandScopeVariables : array<string|int, mixed>
Return values
mixed

setLastException()

Set the most recent Exception.

public setLastException(Exception $e) : mixed
Parameters
$e : Exception
Return values
mixed

setLastStdout()

Set the most recent output from evaluated code.

public setLastStdout(string $lastStdout) : mixed
Parameters
$lastStdout : string
Return values
mixed

setReturnValue()

Set the most recent return value.

public setReturnValue(mixed $value) : mixed
Parameters
$value : mixed
Return values
mixed

Search results