PHPSandbox

PHPSandbox
in package
implements IteratorAggregate

PHPSandbox class for PHP Sandboxes.

This class encapsulates the entire functionality of a PHPSandbox so that an end user only has to create a PHPSandbox instance, configure its options, and run their code

Tags
namespace

PHPSandbox

author

Elijah Horton [email protected]

version
3.0

Interfaces, Classes and Traits

IteratorAggregate

Table of Contents

IMPORT_ALL  = 0
IMPORT_BLACKLIST  = 8
IMPORT_CODE  = 32
IMPORT_DEFINITIONS  = 2
IMPORT_OPTIONS  = 1
IMPORT_TRUSTED_CODE  = 16
IMPORT_WHITELIST  = 4
SANDBOX_PREFIX  = '__PHPSandbox_'
$allow_aliases  : bool
$allow_backticks  : bool
$allow_casting  : bool
$allow_classes  : bool
$allow_closures  : bool
$allow_constants  : bool
$allow_error_suppressing  : bool
$allow_escaping  : bool
$allow_functions  : bool
$allow_generators  : bool
$allow_globals  : bool
$allow_halting  : bool
$allow_includes  : bool
$allow_interfaces  : bool
$allow_namespaces  : bool
$allow_objects  : bool
$allow_references  : bool
$allow_static_variables  : bool
$allow_traits  : bool
$allow_variables  : bool
$arg_funcs  : array<string|int, mixed>
$auto_define_vars  : bool
$auto_whitelist_classes  : bool
$auto_whitelist_constants  : bool
$auto_whitelist_functions  : bool
$auto_whitelist_globals  : bool
$auto_whitelist_interfaces  : bool
$auto_whitelist_traits  : bool
$auto_whitelist_trusted_code  : bool
$capture_output  : bool
$convert_errors  : bool
$defined_funcs  : array<string|int, mixed>
$error_level  : int|null
$magic_constants  : array<string|int, mixed>
$name  : string
$overwrite_defined_funcs  : bool
$overwrite_func_get_args  : bool
$overwrite_sandboxed_string_funcs  : bool
$overwrite_superglobals  : bool
$restore_error_level  : bool
$sandbox_includes  : bool
$sandbox_strings  : bool
$sandboxed_string_funcs  : array<string|int, mixed>
$superglobals  : array<string|int, mixed>
$time_limit  : int
$validate_aliases  : bool
$validate_classes  : bool
$validate_constants  : bool
$validate_functions  : bool
$validate_globals  : bool
$validate_interfaces  : bool
$validate_keywords  : bool
$validate_magic_constants  : bool
$validate_namespaces  : bool
$validate_operators  : bool
$validate_primitives  : bool
$validate_superglobals  : bool
$validate_traits  : bool
$validate_types  : bool
$validate_variables  : bool
$appended_code  : string
$blacklist  : array<string|int, mixed>
$definitions  : array<string|int, mixed>
$error_handler  : callable|null
$error_handler_types  : int
$exception_handler  : callable|null
$executing_file  : string|null
$execution_time  : float
$generated_code  : string
$includes  : array<string|int, mixed>
$last_error  : array<string|int, mixed>|null
$last_exception  : Throwable|null
$last_validation_error  : Throwable|null
$memory_usage  : int
$parsed_ast  : array<string|int, mixed>
$prepare_time  : float
$prepared_ast  : array<string|int, mixed>
$prepared_code  : string
$preparsed_code  : string
$prepended_code  : string
$sandboxes  : array<string|int, mixed>
$validation  : array<string|int, mixed>
$validation_error_handler  : callable|null
$whitelist  : array<string|int, mixed>
__call()  : mixed
Magic method to provide API compatibility for v1.* code
__construct()  : mixed
PHPSandbox class constructor
__invoke()  : mixed
PHPSandbox __invoke magic method
__sleep()  : array<string|int, mixed>
PHPSandbox __sleep magic method
_array_key_exists()  : bool
Get PHPSandbox redefined array_key_exists
_arrayval()  : array<string|int, mixed>
Return array value of SandboxedString or mixed value
_boolval()  : bool
Return boolean value of SandboxedString or mixed value
_floatval()  : float
Return float value of SandboxedString or mixed value
_func_get_arg()  : mixed
Get PHPSandbox redefined function argument
_func_get_args()  : array<string|int, mixed>
Get PHPSandbox redefined function arguments array
_func_num_args()  : int
Get PHPSandbox redefined number of function arguments
_get_declared_classes()  : array<string|int, mixed>
Get PHPSandbox redefined classes in place of get_declared_classes(). This is an internal PHPSandbox function but requires public access to work.
_get_declared_interfaces()  : array<string|int, mixed>
Get PHPSandbox redefined interfaces in place of get_declared_interfaces(). This is an internal PHPSandbox function but requires public access to work.
_get_declared_traits()  : array<string|int, mixed>
Get PHPSandbox redefined traits in place of get_declared_traits(). This is an internal PHPSandbox function but requires public access to work.
_get_defined_constants()  : array<string|int, mixed>
Get PHPSandbox redefined constants in place of get_defined_constants(). This is an internal PHPSandbox function but requires public access to work.
_get_defined_functions()  : array<string|int, mixed>
Get PHPSandbox redefined functions in place of get_defined_functions(). This is an internal PHPSandbox function but requires public access to work.
_get_defined_vars()  : array<string|int, mixed>
Get PHPSandbox redefined variables in place of get_defined_vars(). This is an internal PHPSandbox function but requires public access to work.
_get_included_files()  : array<string|int, mixed>
Return get_included_files() and sandboxed included files
_get_magic_const()  : mixed
Get PHPSandbox redefined magic constant. This is an internal PHPSandbox function but requires public access to work.
_get_superglobal()  : array<string|int, mixed>
Get PHPSandbox redefined superglobal. This is an internal PHPSandbox function but requires public access to work.
_include()  : mixed
Sandbox included file
_include_once()  : mixed
Sandbox included once file
_intval()  : int
Return integer value of SandboxedString or mixed value
_is_callable()  : bool
Return is_callable value of SandboxedString or mixed value
_is_object()  : bool
Return is_object value of SandboxedString or mixed value
_is_scalar()  : bool
Return is_scalar value of SandboxedString or mixed value
_is_string()  : bool
Return is_string value of SandboxedString or mixed value
_objectval()  : object
Return object value of SandboxedString or mixed value
_print_r()  : bool|string
Get PHPSandbox redefined print_r
_require()  : mixed
Sandbox required file
_require_once()  : mixed
Sandbox required once file
_var_dump()  : void
Get PHPSandbox redefined var_dump
_var_export()  : string|null
Get PHPSandbox redefined var_export
append()  : PHPSandbox
Append trusted code
auto_define()  :
auto_whitelist()  :
blacklist()  : PHPSandbox
Blacklist PHPSandbox definitions, such as functions, constants, classes, etc. to set
blacklist_alias()  :
blacklist_class()  :
blacklist_const()  :
blacklist_func()  :
blacklist_global()  :
blacklist_interface()  :
blacklist_keyword()  :
blacklist_magic_const()  :
blacklist_namespace()  :
blacklist_operator()  :
blacklist_primitive()  :
blacklist_superglobal()  :
blacklist_trait()  :
blacklist_type()  :
blacklist_use()  :
blacklist_var()  :
blacklistAlias()  : PHPSandbox
Blacklist alias
blacklistClass()  : PHPSandbox
Blacklist class
blacklistConst()  : PHPSandbox
Blacklist constant
blacklistFunc()  : PHPSandbox
Blacklist function
blacklistGlobal()  : PHPSandbox
Blacklist global
blacklistInterface()  : PHPSandbox
Blacklist interface
blacklistKeyword()  : PHPSandbox
Blacklist keyword
blacklistMagicConst()  : PHPSandbox
Blacklist magic constant
blacklistNamespace()  : PHPSandbox
Blacklist namespace
blacklistOperator()  : PHPSandbox
Blacklist operator
blacklistPrimitive()  : PHPSandbox
Blacklist primitive
blacklistSuperglobal()  : PHPSandbox
Blacklist superglobal or superglobal key * You can pass a string of the superglobal name, or a string of the superglobal name and a string of the key, or pass an array of superglobal names, or an associative array of superglobal names and their keys to blacklist
blacklistTrait()  : PHPSandbox
Blacklist trait
blacklistType()  : PHPSandbox
Blacklist type
blacklistUse()  : PHPSandbox
Blacklist use (or alias)
blacklistVar()  : PHPSandbox
Blacklist variable
call_func()  : mixed
Get PHPSandbox redefined function. This is an internal PHPSandbox function but requires public access to work.
check_alias()  :
check_class()  :
check_const()  :
check_func()  :
check_global()  :
check_interface()  :
check_keyword()  :
check_magic_const()  :
check_namespace()  :
check_operator()  :
check_primitive()  :
check_superglobal()  :
check_trait()  :
check_type()  :
check_use()  :
check_var()  :
checkAlias()  : bool
Check alias name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.
checkClass()  : bool
Check class name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.
checkConst()  : bool
Check constant name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.
checkFunc()  : bool
Check function name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.
checkGlobal()  : bool
Check global name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.
checkInterface()  : bool
Check interface name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.
checkKeyword()  : bool
Check keyword name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.
checkMagicConst()  : bool
Check magic constant name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.
checkNamespace()  : bool
Check namespace name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.
checkOperator()  : bool
Check operator name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.
checkPrimitive()  : bool
Check primitive name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.
checkSuperglobal()  : bool
Check superglobal name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.
checkTrait()  : bool
Check trait name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.
checkType()  : bool
Check type name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.
checkUse()  : bool
Check use (or alias) name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.
checkVar()  : bool
Check variable name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.
clear()  : PHPSandbox
Clear all trusted and sandboxed code
clear_append()  :
clear_code()  :
clear_prepend()  :
clear_trusted_code()  :
clearAppend()  : PHPSandbox
Clear all appended trusted code
clearAppendedCode()  : PHPSandbox
Clear all appended trusted code
clearCode()  : PHPSandbox
Clear generated code
clearPrepended()  : PHPSandbox
Clear all prepended trusted code
clearPrependedCode()  : PHPSandbox
Clear all prepended trusted code
clearTrustedCode()  : PHPSandbox
Clear all trusted code
create()  : PHPSandbox
PHPSandbox static factory method
deblacklist()  : PHPSandbox
Remove PHPSandbox definitions, such as functions, constants, classes, etc. from blacklist
deblacklist_alias()  :
deblacklist_class()  :
deblacklist_const()  :
deblacklist_func()  :
deblacklist_global()  :
deblacklist_interface()  :
deblacklist_keyword()  :
deblacklist_magic_const()  :
deblacklist_namespace()  :
deblacklist_operator()  :
deblacklist_primitive()  :
deblacklist_superglobal()  :
deblacklist_trait()  :
deblacklist_type()  :
deblacklist_use()  :
deblacklist_var()  :
deblacklistAlias()  : PHPSandbox
Remove alias from blacklist
deblacklistClass()  : PHPSandbox
Remove class from blacklist
deblacklistConst()  : PHPSandbox
Remove constant from blacklist
deblacklistFunc()  : PHPSandbox
Remove function from blacklist
deblacklistGlobal()  : PHPSandbox
Remove global from blacklist
deblacklistInterface()  : PHPSandbox
Remove interface from blacklist
deblacklistKeyword()  : PHPSandbox
Remove keyword from blacklist
deblacklistMagicConst()  : PHPSandbox
Remove magic constant from blacklist
deblacklistNamespace()  : PHPSandbox
Remove namespace from blacklist
deblacklistOperator()  : PHPSandbox
Remove operator from blacklist
deblacklistPrimitive()  : PHPSandbox
Remove primitive from blacklist
deblacklistSuperglobal()  : PHPSandbox
Remove superglobal or superglobal key from blacklist * You can pass a string of the superglobal name, or a string of the superglobal name and a string of the key, or pass an array of superglobal names, or an associative array of superglobal names and their keys to remove from blacklist
deblacklistTrait()  : PHPSandbox
Remove trait from blacklist
deblacklistType()  : PHPSandbox
Remove type from blacklist
deblacklistUse()  : PHPSandbox
Remove use (or alias) from blacklist
deblacklistVar()  : PHPSandbox
Remove function from blacklist
define()  : PHPSandbox
Define PHPSandbox definitions, such as functions, constants, namespaces, etc.
define_alias()  :
define_aliases()  :
define_class()  :
define_classes()  :
define_const()  :
define_consts()  :
define_func()  :
define_funcs()  :
define_interface()  :
define_interfaces()  :
define_magic_const()  :
define_magic_consts()  :
define_namespace()  :
define_namespaces()  :
define_superglobal()  :
define_superglobals()  :
define_trait()  :
define_traits()  :
define_use()  :
define_uses()  :
define_var()  :
define_vars()  :
defineAlias()  : PHPSandbox
Define PHPSandbox alias
defineAliases()  : PHPSandbox
Define PHPSandbox aliases by array
defineClass()  : PHPSandbox
Define PHPSandbox class
defineClasses()  : PHPSandbox
Define PHPSandbox classes by array
defineConst()  : PHPSandbox
Define PHPSandbox constant
defineConsts()  : PHPSandbox
Define PHPSandbox constants by array
defineFunc()  : PHPSandbox
Define PHPSandbox function
defineFuncs()  : PHPSandbox
Define PHPSandbox functions by array
defineInterface()  : PHPSandbox
Define PHPSandbox interface
defineInterfaces()  : PHPSandbox
Define PHPSandbox interfaces by array
defineMagicConst()  : PHPSandbox
Define PHPSandbox magic constant
defineMagicConsts()  : PHPSandbox
Define PHPSandbox magic constants by array
defineNamespace()  : PHPSandbox
Define PHPSandbox namespace
defineNamespaces()  : PHPSandbox
Define PHPSandbox namespaces by array
defineSuperglobal()  : PHPSandbox
Define PHPSandbox superglobal
defineSuperglobals()  : PHPSandbox
Define PHPSandbox superglobals by array
defineTrait()  : PHPSandbox
Define PHPSandbox trait
defineTraits()  : PHPSandbox
Define PHPSandbox traits by array
defineUse()  : PHPSandbox
Define PHPSandbox use (or alias)
defineUses()  : PHPSandbox
Define PHPSandbox uses (or aliases) by array
defineVar()  : PHPSandbox
Define PHPSandbox variable
defineVars()  : PHPSandbox
Define PHPSandbox variables by array
dewhitelist()  : PHPSandbox
Remove PHPSandbox definitions, such as functions, constants, classes, etc. from whitelist
dewhitelist_alias()  :
dewhitelist_class()  :
dewhitelist_const()  :
dewhitelist_func()  :
dewhitelist_global()  :
dewhitelist_interface()  :
dewhitelist_keyword()  :
dewhitelist_magic_const()  :
dewhitelist_namespace()  :
dewhitelist_operator()  :
dewhitelist_primitive()  :
dewhitelist_superglobal()  :
dewhitelist_trait()  :
dewhitelist_type()  :
dewhitelist_use()  :
dewhitelist_var()  :
dewhitelistAlias()  : PHPSandbox
Remove alias from whitelist
dewhitelistClass()  : PHPSandbox
Remove class from whitelist
dewhitelistConst()  : PHPSandbox
Remove constant from whitelist
dewhitelistFunc()  : PHPSandbox
Remove function from whitelist
dewhitelistGlobal()  : PHPSandbox
Remove global from whitelist
dewhitelistInterface()  : PHPSandbox
Remove interface from whitelist
dewhitelistKeyword()  : PHPSandbox
Remove keyword from whitelist
dewhitelistMagicConst()  : PHPSandbox
Remove magic constant from whitelist
dewhitelistNamespace()  : PHPSandbox
Remove namespace from whitelist
dewhitelistOperator()  : PHPSandbox
Remove operator from whitelist
dewhitelistPrimitive()  : PHPSandbox
Remove primitive from whitelist
dewhitelistSuperglobal()  : PHPSandbox
Remove superglobal or superglobal key from whitelist * You can pass a string of the superglobal name, or a string of the superglobal name and a string of the key, or pass an array of superglobal names, or an associative array of superglobal names and their keys to remove from whitelist
dewhitelistTrait()  : PHPSandbox
Remove trait from whitelist
dewhitelistType()  : PHPSandbox
Remove type from whitelist
dewhitelistUse()  : PHPSandbox
Remove use (or alias) from whitelist
dewhitelistVar()  : PHPSandbox
Remove variable from whitelist
error()  : mixed
Invoke sandbox error handler
exception()  : mixed
Invoke sandbox exception handler
execute()  : mixed
Prepare and execute callable and return output
get_defined_class()  :
get_defined_interface()  :
get_defined_namespace()  :
get_defined_trait()  :
get_error_handler()  :
get_exception_handler()  :
get_execution_time()  :
get_last_error()  :
get_last_exception()  :
get_last_validation_error()  :
get_prepared_time()  :
get_time()  :
get_validation_error_handler()  :
getAliasValidator()  : callable|null
Get validation callable for aliases
getAppendedCode()  : string
Get PHPSandbox appended code
getClassValidator()  : callable|null
Get validation callable for classes
getCode()  : string
Get PHPSandbox generated code
getConstValidator()  : callable|null
Get validation callable for constants
getDefinedClass()  : string
Get defined class of $name
getDefinedInterface()  : string
Get defined interface of $name
getDefinedNamespace()  : string
Get defined namespace of $name
getDefinedTrait()  : string
Get defined trait of $name
getErrorHandler()  : callable|null
Get error handler
getExceptionHandler()  : callable|null
Get exception handler
getExecutingFile()  : string|null
Return the current file being executed in the sandbox
getExecutionTime()  : float
Return the amount of time the sandbox spent executing the sandboxed code
getFuncValidator()  : callable|null
Get validation for functions
getGeneratedCode()  : string
Get PHPSandbox generated code
getGlobalValidator()  : callable|null
Get validation callable for globals
getInterfaceValidator()  : callable|null
Get validation callable for interfaces
getIterator()  : ArrayIterator
Get an iterator of all the public PHPSandbox properties
getKeywordValidator()  : callable|null
Get validation callable for keywords
getLastError()  : array<string|int, mixed>|null
Gets the last sandbox error
getLastException()  : Throwable|null
Gets the last exception thrown by the sandbox
getLastValidationError()  : Throwable|null
Gets the last validation error thrown by the sandbox
getMagicConstValidator()  : callable|null
Get validation callable for magic constants
getMemoryUsage()  : float
Return the amount of bytes the sandbox allocated while preparing and executing the sandboxed code
getName()  : string
Get name of PHPSandbox variable
getNamespaceValidator()  : callable|null
Get validation callable for namespaces
getOperatorValidator()  : callable|null
Get validation callable for operators
getOption()  : bool|int|null
Get PHPSandbox option
getParsedAST()  : array<string|int, mixed>
Get PHPSandbox parsed AST array
getPreparedAST()  : array<string|int, mixed>
Get PHPSandbox prepared AST array
getPreparedCode()  : string
Get PHPSandbox prepared code
getPreparedTime()  : float
Return the amount of time the sandbox spent preparing the sandboxed code
getPreparsedCode()  : string
Get PHPSandbox preparsed code
getPrependedCode()  : string
Get PHPSandbox prepended code
getPrimitiveValidator()  : callable|null
Get validation callable for primitives
getSandbox()  : PHPSandbox|null
Get a named PHPSandbox instance (used to retrieve the sandbox instance from within sandboxed code)
getSuperglobalValidator()  : callable|null
Get validation callable for superglobals
getTime()  : float
Return the amount of time the sandbox spent preparing and executing the sandboxed code
getTraitValidator()  : callable|null
Get validation callable for traits
getTypeValidator()  : callable|null
Get validation callable for types
getUseValidator()  : callable|null
Get validation callable for uses (aka aliases)
getValidationErrorHandler()  : callable|null
Get validation error handler
getValidator()  : callable|null
Get validation callable for specified $type
getVarValidator()  : callable|null
Get validation callable for variables
has_blacklist()  :
has_blacklist_aliases()  :
has_blacklist_classes()  :
has_blacklist_consts()  :
has_blacklist_funcs()  :
has_blacklist_globals()  :
has_blacklist_interfaces()  :
has_blacklist_keywords()  :
has_blacklist_magic_consts()  :
has_blacklist_namespaces()  :
has_blacklist_operators()  :
has_blacklist_primitives()  :
has_blacklist_superglobals()  :
has_blacklist_traits()  :
has_blacklist_types()  :
has_blacklist_uses()  :
has_blacklist_vars()  :
has_defined_aliases()  :
has_defined_classes()  :
has_defined_consts()  :
has_defined_funcs()  :
has_defined_interfaces()  :
has_defined_magic_consts()  :
has_defined_namespaces()  :
has_defined_superglobals()  :
has_defined_traits()  :
has_defined_uses()  :
has_defined_vars()  :
has_whitelist()  :
has_whitelist_aliases()  :
has_whitelist_classes()  :
has_whitelist_consts()  :
has_whitelist_funcs()  :
has_whitelist_globals()  :
has_whitelist_interfaces()  :
has_whitelist_keywords()  :
has_whitelist_magic_consts()  :
has_whitelist_namespaces()  :
has_whitelist_operators()  :
has_whitelist_primitives()  :
has_whitelist_superglobals()  :
has_whitelist_traits()  :
has_whitelist_types()  :
has_whitelist_uses()  :
has_whitelist_vars()  :
hasBlacklist()  : int
Query whether PHPSandbox instance has blacklist type.
hasBlacklistedAliases()  : int
Query whether PHPSandbox instance has blacklisted aliases.
hasBlacklistedClasses()  : int
Query whether PHPSandbox instance has blacklisted classes.
hasBlacklistedConsts()  : int
Query whether PHPSandbox instance has blacklisted constants.
hasBlacklistedFuncs()  : int
Query whether PHPSandbox instance has blacklisted functions.
hasBlacklistedGlobals()  : int
Query whether PHPSandbox instance has blacklisted globals.
hasBlacklistedInterfaces()  : int
Query whether PHPSandbox instance has blacklisted interfaces.
hasBlacklistedKeywords()  : int
Query whether PHPSandbox instance has blacklisted keywords.
hasBlacklistedMagicConsts()  : int
Query whether PHPSandbox instance has blacklisted magic constants.
hasBlacklistedNamespaces()  : int
Query whether PHPSandbox instance has blacklisted namespaces.
hasBlacklistedOperators()  : int
Query whether PHPSandbox instance has blacklisted operators.
hasBlacklistedPrimitives()  : int
Query whether PHPSandbox instance has blacklisted primitives.
hasBlacklistedSuperglobals()  : int
Query whether PHPSandbox instance has blacklisted superglobals, or superglobal keys
hasBlacklistedTraits()  : int
Query whether PHPSandbox instance has blacklisted traits.
hasBlacklistedTypes()  : int
Query whether PHPSandbox instance has blacklisted types.
hasBlacklistedUses()  : int
Query whether PHPSandbox instance has blacklisted uses (or aliases.)
hasBlacklistedVars()  : int
Query whether PHPSandbox instance has blacklisted variables.
hasDefinedAliases()  : int
Query whether PHPSandbox instance has defined aliases
hasDefinedClasses()  : int
Query whether PHPSandbox instance has defined classes
hasDefinedConsts()  : int
Query whether PHPSandbox instance has defined constants
hasDefinedFuncs()  : int
Query whether PHPSandbox instance has defined functions
hasDefinedInterfaces()  : int
Query whether PHPSandbox instance has defined interfaces
hasDefinedMagicConsts()  : int
Query whether PHPSandbox instance has defined magic constants
hasDefinedNamespaces()  : int
Query whether PHPSandbox instance has defined namespaces
hasDefinedSuperglobals()  : int
Query whether PHPSandbox instance has defined superglobals, or if superglobal $name has defined keys
hasDefinedTraits()  : int
Query whether PHPSandbox instance has defined traits
hasDefinedUses()  : int
Query whether PHPSandbox instance has defined uses (or aliases)
hasDefinedVars()  : int
Query whether PHPSandbox instance has defined variables
hasWhitelist()  : int
Query whether PHPSandbox instance has whitelist type
hasWhitelistedAliases()  : int
Query whether PHPSandbox instance has whitelisted aliases.
hasWhitelistedClasses()  : int
Query whether PHPSandbox instance has whitelisted classes.
hasWhitelistedConsts()  : int
Query whether PHPSandbox instance has whitelisted constants.
hasWhitelistedFuncs()  : int
Query whether PHPSandbox instance has whitelisted functions.
hasWhitelistedGlobals()  : int
Query whether PHPSandbox instance has whitelisted globals.
hasWhitelistedInterfaces()  : int
Query whether PHPSandbox instance has whitelisted interfaces.
hasWhitelistedMagicConsts()  : int
Query whether PHPSandbox instance has whitelisted magic constants.
hasWhitelistedNamespaces()  : int
Query whether PHPSandbox instance has whitelisted namespaces.
hasWhitelistedOperators()  : int
Query whether PHPSandbox instance has whitelisted operators.
hasWhitelistedPrimitives()  : int
Query whether PHPSandbox instance has whitelisted primitives.
hasWhitelistedSuperglobals()  : int
Query whether PHPSandbox instance has whitelisted superglobals, or superglobal keys
hasWhitelistedTraits()  : int
Query whether PHPSandbox instance has whitelisted traits.
hasWhitelistedTypes()  : int
Query whether PHPSandbox instance has whitelisted types.
hasWhitelistedUses()  : int
Query whether PHPSandbox instance has whitelisted uses (or aliases.)
hasWhitelistedVars()  : int
Query whether PHPSandbox instance has whitelisted variables.
hasWhitelistKeywords()  : int
Query whether PHPSandbox instance has whitelisted keywords.
import()  : PHPSandbox
PHPSandbox __wakeup magic method
importJSON()  : PHPSandbox
Import JSON template into sandbox
is_blacklisted()  :
is_blacklisted_alias()  :
is_blacklisted_class()  :
is_blacklisted_const()  :
is_blacklisted_func()  :
is_blacklisted_global()  :
is_blacklisted_interface()  :
is_blacklisted_keyword()  :
is_blacklisted_magic_const()  :
is_blacklisted_namespace()  :
is_blacklisted_operator()  :
is_blacklisted_primitive()  :
is_blacklisted_superglobal()  :
is_blacklisted_trait()  :
is_blacklisted_type()  :
is_blacklisted_use()  :
is_blacklisted_var()  :
is_defined_alias()  :
is_defined_class()  :
is_defined_const()  :
is_defined_func()  :
is_defined_interface()  :
is_defined_magic_const()  :
is_defined_namespace()  :
is_defined_superglobal()  :
is_defined_trait()  :
is_defined_use()  :
is_defined_var()  :
is_whitelisted()  :
is_whitelisted_alias()  :
is_whitelisted_class()  :
is_whitelisted_const()  :
is_whitelisted_func()  :
is_whitelisted_global()  :
is_whitelisted_interface()  :
is_whitelisted_keyword()  :
is_whitelisted_magic_const()  :
is_whitelisted_namespace()  :
is_whitelisted_operator()  :
is_whitelisted_primitive()  :
is_whitelisted_superglobal()  :
is_whitelisted_trait()  :
is_whitelisted_type()  :
is_whitelisted_use()  :
is_whitelisted_var()  :
isBlacklisted()  : bool
Check if PHPSandbox instance has blacklist type and name set
isBlacklistedAlias()  : bool
Check if PHPSandbox instance has blacklisted alias name set
isBlacklistedClass()  : bool
Check if PHPSandbox instance has blacklisted class name set
isBlacklistedConst()  : bool
Check if PHPSandbox instance has blacklisted constant name set
isBlacklistedFunc()  : bool
Check if PHPSandbox instance has blacklisted function name set
isBlacklistedGlobal()  : bool
Check if PHPSandbox instance has blacklisted global name set
isBlacklistedInterface()  : bool
Check if PHPSandbox instance has blacklisted interface name set
isBlacklistedKeyword()  : bool
Check if PHPSandbox instance has blacklisted keyword name set
isBlacklistedMagicConst()  : bool
Check if PHPSandbox instance has blacklisted magic constant name set
isBlacklistedNamespace()  : bool
Check if PHPSandbox instance has blacklisted namespace name set
isBlacklistedOperator()  : bool
Check if PHPSandbox instance has blacklisted operator name set
isBlacklistedPrimitive()  : bool
Check if PHPSandbox instance has blacklisted primitive name set
isBlacklistedSuperglobal()  : bool
Check if PHPSandbox instance has blacklisted superglobal or superglobal key set
isBlacklistedTrait()  : bool
Check if PHPSandbox instance has blacklisted trait name set
isBlacklistedType()  : bool
Check if PHPSandbox instance has blacklisted type name set
isBlacklistedUse()  : bool
Check if PHPSandbox instance has blacklisted use (or alias) name set
isBlacklistedVar()  : bool
Check if PHPSandbox instance has blacklisted variable name set
isDefinedAlias()  : bool
Check if PHPSandbox instance has $name alias defined
isDefinedClass()  : bool
Check if PHPSandbox instance has $name class defined
isDefinedConst()  : bool
Check if PHPSandbox instance has $name constant defined
isDefinedFunc()  : bool
Check if PHPSandbox instance has $name function defined
isDefinedInterface()  : bool
Check if PHPSandbox instance has $name interface defined
isDefinedMagicConst()  : bool
Check if PHPSandbox instance has $name magic constant defined
isDefinedNamespace()  : bool
Check if PHPSandbox instance has $name namespace defined
isDefinedSuperglobal()  : bool
Check if PHPSandbox instance has $name superglobal defined, or if superglobal $name key is defined
isDefinedTrait()  : bool
Check if PHPSandbox instance has $name trait defined
isDefinedUse()  : bool
Check if PHPSandbox instance has $name uses (or alias) defined
isDefinedVar()  : bool
Check if PHPSandbox instance has $name variable defined
isWhitelisted()  : bool
Check if PHPSandbox instance has whitelist type and name set
isWhitelistedAlias()  : bool
Check if PHPSandbox instance has whitelisted alias name set
isWhitelistedClass()  : bool
Check if PHPSandbox instance has whitelisted class name set
isWhitelistedConst()  : bool
Check if PHPSandbox instance has whitelisted constant name set
isWhitelistedFunc()  : bool
Check if PHPSandbox instance has whitelisted function name set
isWhitelistedGlobal()  : bool
Check if PHPSandbox instance has whitelisted global name set
isWhitelistedInterface()  : bool
Check if PHPSandbox instance has whitelisted interface name set
isWhitelistedKeyword()  : bool
Check if PHPSandbox instance has whitelisted keyword name set
isWhitelistedMagicConst()  : bool
Check if PHPSandbox instance has whitelisted magic constant name set
isWhitelistedNamespace()  : bool
Check if PHPSandbox instance has whitelisted namespace name set
isWhitelistedOperator()  : bool
Check if PHPSandbox instance has whitelisted operator name set
isWhitelistedPrimitive()  : bool
Check if PHPSandbox instance has whitelisted primitive name set
isWhitelistedSuperglobal()  : bool
Check if PHPSandbox instance has whitelisted superglobal or superglobal key set
isWhitelistedTrait()  : bool
Check if PHPSandbox instance has whitelisted trait name set
isWhitelistedType()  : bool
Check if PHPSandbox instance has whitelisted type name set
isWhitelistedUse()  : bool
Check if PHPSandbox instance has whitelisted use (or alias) name set
isWhitelistedVar()  : bool
Check if PHPSandbox instance has whitelisted variable name set
normalize_alias()  :
normalize_class()  :
normalize_func()  :
normalize_interface()  :
normalize_keyword()  :
normalize_magic_const()  :
normalize_namespace()  :
normalize_operator()  :
normalize_primitive()  :
normalize_superglobal()  :
normalize_trait()  :
normalize_type()  :
normalize_use()  :
prepare()  : string
Prepare passed callable for execution
prepare_aliases()  :
prepare_consts()  :
prepare_namespaces()  :
prepare_uses()  :
prepare_vars()  :
prepend()  : PHPSandbox
Prepend trusted code
resetOptions()  : PHPSandbox
Reset PHPSandbox options to their default values
set_error_handler()  :
set_exception_handler()  :
set_validation_error_handler()  :
setAliasValidator()  : PHPSandbox
Set validation callable for aliases
setAppendedCode()  : PHPSandbox
Set PHPSandbox appended code
setClassValidator()  : PHPSandbox
Set validation callable for classes
setCode()  : PHPSandbox
Set PHPSandbox generated code
setConstValidator()  : PHPSandbox
Set validation callable for constants
setErrorHandler()  : PHPSandbox
Set callable to handle errors
setExceptionHandler()  : PHPSandbox
Set callable to handle thrown exceptions
setExecutingFile()  : PHPSandbox
Set the currently executing filepath
setFuncValidator()  : PHPSandbox
Set validation callable for functions
setGeneratedCode()  : PHPSandbox
Set PHPSandbox generated code
setGlobalValidator()  : PHPSandbox
Set validation callable for globals
setInterfaceValidator()  : PHPSandbox
Set validation callable for interfaces
setKeywordValidator()  : PHPSandbox
Set validation callable for keywords
setMagicConstValidator()  : PHPSandbox
Set validation callable for magic constants
setNamespaceValidator()  : PHPSandbox
Set validation callable for namespaces
setOperatorValidator()  : PHPSandbox
Set validation callable for operators
setOption()  : PHPSandbox
Set PHPSandbox option
setOptions()  : PHPSandbox
Set PHPSandbox options by array
setParsedAST()  : PHPSandbox
Set PHPSandbox parsed AST array
setPreparedAST()  : PHPSandbox
Set PHPSandbox prepared AST array
setPreparedCode()  : PHPSandbox
Set PHPSandbox prepared code
setPreparsedCode()  : PHPSandbox
Set PHPSandbox preparsed code
setPrependedCode()  : PHPSandbox
Set PHPSandbox prepended code
setPrimitiveValidator()  : PHPSandbox
Set validation callable for primitives
setSuperglobalValidator()  : PHPSandbox
Set validation callable for superglobals
setTraitValidator()  : PHPSandbox
Set validation callable for traits
setTypeValidator()  : PHPSandbox
Set validation callable for types
setUseValidator()  : PHPSandbox
Set validation callable for uses (aka aliases)
setValidationErrorHandler()  : PHPSandbox
Set callable to handle thrown validation Errors
setValidator()  : PHPSandbox
Set validation callable for specified $type
setVarValidator()  : PHPSandbox
Set validation callable for variables
undefine()  : PHPSandbox
Undefine PHPSandbox definitions, such as functions, constants, namespaces, etc.
undefine_alias()  :
undefine_aliases()  :
undefine_class()  :
undefine_classes()  :
undefine_const()  :
undefine_consts()  :
undefine_func()  :
undefine_funcs()  :
undefine_interface()  :
undefine_interfaces()  :
undefine_magic_const()  :
undefine_magic_consts()  :
undefine_namespace()  :
undefine_namespaces()  :
undefine_superglobal()  :
undefine_superglobals()  :
undefine_trait()  :
undefine_traits()  :
undefine_use()  :
undefine_uses()  :
undefine_var()  :
undefine_vars()  :
undefineAlias()  : PHPSandbox
Undefine PHPSandbox alias
undefineAliases()  : PHPSandbox
Undefine PHPSandbox aliases by array
undefineClass()  : PHPSandbox
Undefine PHPSandbox class
undefineClasses()  : PHPSandbox
Undefine PHPSandbox classes by array
undefineConst()  : PHPSandbox
Undefine PHPSandbox constant
undefineConsts()  : PHPSandbox
Undefine PHPSandbox constants by array
undefineFunc()  : PHPSandbox
Undefine PHPSandbox function
undefineFuncs()  : PHPSandbox
Undefine PHPSandbox functions by array
undefineInterface()  : PHPSandbox
Undefine PHPSandbox interface
undefineInterfaces()  : PHPSandbox
Undefine PHPSandbox interfaces by array
undefineMagicConst()  : PHPSandbox
Undefine PHPSandbox magic constant
undefineMagicConsts()  : PHPSandbox
Undefine PHPSandbox magic constants by array
undefineNamespace()  : PHPSandbox
Undefine PHPSandbox namespace
undefineNamespaces()  : PHPSandbox
Undefine PHPSandbox namespaces by array
undefineSuperglobal()  : PHPSandbox
Undefine PHPSandbox superglobal or superglobal key
undefineSuperglobals()  : PHPSandbox
Undefine PHPSandbox superglobals by array
undefineTrait()  : PHPSandbox
Undefine PHPSandbox trait
undefineTraits()  : PHPSandbox
Undefine PHPSandbox traits by array
undefineUse()  : PHPSandbox
Undefine PHPSandbox use (or alias)
undefineUses()  : PHPSandbox
Undefine PHPSandbox uses (or aliases) by array
undefineVar()  : PHPSandbox
Undefine PHPSandbox variable
undefineVars()  : PHPSandbox
Undefine PHPSandbox variables by array
unset_error_handler()  :
unset_exception_handler()  :
unset_validation_error_handler()  :
unsetAliasValidator()  : PHPSandbox
Unset validation callable for aliases
unsetClassValidator()  : PHPSandbox
Unset validation callable for classes
unsetConstValidator()  : PHPSandbox
Unset validation callable for constants
unsetErrorHandler()  : self
Unset error handler
unsetExceptionHandler()  : PHPSandbox
Unset exception handler
unsetFuncValidator()  : PHPSandbox
Unset validation callable for functions
unsetGlobalValidator()  : PHPSandbox
Unset validation callable for globals
unsetInterfaceValidator()  : PHPSandbox
Unset validation callable for interfaces
unsetKeywordValidator()  : PHPSandbox
Unset validation callable for keywords
unsetMagicConstValidator()  : PHPSandbox
Unset validation callable for magic constants
unsetNamespaceValidator()  : PHPSandbox
Unset validation callable for namespaces
unsetOperatorValidator()  : PHPSandbox
Unset validation callable for operators
unsetPrimitiveValidator()  : PHPSandbox
Unset validation callable for primitives
unsetSuperglobalValidator()  : PHPSandbox
Unset validation callable for superglobals
unsetTraitValidator()  : PHPSandbox
Unset validation callable for traits
unsetTypeValidator()  : PHPSandbox
Unset validation callable for types
unsetUseValidator()  : PHPSandbox
Unset validation callable for uses (aka aliases)
unsetValidationErrorHandler()  : PHPSandbox
Unset validation error handler
unsetValidator()  : PHPSandbox
Unset validation callable for specified $type
unsetVarValidator()  : PHPSandbox
Unset validation callable for variables
validate()  : PHPSandbox
Validate passed callable for execution
validation_error()  :
validationError()  : mixed
Invoke sandbox error validation handler if it exists, throw Error otherwise
whitelist()  : PHPSandbox
Whitelist PHPSandbox definitions, such as functions, constants, classes, etc. to set
whitelist_alias()  :
whitelist_class()  :
whitelist_const()  :
whitelist_func()  :
whitelist_global()  :
whitelist_interface()  :
whitelist_keyword()  :
whitelist_magic_const()  :
whitelist_namespace()  :
whitelist_operator()  :
whitelist_primitive()  :
whitelist_superglobal()  :
whitelist_trait()  :
whitelist_type()  :
whitelist_use()  :
whitelist_var()  :
whitelistAlias()  : PHPSandbox
Whitelist alias
whitelistClass()  : PHPSandbox
Whitelist class
whitelistConst()  : PHPSandbox
Whitelist constant
whitelistFunc()  : PHPSandbox
Whitelist function
whitelistGlobal()  : PHPSandbox
Whitelist global
whitelistInterface()  : PHPSandbox
Whitelist interface
whitelistKeyword()  : PHPSandbox
Whitelist keyword
whitelistMagicConst()  : PHPSandbox
Whitelist magic constant
whitelistNamespace()  : PHPSandbox
Whitelist namespace
whitelistOperator()  : PHPSandbox
Whitelist operator
whitelistPrimitive()  : PHPSandbox
Whitelist primitive
whitelistSuperglobal()  : PHPSandbox
Whitelist superglobal or superglobal key
whitelistTrait()  : PHPSandbox
Whitelist trait
whitelistType()  : PHPSandbox
Whitelist type
whitelistUse()  : PHPSandbox
Whitelist use (or alias)
whitelistVar()  : PHPSandbox
Whitelist variable
autoDefine()  : PHPSandbox
Automatically define variables passed to disassembled closure
autoWhitelist()  : mixed
Automatically whitelisted trusted code
disassemble()  : string
Disassemble callable to string
normalizeAlias()  : string|array<string|int, mixed>
Normalize alias name. This is an internal PHPSandbox function.
normalizeClass()  : string|array<string|int, mixed>
Normalize class name. This is an internal PHPSandbox function.
normalizeFunc()  : string|array<string|int, mixed>
Normalize function name. This is an internal PHPSandbox function.
normalizeInterface()  : string|array<string|int, mixed>
Normalize interface name. This is an internal PHPSandbox function.
normalizeKeyword()  : string|array<string|int, mixed>
Normalize keyword name. This is an internal PHPSandbox function.
normalizeMagicConst()  : string|array<string|int, mixed>
Normalize magic constant name. This is an internal PHPSandbox function.
normalizeNamespace()  : string|array<string|int, mixed>
Normalize namespace name. This is an internal PHPSandbox function.
normalizeOperator()  : string|array<string|int, mixed>
Normalize operator name. This is an internal PHPSandbox function.
normalizePrimitive()  : string|array<string|int, mixed>
Normalize primitive name. This is an internal PHPSandbox function.
normalizeSuperglobal()  : string|array<string|int, mixed>
Normalize superglobal name. This is an internal PHPSandbox function.
normalizeTrait()  : string|array<string|int, mixed>
Normalize trait name. This is an internal PHPSandbox function.
normalizeType()  : string|array<string|int, mixed>
Normalize type name. This is an internal PHPSandbox function.
normalizeUse()  : string|array<string|int, mixed>
Normalize use (or alias) name. This is an internal PHPSandbox function.
prepareAliases()  : string
Prepare defined aliases for execution
prepareConsts()  : string
Prepare defined constants for execution
prepareNamespaces()  : string
Prepare defined namespaces for execution
prepareUses()  : string
Prepare defined uses (or aliases) for execution
prepareVars()  : string
Prepare defined variables for execution

Constants

IMPORT_ALL

public mixed IMPORT_ALL = 0
Tags
const

int A bit flag for the import() method, signifies to import all data from a template

IMPORT_BLACKLIST

public mixed IMPORT_BLACKLIST = 8
Tags
const

int A bit flag for the import() method, signifies to import only blacklists from a template

IMPORT_CODE

public mixed IMPORT_CODE = 32
Tags
const

int A bit flag for the import() method, signifies to import only sandboxed code from a template

IMPORT_DEFINITIONS

public mixed IMPORT_DEFINITIONS = 2
Tags
const

int A bit flag for the import() method, signifies to import only definitions from a template

IMPORT_OPTIONS

public mixed IMPORT_OPTIONS = 1
Tags
const

int A bit flag for the import() method, signifies to import only options from a template

IMPORT_TRUSTED_CODE

public mixed IMPORT_TRUSTED_CODE = 16
Tags
const

int A bit flag for the import() method, signifies to import only trusted code from a template

IMPORT_WHITELIST

public mixed IMPORT_WHITELIST = 4
Tags
const

int A bit flag for the import() method, signifies to import only whitelists from a template

SANDBOX_PREFIX

public mixed SANDBOX_PREFIX = '__PHPSandbox_'
Tags
const

string The prefix given to the obfuscated sandbox key passed to the generated code

Properties

$allow_aliases

public bool $allow_aliases = false

Should PHPSandbox allow sandboxed code to use namespaces and declare namespace aliases (utilizing the defineAlias function?)

Tags
default

false

$allow_backticks

public bool $allow_backticks = false

Should PHPSandbox allow sandboxed code to use backtick execution? (e.g. $var = `ping google.com`; This will also be disabled if shell_exec is not whitelisted or if it is blacklisted, and will be converted to a defined shell_exec function call if one is defined)

Tags
default

false

$allow_casting

public bool $allow_casting = false

Should PHPSandbox allow sandboxed code to cast types? (This will still be subject to allowed classes)

Tags
default

false

$allow_classes

public bool $allow_classes = false

Should PHPSandbox allow sandboxed code to declare classes?

Tags
default

false

$allow_closures

public bool $allow_closures = false

Should PHPSandbox allow sandboxed code to declare closures?

Tags
default

false

$allow_constants

public bool $allow_constants = false

Should PHPSandbox allow sandboxed code to define constants?

Tags
default

false

$allow_error_suppressing

public bool $allow_error_suppressing = false

Should PHPSandbox allow sandboxed code to suppress errors (e.g. the @ operator?)

Tags
default

false

$allow_escaping

public bool $allow_escaping = false

Should PHPSandbox allow sandboxed code to escape to HTML?

Tags
default

false

$allow_functions

public bool $allow_functions = false

Should PHPSandbox allow sandboxed code to declare functions?

Tags
default

false

$allow_generators

public bool $allow_generators = true

Should PHPSandbox allow sandboxed code to create generators?

Tags
default

true

$allow_globals

public bool $allow_globals = false

Should PHPSandbox allow sandboxed code to use global keyword to access variables in the global scope?

Tags
default

false

$allow_halting

public bool $allow_halting = false

Should PHPSandbox allow sandboxed code to halt the PHP compiler?

Tags
default

false

$allow_includes

public bool $allow_includes = false

Flag to indicate whether the sandbox should allow included files

Tags
default

false

$allow_interfaces

public bool $allow_interfaces = false

Should PHPSandbox allow sandboxed code to declare interfaces?

Tags
default

false

$allow_namespaces

public bool $allow_namespaces = false

Should PHPSandbox allow sandboxed code to declare namespaces (utilizing the defineNamespace function?)

Tags
default

false

$allow_objects

public bool $allow_objects = true

Should PHPSandbox allow sandboxed code to create objects of allow classes (e.g. new keyword)?

Tags
default

true

$allow_references

public bool $allow_references = true

Should PHPSandbox allow sandboxed code to assign references?

Tags
default

true

$allow_static_variables

public bool $allow_static_variables = true

Should PHPSandbox allow sandboxed code to create static variables?

Tags
default

true

$allow_traits

public bool $allow_traits = false

Should PHPSandbox allow sandboxed code to declare traits?

Tags
default

false

$allow_variables

public bool $allow_variables = true

Should PHPSandbox allow sandboxed code to create variables?

Tags
default

true

$arg_funcs

public static array<string|int, mixed> $arg_funcs = ['func_get_args', 'func_get_arg', 'func_num_args']

A static array of func_get_args, func_get_arg, and func_num_args used for redefining those functions

Tags
static

$auto_define_vars

public bool $auto_define_vars = true

Should PHPSandbox automagically define variables passed to prepended, appended and prepared code closures?

Tags
default

true

$auto_whitelist_classes

public bool $auto_whitelist_classes = true

Should PHPSandbox automagically whitelist classes created in sandboxed code if $allow_classes is true?

Tags
default

true

$auto_whitelist_constants

public bool $auto_whitelist_constants = true

Should PHPSandbox automagically whitelist constants created in sandboxed code if $allow_constants is true?

Tags
default

true

$auto_whitelist_functions

public bool $auto_whitelist_functions = true

Should PHPSandbox automagically whitelist functions created in sandboxed code if $allow_functions is true?

Tags
default

true

$auto_whitelist_globals

public bool $auto_whitelist_globals = true

Should PHPSandbox automagically whitelist global variables created in sandboxed code if $allow_globals is true? (Used to whitelist them in the variables list)

Tags
default

true

$auto_whitelist_interfaces

public bool $auto_whitelist_interfaces = true

Should PHPSandbox automagically whitelist interfaces created in sandboxed code if $allow_interfaces is true?

Tags
default

true

$auto_whitelist_traits

public bool $auto_whitelist_traits = true

Should PHPSandbox automagically whitelist traits created in sandboxed code if $allow_traits is true?

Tags
default

true

$auto_whitelist_trusted_code

public bool $auto_whitelist_trusted_code = true

Should PHPSandbox automagically whitelist prepended and appended code?

Tags
default

true

$capture_output

public bool $capture_output = false

Flag whether to return output via an output buffer

Tags
default

false

$convert_errors

public bool $convert_errors = false

Flag to indicate whether the sandbox should convert errors to exceptions

Tags
default

false

$defined_funcs

public static array<string|int, mixed> $defined_funcs = ['get_defined_functions', 'get_defined_vars', 'get_defined_constants', 'get_declared_classes', 'get_declared_interfaces', 'get_declared_traits', 'get_included_files']

A static array of defined_* and declared_* functions names used for redefining defined_* and declared_* values

Tags
static

$error_level

public int|null $error_level = null

The error_reporting level to set the PHPSandbox scope to when executing the generated closure, if set to null it will use parent scope error level.

Tags
default

true

$magic_constants

public static array<string|int, mixed> $magic_constants = ['__LINE__', '__FILE__', '__DIR__', '__FUNCTION__', '__CLASS__', '__TRAIT__', '__METHOD__', '__NAMESPACE__']

A static array of magic constant names used for redefining magic constant values

Tags
static

$name

public string $name = ''

The randomly generated name of the PHPSandbox variable passed to the generated closure

$overwrite_defined_funcs

public bool $overwrite_defined_funcs = true

Should PHPSandbox overwrite get_defined_functions, get_defined_vars, get_defined_constants, get_declared_classes, get_declared_interfaces and get_declared_traits?

Tags
default

true

$overwrite_func_get_args

public bool $overwrite_func_get_args = true

Should PHPSandbox overwrite func_get_args, func_get_arg and func_num_args?

Tags
default

true

$overwrite_sandboxed_string_funcs

public bool $overwrite_sandboxed_string_funcs = true

Should PHPSandbox overwrite functions to help hide SandboxedStrings?

Tags
default

true

$overwrite_superglobals

public bool $overwrite_superglobals = true

Should PHPSandbox overwrite $_GET, $_POST, $_COOKIE, $_FILES, $_ENV, $_REQUEST, $_SERVER, $_SESSION and $GLOBALS superglobals? If so, unless alternate superglobal values have been defined they will return as empty arrays.

Tags
default

true

$restore_error_level

public bool $restore_error_level = true

Flag to indicate whether the sandbox should return error_reporting to its previous level after execution

Tags
default

true

$sandbox_includes

public bool $sandbox_includes = true

Flag to indicate whether the sandbox should automatically sandbox included files

Tags
default

true

$sandbox_strings

public bool $sandbox_strings = true

Should PHPSandbox sandbox all string values?

Tags
default

true

$sandboxed_string_funcs

public static array<string|int, mixed> $sandboxed_string_funcs = ['var_dump', 'print_r', 'var_export', 'intval', 'floatval', 'boolval', 'is_string', 'is_object', 'is_scalar', 'is_callable', 'array_key_exists']

A static array of var_dump, print_r and var_export, intval, floatval, is_string, is_object, is_scalar, is_callable, and array_key_exists for redefining those functions

Tags
static

$superglobals

public static array<string|int, mixed> $superglobals = ['_GET', '_POST', '_COOKIE', '_FILES', '_ENV', '_REQUEST', '_SERVER', '_SESSION', 'GLOBALS']

A static array of superglobal names used for redefining superglobal values

Tags
static

$time_limit

public int $time_limit = 0

Integer value of maximum number of seconds the sandbox should be allowed to execute

Tags
default

0

$validate_aliases

public bool $validate_aliases = true

Flag to indicate whether the sandbox should validate aliases (aka use)

Tags
default

true

$validate_classes

public bool $validate_classes = true

Flag to indicate whether the sandbox should validate classes

Tags
default

true

$validate_constants

public bool $validate_constants = true

Flag to indicate whether the sandbox should validate constants

Tags
default

true

$validate_functions

public bool $validate_functions = true

Flag to indicate whether the sandbox should validate functions

Tags
default

true

$validate_globals

public bool $validate_globals = true

Flag to indicate whether the sandbox should validate globals

Tags
default

true

$validate_interfaces

public bool $validate_interfaces = true

Flag to indicate whether the sandbox should validate interfaces

Tags
default

true

$validate_keywords

public bool $validate_keywords = true

Flag to indicate whether the sandbox should validate keywords

Tags
default

true

$validate_magic_constants

public bool $validate_magic_constants = true

Flag to indicate whether the sandbox should validate magic constants

Tags
default

true

$validate_namespaces

public bool $validate_namespaces = true

Flag to indicate whether the sandbox should validate namespaces

Tags
default

true

$validate_operators

public bool $validate_operators = true

Flag to indicate whether the sandbox should validate operators

Tags
default

true

$validate_primitives

public bool $validate_primitives = true

Flag to indicate whether the sandbox should validate primitives

Tags
default

true

$validate_superglobals

public bool $validate_superglobals = true

Flag to indicate whether the sandbox should validate superglobals

Tags
default

true

$validate_traits

public bool $validate_traits = true

Flag to indicate whether the sandbox should validate traits

Tags
default

true

$validate_types

public bool $validate_types = true

Flag to indicate whether the sandbox should validate types

Tags
default

true

$validate_variables

public bool $validate_variables = true

Flag to indicate whether the sandbox should validate variables

Tags
default

true

$appended_code

protected string $appended_code = ''

String of appended code, will be automagically whitelisted for functions, variables, globals, constants, classes, interfaces and traits if $auto_whitelist_trusted_code is true

$blacklist

protected array<string|int, mixed> $blacklist = ['functions' => [], 'variables' => [], 'globals' => [], 'superglobals' => [], 'constants' => [], 'magic_constants' => [], 'namespaces' => [], 'aliases' => [], 'classes' => [], 'interfaces' => [], 'traits' => [], 'keywords' => ['declare' => true, 'eval' => true, 'exit' => true, 'halt' => true], 'operators' => [], 'primitives' => [], 'types' => []]

Array of blacklisted functions, classes, etc. Any whitelisted array types override their counterpart in this array

$definitions

protected array<string|int, mixed> $definitions = ['functions' => [], 'variables' => [], 'superglobals' => [], 'constants' => [], 'magic_constants' => [], 'namespaces' => [], 'aliases' => [], 'classes' => [], 'interfaces' => [], 'traits' => []]

Array of defined functions, superglobals, etc. If an array type contains elements, then it overwrites its external counterpart

$error_handler

protected callable|null $error_handler

Callable that handles any errors when set

$error_handler_types

protected int $error_handler_types = E_ALL

Integer value of the error types to handle (default is E_ALL)

$exception_handler

protected callable|null $exception_handler

Callable that handles any thrown exceptions when set

$executing_file

protected string|null $executing_file = null

The current file being executed

$execution_time

protected float $execution_time = 0.0

Float of the number of microseconds it took to execute the sandbox

$generated_code

protected string $generated_code = ''

String of generated code, for debugging and serialization purposes

$includes

protected array<string|int, mixed> $includes = []

Array of sandboxed included files

$last_error

protected array<string|int, mixed>|null $last_error

The last error thrown by the sandbox

$last_exception

protected Throwable|null $last_exception = null

The last exception thrown by the sandbox

$last_validation_error

protected Throwable|null $last_validation_error = null

The last validation error thrown by the sandbox

$memory_usage

protected int $memory_usage = 0

Int of the number of bytes the sandbox allocates during execution

$parsed_ast

protected array<string|int, mixed> $parsed_ast = []

Array of parsed code broken down into AST tokens, for debugging and serialization purposes

$prepare_time

protected float $prepare_time = 0.0

Float of the number of microseconds it took to prepare the sandbox

$prepared_ast

protected array<string|int, mixed> $prepared_ast = []

Array of prepared code broken down into AST tokens, for debugging and serialization purposes

$prepared_code

protected string $prepared_code = ''

String of prepared code, for debugging and serialization purposes

$preparsed_code

protected string $preparsed_code = ''

String of preparsed code, for debugging and serialization purposes

$prepended_code

protected string $prepended_code = ''

String of prepended code, will be automagically whitelisted for functions, variables, globals, constants, classes, interfaces and traits if $auto_whitelist_trusted_code is true

$sandboxes

protected static array<string|int, mixed> $sandboxes = []

Array of PHPSandboxes

$validation

protected array<string|int, mixed> $validation = ['function' => null, 'variable' => null, 'global' => null, 'superglobal' => null, 'constant' => null, 'magic_constant' => null, 'namespace' => null, 'alias' => null, 'class' => null, 'interface' => null, 'trait' => null, 'keyword' => null, 'operator' => null, 'primitive' => null, 'type' => null]

Array of custom validation functions

$validation_error_handler

protected callable|null $validation_error_handler

Callable that handles any thrown validation errors when set

$whitelist

protected array<string|int, mixed> $whitelist = ['functions' => [], 'variables' => [], 'globals' => [], 'superglobals' => [], 'constants' => [], 'magic_constants' => [], 'namespaces' => [], 'aliases' => [], 'classes' => [], 'interfaces' => [], 'traits' => [], 'keywords' => [], 'operators' => [], 'primitives' => [], 'types' => []]

Array of whitelisted functions, classes, etc. If an array type contains elements, then it overrides its blacklist counterpart

Methods

__call()

Magic method to provide API compatibility for v1.* code

public __call(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
$method : string

The method name to call

$arguments : array<string|int, mixed>

The method arguments to call

Return values
mixed

__construct()

PHPSandbox class constructor

public __construct([array<string|int, mixed> $options = [] ][, array<string|int, mixed> $functions = [] ][, array<string|int, mixed> $variables = [] ][, array<string|int, mixed> $constants = [] ][, array<string|int, mixed> $namespaces = [] ][, array<string|int, mixed> $aliases = [] ][, array<string|int, mixed> $superglobals = [] ][, array<string|int, mixed> $magic_constants = [] ][, array<string|int, mixed> $classes = [] ][, array<string|int, mixed> $interfaces = [] ][, array<string|int, mixed> $traits = [] ]) : mixed

You can pass optional arrays of predefined functions, variables, etc. to the sandbox through the constructor

Parameters
$options : array<string|int, mixed> = []

Optional array of options to set for the sandbox

$functions : array<string|int, mixed> = []

Optional array of functions to define for the sandbox

$variables : array<string|int, mixed> = []

Optional array of variables to define for the sandbox

$constants : array<string|int, mixed> = []

Optional array of constants to define for the sandbox

$namespaces : array<string|int, mixed> = []

Optional array of namespaces to define for the sandbox

$aliases : array<string|int, mixed> = []

Optional array of aliases to define for the sandbox

$superglobals : array<string|int, mixed> = []

Optional array of superglobals to define for the sandbox

$magic_constants : array<string|int, mixed> = []

Optional array of magic constants to define for the sandbox

$classes : array<string|int, mixed> = []

Optional array of classes to define for the sandbox

$interfaces : array<string|int, mixed> = []

Optional array of interfaces to define for the sandbox

$traits : array<string|int, mixed> = []

Optional array of traits to define for the sandbox

Tags
throws
Throwable

Throws exception if definition fails

Return values
mixed

__invoke()

PHPSandbox __invoke magic method

public __invoke(Closure|callable|string $code) : mixed

Besides the code or closure to be executed, you can also pass additional arguments that will overwrite the default values of their respective arguments defined in the code

Parameters
$code : Closure|callable|string

The closure, callable or string of code to execute

Return values
mixed

The output of the executed sandboxed code

__sleep()

PHPSandbox __sleep magic method

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

An array of property keys to be serialized

_array_key_exists()

Get PHPSandbox redefined array_key_exists

public _array_key_exists(string|SandboxedString $key, array<string|int, mixed> $array) : bool
Parameters
$key : string|SandboxedString

The key to check for

$array : array<string|int, mixed>

The array to check against

Return values
bool

Returns the value from array_key_exists()

_arrayval()

Return array value of SandboxedString or mixed value

public _arrayval(mixed $value) : array<string|int, mixed>
Parameters
$value : mixed

Value to return as array

Return values
array<string|int, mixed>

Returns the array value

_boolval()

Return boolean value of SandboxedString or mixed value

public _boolval(mixed $value) : bool
Parameters
$value : mixed

Value to return as boolean

Return values
bool

Returns the boolean value

_floatval()

Return float value of SandboxedString or mixed value

public _floatval(mixed $value) : float
Parameters
$value : mixed

Value to return as float

Return values
float

Returns the float value

_func_get_arg()

Get PHPSandbox redefined function argument

public _func_get_arg([array<string|int, mixed> $arguments = [] ], int $index) : mixed
Parameters
$arguments : array<string|int, mixed> = []

Array result from func_get_args() is passed here

$index : int

Requested func_get_arg index is passed here

Return values
mixed

Returns the redefined argument

_func_get_args()

Get PHPSandbox redefined function arguments array

public _func_get_args([array<string|int, mixed> $arguments = [] ]) : array<string|int, mixed>
Parameters
$arguments : array<string|int, mixed> = []

Array result from func_get_args() is passed here

Return values
array<string|int, mixed>

Returns the redefined arguments array

_func_num_args()

Get PHPSandbox redefined number of function arguments

public _func_num_args([array<string|int, mixed> $arguments = [] ]) : int
Parameters
$arguments : array<string|int, mixed> = []

Array result from func_get_args() is passed here

Return values
int

Returns the redefined number of function arguments

_get_declared_classes()

Get PHPSandbox redefined classes in place of get_declared_classes(). This is an internal PHPSandbox function but requires public access to work.

public _get_declared_classes([array<string|int, mixed> $classes = [] ]) : array<string|int, mixed>
Parameters
$classes : array<string|int, mixed> = []

Array result from get_declared_classes() is passed here

Return values
array<string|int, mixed>

Returns the redefined classes

_get_declared_interfaces()

Get PHPSandbox redefined interfaces in place of get_declared_interfaces(). This is an internal PHPSandbox function but requires public access to work.

public _get_declared_interfaces([array<string|int, mixed> $interfaces = [] ]) : array<string|int, mixed>
Parameters
$interfaces : array<string|int, mixed> = []

Array result from get_declared_interfaces() is passed here

Return values
array<string|int, mixed>

Returns the redefined interfaces

_get_declared_traits()

Get PHPSandbox redefined traits in place of get_declared_traits(). This is an internal PHPSandbox function but requires public access to work.

public _get_declared_traits([array<string|int, mixed> $traits = [] ]) : array<string|int, mixed>
Parameters
$traits : array<string|int, mixed> = []

Array result from get_declared_traits() is passed here

Return values
array<string|int, mixed>

Returns the redefined traits

_get_defined_constants()

Get PHPSandbox redefined constants in place of get_defined_constants(). This is an internal PHPSandbox function but requires public access to work.

public _get_defined_constants([array<string|int, mixed> $constants = [] ]) : array<string|int, mixed>
Parameters
$constants : array<string|int, mixed> = []

Array result from get_defined_constants() is passed here

Return values
array<string|int, mixed>

Returns the redefined constants

_get_defined_functions()

Get PHPSandbox redefined functions in place of get_defined_functions(). This is an internal PHPSandbox function but requires public access to work.

public _get_defined_functions([array<string|int, mixed> $functions = [] ]) : array<string|int, mixed>
Parameters
$functions : array<string|int, mixed> = []

Array result from get_defined_functions() is passed here

Return values
array<string|int, mixed>

Returns the redefined functions array

_get_defined_vars()

Get PHPSandbox redefined variables in place of get_defined_vars(). This is an internal PHPSandbox function but requires public access to work.

public _get_defined_vars([array<string|int, mixed> $variables = [] ]) : array<string|int, mixed>
Parameters
$variables : array<string|int, mixed> = []

Array result from get_defined_vars() is passed here

Return values
array<string|int, mixed>

Returns the redefined variables array

_get_included_files()

Return get_included_files() and sandboxed included files

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

Returns array of get_included_files() and sandboxed included files

_get_magic_const()

Get PHPSandbox redefined magic constant. This is an internal PHPSandbox function but requires public access to work.

public _get_magic_const(string $name) : mixed
Parameters
$name : string

Requested magic constant name (e.g. FILE, LINE, etc.)

Return values
mixed

Returns the redefined magic constant

_get_superglobal()

Get PHPSandbox redefined superglobal. This is an internal PHPSandbox function but requires public access to work.

public _get_superglobal(string $name) : array<string|int, mixed>
Parameters
$name : string

Requested superglobal name (e.g. _GET, _POST, etc.)

Return values
array<string|int, mixed>

Returns the redefined superglobal

_include()

Sandbox included file

public _include(string $file) : mixed
Parameters
$file : string

Included file to sandbox

Return values
mixed

Returns value passed from included file

_include_once()

Sandbox included once file

public _include_once(string $file) : mixed
Parameters
$file : string

Included once file to sandbox

Return values
mixed

Returns value passed from included once file

_intval()

Return integer value of SandboxedString or mixed value

public _intval(mixed $value) : int
Parameters
$value : mixed

Value to return as integer

Return values
int

Returns the integer value

_is_callable()

Return is_callable value of SandboxedString or mixed value

public _is_callable(mixed $value) : bool
Parameters
$value : mixed

Value to check if is_callable

Return values
bool

Returns the is_callable value

_is_object()

Return is_object value of SandboxedString or mixed value

public _is_object(mixed $value) : bool
Parameters
$value : mixed

Value to check if is_object

Return values
bool

Returns the is_object value

_is_scalar()

Return is_scalar value of SandboxedString or mixed value

public _is_scalar(mixed $value) : bool
Parameters
$value : mixed

Value to check if is_scalar

Return values
bool

Returns the is_scalar value

_is_string()

Return is_string value of SandboxedString or mixed value

public _is_string(mixed $value) : bool
Parameters
$value : mixed

Value to check if is_string

Return values
bool

Returns the is_string value

_objectval()

Return object value of SandboxedString or mixed value

public _objectval(mixed $value) : object
Parameters
$value : mixed

Value to return as object

Return values
object

Returns the object value

_print_r()

Get PHPSandbox redefined print_r

public _print_r() : bool|string
Return values
bool|string

Returns the value from print_r()

_require()

Sandbox required file

public _require(string $file) : mixed
Parameters
$file : string

Required file to sandbox

Return values
mixed

Returns value passed from required file

_require_once()

Sandbox required once file

public _require_once(string $file) : mixed
Parameters
$file : string

Required once file to sandbox

Return values
mixed

Returns value passed from required once file

_var_dump()

Get PHPSandbox redefined var_dump

public _var_dump() : void
Return values
void

var_dump() does not return any value

_var_export()

Get PHPSandbox redefined var_export

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

Returns the value from var_export()

append()

Append trusted code

public append(string|callable $code) : PHPSandbox
Parameters
$code : string|callable

String or callable of trusted $code to append to generated code

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

auto_define()

public auto_define() :
Return values

auto_whitelist()

public auto_whitelist() :
Return values

blacklist()

Blacklist PHPSandbox definitions, such as functions, constants, classes, etc. to set

public blacklist(string|array<string|int, mixed> $type[, string|array<string|int, mixed>|null $name = null ]) : PHPSandbox

You can pass an associative array of blacklist types and their names, or a string $type and array of $names, or pass a string of the $type and $name

Parameters
$type : string|array<string|int, mixed>

Associative array or string of blacklist type to set

$name : string|array<string|int, mixed>|null = null

Array or string of blacklist name to set

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

blacklist_alias()

public blacklist_alias() :
Return values

blacklist_class()

public blacklist_class() :
Return values

blacklist_const()

public blacklist_const() :
Return values

blacklist_func()

public blacklist_func() :
Return values

blacklist_global()

public blacklist_global() :
Return values

blacklist_interface()

public blacklist_interface() :
Return values

blacklist_keyword()

public blacklist_keyword() :
Return values

blacklist_magic_const()

public blacklist_magic_const() :
Return values

blacklist_namespace()

public blacklist_namespace() :
Return values

blacklist_operator()

public blacklist_operator() :
Return values

blacklist_primitive()

public blacklist_primitive() :
Return values

blacklist_superglobal()

public blacklist_superglobal() :
Return values

blacklist_trait()

public blacklist_trait() :
Return values

blacklist_type()

public blacklist_type() :
Return values

blacklist_use()

public blacklist_use() :
Return values

blacklist_var()

public blacklist_var() :
Return values

blacklistAlias()

Blacklist alias

public blacklistAlias(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of alias name, or pass an array of the alias names to blacklist

Parameters
$name : string|array<string|int, mixed>

String of alias name or array of alias names to blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

blacklistClass()

Blacklist class

public blacklistClass(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of class name, or pass an array of the class names to blacklist

Parameters
$name : string|array<string|int, mixed>

String of class name or array of class names to blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

blacklistConst()

Blacklist constant

public blacklistConst(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of constant name, or pass an array of the constant names to blacklist

Parameters
$name : string|array<string|int, mixed>

String of constant name or array of constant names to blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

blacklistFunc()

Blacklist function

public blacklistFunc(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of the function name, or pass an array of function names to blacklist

Parameters
$name : string|array<string|int, mixed>

String of function name, or array of function names to blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

blacklistGlobal()

Blacklist global

public blacklistGlobal(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of global name, or pass an array of the global names to blacklist

Parameters
$name : string|array<string|int, mixed>

String of global name or array of global names to blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

blacklistInterface()

Blacklist interface

public blacklistInterface(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of interface name, or pass an array of the interface names to blacklist

Parameters
$name : string|array<string|int, mixed>

String of interface name or array of interface names to blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

blacklistKeyword()

Blacklist keyword

public blacklistKeyword(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of keyword name, or pass an array of the keyword names to blacklist

Parameters
$name : string|array<string|int, mixed>

String of keyword name or array of keyword names to blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

blacklistMagicConst()

Blacklist magic constant

public blacklistMagicConst(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of magic constant name, or pass an array of the magic constant names to blacklist

Parameters
$name : string|array<string|int, mixed>

String of magic constant name or array of magic constant names to blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

blacklistNamespace()

Blacklist namespace

public blacklistNamespace(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of namespace name, or pass an array of the namespace names to blacklist

Parameters
$name : string|array<string|int, mixed>

String of namespace name or array of namespace names to blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

blacklistOperator()

Blacklist operator

public blacklistOperator(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of operator name, or pass an array of the operator names to blacklist

Parameters
$name : string|array<string|int, mixed>

String of operator name or array of operator names to blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

blacklistPrimitive()

Blacklist primitive

public blacklistPrimitive(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of primitive name, or pass an array of the primitive names to blacklist

Parameters
$name : string|array<string|int, mixed>

String of primitive name or array of primitive names to blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

blacklistSuperglobal()

Blacklist superglobal or superglobal key * You can pass a string of the superglobal name, or a string of the superglobal name and a string of the key, or pass an array of superglobal names, or an associative array of superglobal names and their keys to blacklist

public blacklistSuperglobal(string|array<string|int, mixed> $name[, string|null $key = null ]) : PHPSandbox
Parameters
$name : string|array<string|int, mixed>

String of superglobal name, or an array of superglobal names, or an associative array of superglobal names and their keys to blacklist

$key : string|null = null

String of superglobal key to blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

blacklistTrait()

Blacklist trait

public blacklistTrait(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of trait name, or pass an array of the trait names to blacklist

Parameters
$name : string|array<string|int, mixed>

String of trait name or array of trait names to blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

blacklistType()

Blacklist type

public blacklistType(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of type name, or pass an array of the type names to blacklist

Parameters
$name : string|array<string|int, mixed>

String of type name or array of type names to blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

blacklistUse()

Blacklist use (or alias)

public blacklistUse(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of use (or alias) name, or pass an array of the use (or alias) names to blacklist

Parameters
$name : string|array<string|int, mixed>

String of use (or alias) name or array of use (or alias) names to blacklist

Tags
alias

blacklistAlias();

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

blacklistVar()

Blacklist variable

public blacklistVar(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of variable name, or pass an array of the variable names to blacklist

Parameters
$name : string|array<string|int, mixed>

String of variable name or array of variable names to blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

call_func()

Get PHPSandbox redefined function. This is an internal PHPSandbox function but requires public access to work.

public call_func() : mixed
Tags
throws
Throwable

Will throw exception if invalid function requested

Return values
mixed

Returns the redefined function result

check_alias()

public check_alias() :
Return values

check_class()

public check_class() :
Return values

check_const()

public check_const() :
Return values

check_func()

public check_func(string $name) :
Parameters
$name : string
Return values

check_global()

public check_global() :
Return values

check_interface()

public check_interface() :
Return values

check_keyword()

public check_keyword() :
Return values

check_magic_const()

public check_magic_const() :
Return values

check_namespace()

public check_namespace() :
Return values

check_operator()

public check_operator() :
Return values

check_primitive()

public check_primitive() :
Return values

check_superglobal()

public check_superglobal() :
Return values

check_trait()

public check_trait() :
Return values

check_type()

public check_type() :
Return values

check_use()

public check_use() :
Return values

check_var()

public check_var() :
Return values

checkAlias()

Check alias name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.

public checkAlias(string $name) : bool
Parameters
$name : string

String of the alias name to check

Tags
throws
Throwable

Throws exception if validation error occurs

Return values
bool

Returns true if alias is valid

checkClass()

Check class name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.

public checkClass(string $name[, bool $extends = false ]) : bool
Parameters
$name : string

String of the class name to check

$extends : bool = false

Flag whether this is an extended class

Tags
throws
Throwable

Throws exception if validation error occurs

Return values
bool

Returns true if class is valid

checkConst()

Check constant name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.

public checkConst(string $name) : bool
Parameters
$name : string

String of the constant name to check

Tags
throws
Throwable

Throws exception if validation error occurs

Return values
bool

Returns true if constant is valid

checkFunc()

Check function name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.

public checkFunc(string $name) : bool
Parameters
$name : string

String of the function name to check

Tags
throws
Throwable

Throws exception if validation error occurs

Return values
bool

Returns true if function is valid, this is also used for testing closures

checkGlobal()

Check global name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.

public checkGlobal(string $name) : bool
Parameters
$name : string

String of the global name to check

Tags
throws
Throwable

Throws exception if validation error occurs

Return values
bool

Returns true if global is valid

checkInterface()

Check interface name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.

public checkInterface(string $name) : bool
Parameters
$name : string

String of the interface name to check

Tags
throws
Throwable

Throws exception if validation error occurs

Return values
bool

Returns true if interface is valid

checkKeyword()

Check keyword name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.

public checkKeyword(string $name) : bool
Parameters
$name : string

String of the keyword name to check

Tags
throws
Throwable

Throws exception if validation error occurs

Return values
bool

Returns true if keyword is valid

checkMagicConst()

Check magic constant name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.

public checkMagicConst(string $name) : bool
Parameters
$name : string

String of the magic constant name to check

Tags
throws
Throwable

Throws exception if validation error occurs

Return values
bool

Returns true if magic constant is valid

checkNamespace()

Check namespace name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.

public checkNamespace(string $name) : bool
Parameters
$name : string

String of the namespace name to check

Tags
throws
Throwable

Throws exception if validation error occurs

Return values
bool

Returns true if namespace is valid

checkOperator()

Check operator name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.

public checkOperator(string $name) : bool
Parameters
$name : string

String of the type operator to check

Tags
throws
Throwable

Throws exception if validation error occurs

Return values
bool

Returns true if operator is valid

checkPrimitive()

Check primitive name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.

public checkPrimitive(string $name) : bool
Parameters
$name : string

String of the primitive name to check

Tags
throws
Throwable

Throws exception if validation error occurs

Return values
bool

Returns true if primitive is valid

checkSuperglobal()

Check superglobal name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.

public checkSuperglobal(string $name) : bool
Parameters
$name : string

String of the superglobal name to check

Tags
throws
Throwable

Throws exception if validation error occurs

Return values
bool

Returns true if superglobal is valid

checkTrait()

Check trait name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.

public checkTrait(string $name) : bool
Parameters
$name : string

String of the trait name to check

Tags
throws
Throwable

Throws exception if validation error occurs

Return values
bool

Returns true if trait is valid

checkType()

Check type name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.

public checkType(string $name) : bool
Parameters
$name : string

String of the type name to check

Tags
throws
Throwable

Throws exception if validation error occurs

Return values
bool

Returns true if type is valid

checkUse()

Check use (or alias) name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.

public checkUse(string $name) : bool
Parameters
$name : string

String of the use (or alias) name to check

Tags
alias

checkAlias();

throws
Throwable

Throws exception if validation error occurs

Return values
bool

Returns true if use (or alias) is valid

checkVar()

Check variable name against PHPSandbox validation rules. This is an internal PHPSandbox function but requires public access to work.

public checkVar(string $name) : bool
Parameters
$name : string

String of the variable name to check

Tags
throws
Throwable

Throws exception if validation error occurs

Return values
bool

Returns true if variable is valid

clear()

Clear all trusted and sandboxed code

public clear() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

clear_append()

public clear_append() :
Return values

clear_code()

public clear_code() :
Return values

clear_prepend()

public clear_prepend() :
Return values

clear_trusted_code()

public clear_trusted_code() :
Return values

clearAppend()

Clear all appended trusted code

public clearAppend() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

clearAppendedCode()

Clear all appended trusted code

public clearAppendedCode() : PHPSandbox
Tags
alias

$this->clearAppend()

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

clearPrepended()

Clear all prepended trusted code

public clearPrepended() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

clearPrependedCode()

Clear all prepended trusted code

public clearPrependedCode() : PHPSandbox
Tags
alias

$this->clearPrepended()

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

clearTrustedCode()

Clear all trusted code

public clearTrustedCode() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

create()

PHPSandbox static factory method

public static create([array<string|int, mixed> $options = [] ][, array<string|int, mixed> $functions = [] ][, array<string|int, mixed> $variables = [] ][, array<string|int, mixed> $constants = [] ][, array<string|int, mixed> $namespaces = [] ][, array<string|int, mixed> $aliases = [] ][, array<string|int, mixed> $superglobals = [] ][, array<string|int, mixed> $magic_constants = [] ][, array<string|int, mixed> $classes = [] ][, array<string|int, mixed> $interfaces = [] ][, array<string|int, mixed> $traits = [] ]) : PHPSandbox

You can pass optional arrays of predefined functions, variables, etc. to the sandbox through the constructor

Parameters
$options : array<string|int, mixed> = []

Optional array of options to set for the sandbox

$functions : array<string|int, mixed> = []

Optional array of functions to define for the sandbox

$variables : array<string|int, mixed> = []

Optional array of variables to define for the sandbox

$constants : array<string|int, mixed> = []

Optional array of constants to define for the sandbox

$namespaces : array<string|int, mixed> = []

Optional array of namespaces to define for the sandbox

$aliases : array<string|int, mixed> = []

Optional array of aliases to define for the sandbox

$superglobals : array<string|int, mixed> = []

Optional array of superglobals to define for the sandbox

$magic_constants : array<string|int, mixed> = []

Optional array of magic constants to define for the sandbox

$classes : array<string|int, mixed> = []

Optional array of classes to define for the sandbox

$interfaces : array<string|int, mixed> = []

Optional array of interfaces to define for the sandbox

$traits : array<string|int, mixed> = []

Optional array of traits to define for the sandbox

Return values
PHPSandbox

The returned PHPSandbox variable

deblacklist()

Remove PHPSandbox definitions, such as functions, constants, classes, etc. from blacklist

public deblacklist(string|array<string|int, mixed> $type, string|array<string|int, mixed>|null $name) : PHPSandbox

You can pass an associative array of blacklist types and their names, or a string $type and array of $names, or pass a string of the $type and $name to unset

Parameters
$type : string|array<string|int, mixed>

Associative array or string of blacklist type to unset

$name : string|array<string|int, mixed>|null

Array or string of blacklist name to unset

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

deblacklist_alias()

public deblacklist_alias() :
Return values

deblacklist_class()

public deblacklist_class() :
Return values

deblacklist_const()

public deblacklist_const() :
Return values

deblacklist_func()

public deblacklist_func() :
Return values

deblacklist_global()

public deblacklist_global() :
Return values

deblacklist_interface()

public deblacklist_interface() :
Return values

deblacklist_keyword()

public deblacklist_keyword() :
Return values

deblacklist_magic_const()

public deblacklist_magic_const() :
Return values

deblacklist_namespace()

public deblacklist_namespace() :
Return values

deblacklist_operator()

public deblacklist_operator() :
Return values

deblacklist_primitive()

public deblacklist_primitive() :
Return values

deblacklist_superglobal()

public deblacklist_superglobal() :
Return values

deblacklist_trait()

public deblacklist_trait() :
Return values

deblacklist_type()

public deblacklist_type() :
Return values

deblacklist_use()

public deblacklist_use() :
Return values

deblacklist_var()

public deblacklist_var() :
Return values

deblacklistAlias()

Remove alias from blacklist

public deblacklistAlias(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of alias name, or pass an array of the alias names to remove from blacklist

Parameters
$name : string|array<string|int, mixed>

String of alias name or array of alias names to remove from blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

deblacklistClass()

Remove class from blacklist

public deblacklistClass(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of class name, or pass an array of the class names to remove from blacklist

Parameters
$name : string|array<string|int, mixed>

String of class name or array of class names to remove from blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

deblacklistConst()

Remove constant from blacklist

public deblacklistConst(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of constant name, or pass an array of the constant names to remove from blacklist

Parameters
$name : string|array<string|int, mixed>

String of constant name or array of constant names to remove from blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

deblacklistFunc()

Remove function from blacklist

public deblacklistFunc(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of the function name, or pass an array of function names to remove from blacklist

Parameters
$name : string|array<string|int, mixed>

String of function name or array of function names to remove from blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

deblacklistGlobal()

Remove global from blacklist

public deblacklistGlobal(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of global name, or pass an array of the global names to remove from blacklist

Parameters
$name : string|array<string|int, mixed>

String of global name or array of global names to remove from blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

deblacklistInterface()

Remove interface from blacklist

public deblacklistInterface(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of interface name, or pass an array of the interface names to remove from blacklist

Parameters
$name : string|array<string|int, mixed>

String of interface name or array of interface names to remove from blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

deblacklistKeyword()

Remove keyword from blacklist

public deblacklistKeyword(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of keyword name, or pass an array of the keyword names to remove from blacklist

Parameters
$name : string|array<string|int, mixed>

String of keyword name or array of keyword names to remove from blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

deblacklistMagicConst()

Remove magic constant from blacklist

public deblacklistMagicConst(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of magic constant name, or pass an array of the magic constant names to remove from blacklist

Parameters
$name : string|array<string|int, mixed>

String of magic constant name or array of magic constant names to remove from blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

deblacklistNamespace()

Remove namespace from blacklist

public deblacklistNamespace(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of namespace name, or pass an array of the namespace names to remove from blacklist

Parameters
$name : string|array<string|int, mixed>

String of namespace name or array of namespace names to remove from blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

deblacklistOperator()

Remove operator from blacklist

public deblacklistOperator(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of operator name, or pass an array of the operator names to remove from blacklist

Parameters
$name : string|array<string|int, mixed>

String of operator name or array of operator names to remove from blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

deblacklistPrimitive()

Remove primitive from blacklist

public deblacklistPrimitive(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of primitive name, or pass an array of the primitive names to remove from blacklist

Parameters
$name : string|array<string|int, mixed>

String of primitive name or array of primitive names to remove from blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

deblacklistSuperglobal()

Remove superglobal or superglobal key from blacklist * You can pass a string of the superglobal name, or a string of the superglobal name and a string of the key, or pass an array of superglobal names, or an associative array of superglobal names and their keys to remove from blacklist

public deblacklistSuperglobal(string|array<string|int, mixed> $name[, string|null $key = null ]) : PHPSandbox
Parameters
$name : string|array<string|int, mixed>

String of superglobal name, or an array of superglobal names, or an associative array of superglobal names and their keys to remove from blacklist

$key : string|null = null

String of superglobal key to remove from blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

deblacklistTrait()

Remove trait from blacklist

public deblacklistTrait(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of trait name, or pass an array of the trait names to remove from blacklist

Parameters
$name : string|array<string|int, mixed>

String of trait name or array of trait names to remove from blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

deblacklistType()

Remove type from blacklist

public deblacklistType(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of type name, or pass an array of the type names to remove from blacklist

Parameters
$name : string|array<string|int, mixed>

String of type name or array of type names to remove from blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

deblacklistUse()

Remove use (or alias) from blacklist

public deblacklistUse(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of use (or alias name, or pass an array of the use (or alias) names to remove from blacklist

Parameters
$name : string|array<string|int, mixed>

String of use (or alias) name or array of use (or alias) names to remove from blacklist

Tags
alias

deblacklistAlias();

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

deblacklistVar()

Remove function from blacklist

public deblacklistVar(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of variable name, or pass an array of the variable names to remove from blacklist

Parameters
$name : string|array<string|int, mixed>

String of variable name or array of variable names to remove from blacklist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

define()

Define PHPSandbox definitions, such as functions, constants, namespaces, etc.

public define(string|array<string|int, mixed> $type[, string|array<string|int, mixed>|null $name = null ][, mixed|null $value = null ]) : PHPSandbox

You can pass a string of the $type, $name and $value, or pass an associative array of definitions types and an associative array of their corresponding values

Parameters
$type : string|array<string|int, mixed>

Associative array or string of definition type to define

$name : string|array<string|int, mixed>|null = null

Associative array or string of definition name to define

$value : mixed|null = null

Value of definition to define

Tags
throws
Throwable

Throws exception if definition fails

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

define_alias()

public define_alias() :
Return values

define_aliases()

public define_aliases() :
Return values

define_class()

public define_class() :
Return values

define_classes()

public define_classes() :
Return values

define_const()

public define_const() :
Return values

define_consts()

public define_consts() :
Return values

define_func()

public define_func() :
Return values

define_funcs()

public define_funcs() :
Return values

define_interface()

public define_interface() :
Return values

define_interfaces()

public define_interfaces() :
Return values

define_magic_const()

public define_magic_const() :
Return values

define_magic_consts()

public define_magic_consts() :
Return values

define_namespace()

public define_namespace() :
Return values

define_namespaces()

public define_namespaces() :
Return values

define_superglobal()

public define_superglobal() :
Return values

define_superglobals()

public define_superglobals() :
Return values

define_trait()

public define_trait() :
Return values

define_traits()

public define_traits() :
Return values

define_use()

public define_use() :
Return values

define_uses()

public define_uses() :
Return values

define_var()

public define_var() :
Return values

define_vars()

public define_vars() :
Return values

defineAlias()

Define PHPSandbox alias

public defineAlias(string|array<string|int, mixed> $name[, string|null $alias = null ]) : PHPSandbox

You can pass the namespace $name and $alias to use, an array of namespaces to use, or an associative array of namespaces to use and their aliases

Parameters
$name : string|array<string|int, mixed>

String of namespace $name to use, or an array of namespaces to use, or an associative array of namespaces and their aliases to use

$alias : string|null = null

String of $alias to use

Tags
throws
Throwable

Throws exception if unnamed namespace is used

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineAliases()

Define PHPSandbox aliases by array

public defineAliases([array<string|int, mixed> $aliases = [] ]) : PHPSandbox

You can pass an array of namespaces to use, or an associative array of namespaces to use and their aliases

Parameters
$aliases : array<string|int, mixed> = []

Array of namespaces to use, or an associative array of namespaces and their aliases to use

Tags
throws
Throwable

Throws exception if unnamed namespace is used

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineClass()

Define PHPSandbox class

public defineClass(string|array<string|int, mixed> $name, mixed $value) : PHPSandbox

You can pass the class $name and $value to define, or an associative array of classes to define

Parameters
$name : string|array<string|int, mixed>

String of class $name or associative array to define

$value : mixed

Value to define class to

Tags
throws
Throwable

Throws exception if unnamed class is defined

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineClasses()

Define PHPSandbox classes by array

public defineClasses([array<string|int, mixed> $classes = [] ]) : PHPSandbox

You can pass an associative array of classes to define

Parameters
$classes : array<string|int, mixed> = []

Associative array of $classes to define

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineConst()

Define PHPSandbox constant

public defineConst(string|array<string|int, mixed> $name, mixed $value) : PHPSandbox

You can pass the constant $name and $value to define, or an associative array of constants to define

Parameters
$name : string|array<string|int, mixed>

String of constant $name or associative array to define

$value : mixed

Value to define constant to

Tags
throws
Throwable

Throws exception if unnamed constant is defined

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineConsts()

Define PHPSandbox constants by array

public defineConsts([array<string|int, mixed> $constants = [] ]) : PHPSandbox

You can pass an associative array of constants to define

Parameters
$constants : array<string|int, mixed> = []

Associative array of $constants to define

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineFunc()

Define PHPSandbox function

public defineFunc(string|array<string|int, mixed> $name, callable $function[, bool $pass_sandbox = false ]) : PHPSandbox

You can pass the function $name and $function closure or callable to define, or an associative array of functions to define, which can have callable values or arrays of the function callable and $pass_sandbox flag

Parameters
$name : string|array<string|int, mixed>

Associative array or string of function $name to define

$function : callable

Callable to define $function to

$pass_sandbox : bool = false

Pass PHPSandbox instance to defined function when called? Default is false

Tags
throws
Throwable

Throws exception if unnamed or uncallable $function is defined

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineFuncs()

Define PHPSandbox functions by array

public defineFuncs([array<string|int, mixed> $functions = [] ]) : PHPSandbox

You can pass an associative array of functions to define

Parameters
$functions : array<string|int, mixed> = []

Associative array of $functions to define

Tags
throws
Throwable

Throws exception if unnamed or uncallable $function is defined

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineInterface()

Define PHPSandbox interface

public defineInterface(string|array<string|int, mixed> $name, mixed $value) : PHPSandbox

You can pass the interface $name and $value to define, or an associative array of interfaces to define

Parameters
$name : string|array<string|int, mixed>

String of interface $name or associative array to define

$value : mixed

Value to define interface to

Tags
throws
Throwable

Throws exception if unnamed interface is defined

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineInterfaces()

Define PHPSandbox interfaces by array

public defineInterfaces([array<string|int, mixed> $interfaces = [] ]) : PHPSandbox

You can pass an associative array of interfaces to define

Parameters
$interfaces : array<string|int, mixed> = []

Associative array of $interfaces to define

Tags
throws
Throwable

Throws exception if unnamed interface is defined

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineMagicConst()

Define PHPSandbox magic constant

public defineMagicConst(string|array<string|int, mixed> $name, mixed $value) : PHPSandbox

You can pass the magic constant $name and $value to define, or an associative array of magic constants to define

Parameters
$name : string|array<string|int, mixed>

String of magic constant $name or associative array to define

$value : mixed

Value to define magic constant to, can be callable

Tags
throws
Throwable

Throws exception if unnamed magic constant is defined

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineMagicConsts()

Define PHPSandbox magic constants by array

public defineMagicConsts([array<string|int, mixed> $magic_constants = [] ]) : PHPSandbox

You can pass an associative array of magic constants to define

Parameters
$magic_constants : array<string|int, mixed> = []

Associative array of $magic_constants to define

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineNamespace()

Define PHPSandbox namespace

public defineNamespace(string|array<string|int, mixed> $name) : PHPSandbox

You can pass the namespace $name and $value to define, or an array of namespaces to define

Parameters
$name : string|array<string|int, mixed>

String of namespace $name, or an array of namespace names to define

Tags
throws
Throwable

Throws exception if unnamed namespace is defined

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineNamespaces()

Define PHPSandbox namespaces by array

public defineNamespaces([array<string|int, mixed> $namespaces = [] ]) : PHPSandbox

You can pass an array of namespaces to define

Parameters
$namespaces : array<string|int, mixed> = []

Array of $namespaces to define

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineSuperglobal()

Define PHPSandbox superglobal

public defineSuperglobal(string|array<string|int, mixed> $name, mixed $value) : PHPSandbox

You can pass the superglobal $name and $value to define, or an associative array of superglobals to define, or a third variable to define the $key

Parameters
$name : string|array<string|int, mixed>

String of superglobal $name or associative array of superglobal names to define

$value : mixed

Value to define superglobal to, can be callable

Tags
throws
Throwable

Throws exception if unnamed superglobal is defined

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineSuperglobals()

Define PHPSandbox superglobals by array

public defineSuperglobals([array<string|int, mixed> $superglobals = [] ]) : PHPSandbox

You can pass an associative array of superglobals to define

Parameters
$superglobals : array<string|int, mixed> = []

Associative array of $superglobals to define

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineTrait()

Define PHPSandbox trait

public defineTrait(string|array<string|int, mixed> $name, mixed $value) : PHPSandbox

You can pass the trait $name and $value to define, or an associative array of traits to define

Parameters
$name : string|array<string|int, mixed>

String of trait $name or associative array to define

$value : mixed

Value to define trait to

Tags
throws
Throwable

Throws exception if unnamed trait is defined

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineTraits()

Define PHPSandbox traits by array

public defineTraits([array<string|int, mixed> $traits = [] ]) : PHPSandbox

You can pass an associative array of traits to define

Parameters
$traits : array<string|int, mixed> = []

Associative array of $traits to define

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineUse()

Define PHPSandbox use (or alias)

public defineUse(string|array<string|int, mixed> $name[, string|null $alias = null ]) : PHPSandbox
Parameters
$name : string|array<string|int, mixed>

String of namespace $name to use, or or an array of namespaces to use, or an associative array of namespaces and their aliases to use

$alias : string|null = null

String of $alias to use

Tags
alias

defineAlias();

You can pass the namespace $name and $alias to use, an array of namespaces to use, or an associative array of namespaces to use and their aliases

throws
Throwable

Throws exception if unnamed namespace is used

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineUses()

Define PHPSandbox uses (or aliases) by array

public defineUses([array<string|int, mixed> $uses = [] ]) : PHPSandbox
Parameters
$uses : array<string|int, mixed> = []

Array of namespaces to use, or an associative array of namespaces and their aliases to use

Tags
alias

defineAliases();

You can pass an array of namespaces to use, or an associative array of namespaces to use and their aliases

throws
Throwable

Throws exception if unnamed namespace is used

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineVar()

Define PHPSandbox variable

public defineVar(string|array<string|int, mixed> $name, mixed $value) : PHPSandbox

You can pass the variable $name and $value to define, or an associative array of variables to define

Parameters
$name : string|array<string|int, mixed>

String of variable $name or associative array to define

$value : mixed

Value to define variable to

Tags
throws
Throwable

Throws exception if unnamed variable is defined

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

defineVars()

Define PHPSandbox variables by array

public defineVars([array<string|int, mixed> $variables = [] ]) : PHPSandbox

You can pass an associative array of variables to define

Parameters
$variables : array<string|int, mixed> = []

Associative array of $variables to define

Tags
throws
Throwable

Throws exception if unnamed variable is defined

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

dewhitelist()

Remove PHPSandbox definitions, such as functions, constants, classes, etc. from whitelist

public dewhitelist(string|array<string|int, mixed> $type, string|array<string|int, mixed>|null $name) : PHPSandbox

You can pass an associative array of whitelist types and their names, or a string $type and array of $names, or pass a string of the $type and $name to unset

Parameters
$type : string|array<string|int, mixed>

Associative array or string of whitelist type to unset

$name : string|array<string|int, mixed>|null

Array or string of whitelist name to unset

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

dewhitelist_alias()

public dewhitelist_alias() :
Return values

dewhitelist_class()

public dewhitelist_class() :
Return values

dewhitelist_const()

public dewhitelist_const() :
Return values

dewhitelist_func()

public dewhitelist_func() :
Return values

dewhitelist_global()

public dewhitelist_global() :
Return values

dewhitelist_interface()

public dewhitelist_interface() :
Return values

dewhitelist_keyword()

public dewhitelist_keyword() :
Return values

dewhitelist_magic_const()

public dewhitelist_magic_const() :
Return values

dewhitelist_namespace()

public dewhitelist_namespace() :
Return values

dewhitelist_operator()

public dewhitelist_operator() :
Return values

dewhitelist_primitive()

public dewhitelist_primitive() :
Return values

dewhitelist_superglobal()

public dewhitelist_superglobal() :
Return values

dewhitelist_trait()

public dewhitelist_trait() :
Return values

dewhitelist_type()

public dewhitelist_type() :
Return values

dewhitelist_use()

public dewhitelist_use() :
Return values

dewhitelist_var()

public dewhitelist_var() :
Return values

dewhitelistAlias()

Remove alias from whitelist

public dewhitelistAlias(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of alias name, or pass an array of the alias names to remove from whitelist

Parameters
$name : string|array<string|int, mixed>

String of alias name or array of alias names to remove from whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

dewhitelistClass()

Remove class from whitelist

public dewhitelistClass(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of class name, or pass an array of the class names to remove from whitelist

Parameters
$name : string|array<string|int, mixed>

String of class name or array of class names to remove from whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

dewhitelistConst()

Remove constant from whitelist

public dewhitelistConst(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of constant name, or pass an array of the constant names to remove from whitelist

Parameters
$name : string|array<string|int, mixed>

String of constant name or array of constant names to remove from whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

dewhitelistFunc()

Remove function from whitelist

public dewhitelistFunc(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of the function name, or pass an array of function names to remove from whitelist

Parameters
$name : string|array<string|int, mixed>

String of function name or array of function names to remove from whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

dewhitelistGlobal()

Remove global from whitelist

public dewhitelistGlobal(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of global name, or pass an array of the global names to remove from whitelist

Parameters
$name : string|array<string|int, mixed>

String of global name or array of global names to remove from whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

dewhitelistInterface()

Remove interface from whitelist

public dewhitelistInterface(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of interface name, or pass an array of the interface names to remove from whitelist

Parameters
$name : string|array<string|int, mixed>

String of interface name or array of interface names to remove from whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

dewhitelistKeyword()

Remove keyword from whitelist

public dewhitelistKeyword(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of keyword name, or pass an array of the keyword names to remove from whitelist

Parameters
$name : string|array<string|int, mixed>

String of keyword name or array of keyword names to remove from whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

dewhitelistMagicConst()

Remove magic constant from whitelist

public dewhitelistMagicConst(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of magic constant name, or pass an array of the magic constant names to remove from whitelist

Parameters
$name : string|array<string|int, mixed>

String of magic constant name or array of magic constant names to remove from whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

dewhitelistNamespace()

Remove namespace from whitelist

public dewhitelistNamespace(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of namespace name, or pass an array of the namespace names to remove from whitelist

Parameters
$name : string|array<string|int, mixed>

String of namespace name or array of namespace names to remove from whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

dewhitelistOperator()

Remove operator from whitelist

public dewhitelistOperator(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of operator name, or pass an array of the operator names to remove from whitelist

Parameters
$name : string|array<string|int, mixed>

String of operator name or array of operator names to remove from whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

dewhitelistPrimitive()

Remove primitive from whitelist

public dewhitelistPrimitive(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of primitive name, or pass an array of the primitive names to remove from whitelist

Parameters
$name : string|array<string|int, mixed>

String of primitive name or array of primitive names to remove from whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

dewhitelistSuperglobal()

Remove superglobal or superglobal key from whitelist * You can pass a string of the superglobal name, or a string of the superglobal name and a string of the key, or pass an array of superglobal names, or an associative array of superglobal names and their keys to remove from whitelist

public dewhitelistSuperglobal(string|array<string|int, mixed> $name[, string|null $key = null ]) : PHPSandbox
Parameters
$name : string|array<string|int, mixed>

String of superglobal name, or an array of superglobal names, or an associative array of superglobal names and their keys to remove from whitelist

$key : string|null = null

String of superglobal key to remove from whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

dewhitelistTrait()

Remove trait from whitelist

public dewhitelistTrait(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of trait name, or pass an array of the trait names to remove from whitelist

Parameters
$name : string|array<string|int, mixed>

String of trait name or array of trait names to remove from whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

dewhitelistType()

Remove type from whitelist

public dewhitelistType(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of type name, or pass an array of the type names to remove from whitelist

Parameters
$name : string|array<string|int, mixed>

String of type name or array of type names to remove from whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

dewhitelistUse()

Remove use (or alias) from whitelist

public dewhitelistUse(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of use (or alias name, or pass an array of the use (or alias) names to remove from whitelist

Parameters
$name : string|array<string|int, mixed>

String of use (or alias) name or array of use (or alias) names to remove from whitelist

Tags
alias

dewhitelistAlias();

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

dewhitelistVar()

Remove variable from whitelist

public dewhitelistVar(string|array<string|int, mixed> $name) : PHPSandbox

You can pass a string of variable name, or pass an array of the variable names to remove from whitelist

Parameters
$name : string|array<string|int, mixed>

String of variable name or array of variable names to remove from whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

error()

Invoke sandbox error handler

public error(int $errno, string $errstr, string $errfile, int $errline[, array<string|int, mixed> $errcontext = [] ]) : mixed
Parameters
$errno : int

Error number

$errstr : string

Error message

$errfile : string

Error file

$errline : int

Error line number

$errcontext : array<string|int, mixed> = []

Error context array

Tags
throws
Throwable
Return values
mixed

exception()

Invoke sandbox exception handler

public exception(Throwable $exception) : mixed
Parameters
$exception : Throwable

Exception to be handled

Tags
throws
Throwable
Return values
mixed

execute()

Prepare and execute callable and return output

public execute([callable|string $callable = null ][, bool $skip_validation = false ][, string|null $executing_file = null ]) : mixed

This function validates your code and automatically whitelists it according to your specified configuration, then executes it.

Parameters
$callable : callable|string = null

Callable or string of PHP code to prepare and execute within the sandbox

$skip_validation : bool = false

Boolean flag to indicate whether the sandbox should skip validation of the pass callable. Default is false.

$executing_file : string|null = null

The file path of the code to execute

Tags
throws
Throwable

Throws exception if error occurs in parsing, validation or whitelisting or if generated closure is invalid

Return values
mixed

The output from the executed sandboxed code

get_defined_class()

public get_defined_class() :
Return values

get_defined_interface()

public get_defined_interface() :
Return values

get_defined_namespace()

public get_defined_namespace() :
Return values

get_defined_trait()

public get_defined_trait() :
Return values

get_error_handler()

public get_error_handler() :
Return values

get_exception_handler()

public get_exception_handler() :
Return values

get_execution_time()

public get_execution_time() :
Return values

get_last_error()

public get_last_error() :
Return values

get_last_exception()

public get_last_exception() :
Return values

get_last_validation_error()

public get_last_validation_error() :
Return values

get_prepared_time()

public get_prepared_time() :
Return values

get_validation_error_handler()

public get_validation_error_handler() :
Return values

getAliasValidator()

Get validation callable for aliases

public getAliasValidator() : callable|null
Return values
callable|null

getAppendedCode()

Get PHPSandbox appended code

public getAppendedCode() : string
Return values
string

Returns a string of the appended code

getClassValidator()

Get validation callable for classes

public getClassValidator() : callable|null
Return values
callable|null

getCode()

Get PHPSandbox generated code

public getCode() : string
Tags
alias

getGeneratedCode();

Return values
string

Returns a string of the generated code

getConstValidator()

Get validation callable for constants

public getConstValidator() : callable|null
Return values
callable|null

getDefinedClass()

Get defined class of $name

public getDefinedClass(string $name) : string
Parameters
$name : string

String of class $name to get

Tags
throws
Throwable

Throws an exception if an invalid class name is requested

Return values
string

Returns string of defined class value

getDefinedInterface()

Get defined interface of $name

public getDefinedInterface(string $name) : string
Parameters
$name : string

String of interface $name to get

Tags
throws
Throwable

Throws an exception if an invalid interface name is requested

Return values
string

Returns string of defined interface value

getDefinedNamespace()

Get defined namespace of $name

public getDefinedNamespace(string $name) : string
Parameters
$name : string

String of namespace $name to get

Tags
throws
Throwable

Throws an exception if an invalid namespace name is requested

Return values
string

Returns string of defined namespace value

getDefinedTrait()

Get defined trait of $name

public getDefinedTrait(string $name) : string
Parameters
$name : string

String of trait $name to get

Tags
throws
Throwable

Throws an exception if an invalid trait name is requested

Return values
string

Returns string of defined trait value

getErrorHandler()

Get error handler

public getErrorHandler() : callable|null

This function returns the sandbox error handler.

Return values
callable|null

getExceptionHandler()

Get exception handler

public getExceptionHandler() : callable|null

This function returns the sandbox exception handler.

Return values
callable|null

getExecutingFile()

Return the current file being executed in the sandbox

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

The current file being executed

getExecutionTime()

Return the amount of time the sandbox spent executing the sandboxed code

public getExecutionTime(int $round) : float

You can pass the number of digits you wish to round the return value

Parameters
$round : int

The number of digits to round the return value

Return values
float

The amount of time in microseconds it took to execute the sandboxed code

getFuncValidator()

Get validation for functions

public getFuncValidator() : callable|null
Return values
callable|null

getGeneratedCode()

Get PHPSandbox generated code

public getGeneratedCode() : string
Return values
string

Returns a string of the generated code

getGlobalValidator()

Get validation callable for globals

public getGlobalValidator() : callable|null
Return values
callable|null

getInterfaceValidator()

Get validation callable for interfaces

public getInterfaceValidator() : callable|null
Return values
callable|null

getIterator()

Get an iterator of all the public PHPSandbox properties

public getIterator() : ArrayIterator
Return values
ArrayIterator

getKeywordValidator()

Get validation callable for keywords

public getKeywordValidator() : callable|null
Return values
callable|null

getLastError()

Gets the last sandbox error

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

getLastException()

Gets the last exception thrown by the sandbox

public getLastException() : Throwable|null
Return values
Throwable|null

getLastValidationError()

Gets the last validation error thrown by the sandbox

public getLastValidationError() : Throwable|null
Return values
Throwable|null

getMagicConstValidator()

Get validation callable for magic constants

public getMagicConstValidator() : callable|null
Return values
callable|null

getMemoryUsage()

Return the amount of bytes the sandbox allocated while preparing and executing the sandboxed code

public getMemoryUsage(int $round) : float

You can pass the number of digits you wish to round the return value

Parameters
$round : int

The number of digits to round the return value

Return values
float

The amount of bytes in memory it took to prepare and execute the sandboxed code

getName()

Get name of PHPSandbox variable

public getName() : string
Return values
string

The name of the PHPSandbox variable

getNamespaceValidator()

Get validation callable for namespaces

public getNamespaceValidator() : callable|null
Return values
callable|null

getOperatorValidator()

Get validation callable for operators

public getOperatorValidator() : callable|null
Return values
callable|null

getOption()

Get PHPSandbox option

public getOption(string $option) : bool|int|null

You pass a string $option name to get its associated value

Parameters
$option : string

String of $option name to get

Return values
bool|int|null

Returns the value of the requested option

getParsedAST()

Get PHPSandbox parsed AST array

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

Returns an array of the parsed AST code

getPreparedAST()

Get PHPSandbox prepared AST array

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

Returns an array of the prepared AST code

getPreparedCode()

Get PHPSandbox prepared code

public getPreparedCode() : string
Return values
string

Returns a string of the prepared code

getPreparedTime()

Return the amount of time the sandbox spent preparing the sandboxed code

public getPreparedTime(int $round) : float

You can pass the number of digits you wish to round the return value

Parameters
$round : int

The number of digits to round the return value

Return values
float

The amount of time in microseconds it took to prepare the sandboxed code

getPreparsedCode()

Get PHPSandbox preparsed code

public getPreparsedCode() : string
Return values
string

Returns a string of the preparsed code

getPrependedCode()

Get PHPSandbox prepended code

public getPrependedCode() : string
Return values
string

Returns a string of the prepended code

getPrimitiveValidator()

Get validation callable for primitives

public getPrimitiveValidator() : callable|null
Return values
callable|null

getSandbox()

Get a named PHPSandbox instance (used to retrieve the sandbox instance from within sandboxed code)

public static getSandbox(string $name) : PHPSandbox|null
Parameters
$name : string

The name of the PHPSandbox instance to retrieve

Return values
PHPSandbox|null

getSuperglobalValidator()

Get validation callable for superglobals

public getSuperglobalValidator() : callable|null
Return values
callable|null

getTime()

Return the amount of time the sandbox spent preparing and executing the sandboxed code

publ