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

public getTime(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 and execute the sandboxed code

getTraitValidator()

Get validation callable for traits

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

getTypeValidator()

Get validation callable for types

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

getUseValidator()

Get validation callable for uses (aka aliases)

public getUseValidator() : callable|null
Tags
alias

getAliasValidator();

Return values
callable|null

getValidationErrorHandler()

Get validation error handler

public getValidationErrorHandler() : callable|null

This function returns the sandbox validation error handler.

Return values
callable|null

getValidator()

Get validation callable for specified $type

public getValidator(string $type) : callable|null
Parameters
$type : string

String of $type to return

Return values
callable|null

getVarValidator()

Get validation callable for variables

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

has_blacklist()

public has_blacklist() :
Return values

has_blacklist_aliases()

public has_blacklist_aliases() :
Return values

has_blacklist_classes()

public has_blacklist_classes() :
Return values

has_blacklist_consts()

public has_blacklist_consts() :
Return values

has_blacklist_funcs()

public has_blacklist_funcs() :
Return values

has_blacklist_globals()

public has_blacklist_globals() :
Return values

has_blacklist_interfaces()

public has_blacklist_interfaces() :
Return values

has_blacklist_keywords()

public has_blacklist_keywords() :
Return values

has_blacklist_magic_consts()

public has_blacklist_magic_consts() :
Return values

has_blacklist_namespaces()

public has_blacklist_namespaces() :
Return values

has_blacklist_operators()

public has_blacklist_operators() :
Return values

has_blacklist_primitives()

public has_blacklist_primitives() :
Return values

has_blacklist_superglobals()

public has_blacklist_superglobals() :
Return values

has_blacklist_traits()

public has_blacklist_traits() :
Return values

has_blacklist_types()

public has_blacklist_types() :
Return values

has_blacklist_uses()

public has_blacklist_uses() :
Return values

has_blacklist_vars()

public has_blacklist_vars() :
Return values

has_defined_aliases()

public has_defined_aliases() :
Return values

has_defined_classes()

public has_defined_classes() :
Return values

has_defined_consts()

public has_defined_consts() :
Return values

has_defined_funcs()

public has_defined_funcs() :
Return values

has_defined_interfaces()

public has_defined_interfaces() :
Return values

has_defined_magic_consts()

public has_defined_magic_consts() :
Return values

has_defined_namespaces()

public has_defined_namespaces() :
Return values

has_defined_superglobals()

public has_defined_superglobals() :
Return values

has_defined_traits()

public has_defined_traits() :
Return values

has_defined_uses()

public has_defined_uses() :
Return values

has_defined_vars()

public has_defined_vars() :
Return values

has_whitelist()

public has_whitelist() :
Return values

has_whitelist_aliases()

public has_whitelist_aliases() :
Return values

has_whitelist_classes()

public has_whitelist_classes() :
Return values

has_whitelist_consts()

public has_whitelist_consts() :
Return values

has_whitelist_funcs()

public has_whitelist_funcs() :
Return values

has_whitelist_globals()

public has_whitelist_globals() :
Return values

has_whitelist_interfaces()

public has_whitelist_interfaces() :
Return values

has_whitelist_keywords()

public has_whitelist_keywords() :
Return values

has_whitelist_magic_consts()

public has_whitelist_magic_consts() :
Return values

has_whitelist_namespaces()

public has_whitelist_namespaces() :
Return values

has_whitelist_operators()

public has_whitelist_operators() :
Return values

has_whitelist_primitives()

public has_whitelist_primitives() :
Return values

has_whitelist_superglobals()

public has_whitelist_superglobals() :
Return values

has_whitelist_traits()

public has_whitelist_traits() :
Return values

has_whitelist_types()

public has_whitelist_types() :
Return values

has_whitelist_uses()

public has_whitelist_uses() :
Return values

has_whitelist_vars()

public has_whitelist_vars() :
Return values

hasBlacklist()

Query whether PHPSandbox instance has blacklist type.

public hasBlacklist(string $type) : int
Parameters
$type : string

The blacklist type to query

Return values
int

Returns the number of blacklists this instance has defined

hasBlacklistedAliases()

Query whether PHPSandbox instance has blacklisted aliases.

public hasBlacklistedAliases() : int
Return values
int

Returns the number of blacklisted aliases this instance has defined

hasBlacklistedClasses()

Query whether PHPSandbox instance has blacklisted classes.

public hasBlacklistedClasses() : int
Return values
int

Returns the number of blacklisted classes this instance has defined

hasBlacklistedConsts()

Query whether PHPSandbox instance has blacklisted constants.

public hasBlacklistedConsts() : int
Return values
int

Returns the number of blacklisted constants this instance has defined

hasBlacklistedFuncs()

Query whether PHPSandbox instance has blacklisted functions.

public hasBlacklistedFuncs() : int
Return values
int

Returns the number of blacklisted functions this instance has defined

hasBlacklistedGlobals()

Query whether PHPSandbox instance has blacklisted globals.

public hasBlacklistedGlobals() : int
Return values
int

Returns the number of blacklisted globals this instance has defined

hasBlacklistedInterfaces()

Query whether PHPSandbox instance has blacklisted interfaces.

public hasBlacklistedInterfaces() : int
Return values
int

Returns the number of blacklisted interfaces this instance has defined

hasBlacklistedKeywords()

Query whether PHPSandbox instance has blacklisted keywords.

public hasBlacklistedKeywords() : int
Return values
int

Returns the number of blacklisted keywords this instance has defined

hasBlacklistedMagicConsts()

Query whether PHPSandbox instance has blacklisted magic constants.

public hasBlacklistedMagicConsts() : int
Return values
int

Returns the number of blacklisted magic constants this instance has defined

hasBlacklistedNamespaces()

Query whether PHPSandbox instance has blacklisted namespaces.

public hasBlacklistedNamespaces() : int
Return values
int

Returns the number of blacklisted namespaces this instance has defined

hasBlacklistedOperators()

Query whether PHPSandbox instance has blacklisted operators.

public hasBlacklistedOperators() : int
Return values
int

Returns the number of blacklisted operators this instance has defined

hasBlacklistedPrimitives()

Query whether PHPSandbox instance has blacklisted primitives.

public hasBlacklistedPrimitives() : int
Return values
int

Returns the number of blacklisted primitives this instance has defined

hasBlacklistedSuperglobals()

Query whether PHPSandbox instance has blacklisted superglobals, or superglobal keys

public hasBlacklistedSuperglobals([string|null $name = null ]) : int
Parameters
$name : string|null = null

The blacklist superglobal key to query

Return values
int

Returns the number of blacklisted superglobals or superglobal keys this instance has defined

hasBlacklistedTraits()

Query whether PHPSandbox instance has blacklisted traits.

public hasBlacklistedTraits() : int
Return values
int

Returns the number of blacklisted traits this instance has defined

hasBlacklistedTypes()

Query whether PHPSandbox instance has blacklisted types.

public hasBlacklistedTypes() : int
Return values
int

Returns the number of blacklisted types this instance has defined

hasBlacklistedUses()

Query whether PHPSandbox instance has blacklisted uses (or aliases.)

public hasBlacklistedUses() : int
Tags
alias

hasBlacklistedAliases();

Return values
int

Returns the number of blacklisted uses (or aliases) this instance has defined

hasBlacklistedVars()

Query whether PHPSandbox instance has blacklisted variables.

public hasBlacklistedVars() : int
Return values
int

Returns the number of blacklisted variables this instance has defined

hasDefinedAliases()

Query whether PHPSandbox instance has defined aliases

public hasDefinedAliases() : int
Return values
int

Returns the number of aliases this instance has defined

hasDefinedClasses()

Query whether PHPSandbox instance has defined classes

public hasDefinedClasses() : int
Return values
int

Returns the number of classes this instance has defined

hasDefinedConsts()

Query whether PHPSandbox instance has defined constants

public hasDefinedConsts() : int
Return values
int

Returns the number of constants this instance has defined

hasDefinedFuncs()

Query whether PHPSandbox instance has defined functions

public hasDefinedFuncs() : int
Return values
int

Returns the number of functions this instance has defined

hasDefinedInterfaces()

Query whether PHPSandbox instance has defined interfaces

public hasDefinedInterfaces() : int
Return values
int

Returns the number of interfaces this instance has defined

hasDefinedMagicConsts()

Query whether PHPSandbox instance has defined magic constants

public hasDefinedMagicConsts() : int
Return values
int

Returns the number of magic constants this instance has defined

hasDefinedNamespaces()

Query whether PHPSandbox instance has defined namespaces

public hasDefinedNamespaces() : int
Return values
int

Returns the number of namespaces this instance has defined

hasDefinedSuperglobals()

Query whether PHPSandbox instance has defined superglobals, or if superglobal $name has defined keys

public hasDefinedSuperglobals([string|null $name = null ]) : int
Parameters
$name : string|null = null

String of superglobal $name to check for keys

Return values
int

Returns the number of superglobals or superglobal keys this instance has defined, or false if invalid superglobal name specified

hasDefinedTraits()

Query whether PHPSandbox instance has defined traits

public hasDefinedTraits() : int
Return values
int

Returns the number of traits this instance has defined

hasDefinedUses()

Query whether PHPSandbox instance has defined uses (or aliases)

public hasDefinedUses() : int
Tags
alias

hasDefinedAliases();

Return values
int

Returns the number of uses (or aliases) this instance has defined

hasDefinedVars()

Query whether PHPSandbox instance has defined variables

public hasDefinedVars() : int
Return values
int

Returns the number of variables this instance has defined

hasWhitelist()

Query whether PHPSandbox instance has whitelist type

public hasWhitelist(string $type) : int
Parameters
$type : string

The whitelist type to query

Return values
int

Returns the number of whitelists this instance has defined

hasWhitelistedAliases()

Query whether PHPSandbox instance has whitelisted aliases.

public hasWhitelistedAliases() : int
Return values
int

Returns the number of whitelisted aliases this instance has defined

hasWhitelistedClasses()

Query whether PHPSandbox instance has whitelisted classes.

public hasWhitelistedClasses() : int
Return values
int

Returns the number of whitelisted classes this instance has defined

hasWhitelistedConsts()

Query whether PHPSandbox instance has whitelisted constants.

public hasWhitelistedConsts() : int
Return values
int

Returns the number of whitelisted constants this instance has defined

hasWhitelistedFuncs()

Query whether PHPSandbox instance has whitelisted functions.

public hasWhitelistedFuncs() : int
Return values
int

Returns the number of whitelisted functions this instance has defined

hasWhitelistedGlobals()

Query whether PHPSandbox instance has whitelisted globals.

public hasWhitelistedGlobals() : int
Return values
int

Returns the number of whitelisted globals this instance has defined

hasWhitelistedInterfaces()

Query whether PHPSandbox instance has whitelisted interfaces.

public hasWhitelistedInterfaces() : int
Return values
int

Returns the number of whitelisted interfaces this instance has defined

hasWhitelistedMagicConsts()

Query whether PHPSandbox instance has whitelisted magic constants.

public hasWhitelistedMagicConsts() : int
Return values
int

Returns the number of whitelisted magic constants this instance has defined

hasWhitelistedNamespaces()

Query whether PHPSandbox instance has whitelisted namespaces.

public hasWhitelistedNamespaces() : int
Return values
int

Returns the number of whitelisted namespaces this instance has defined

hasWhitelistedOperators()

Query whether PHPSandbox instance has whitelisted operators.

public hasWhitelistedOperators() : int
Return values
int

Returns the number of whitelisted operators this instance has defined

hasWhitelistedPrimitives()

Query whether PHPSandbox instance has whitelisted primitives.

public hasWhitelistedPrimitives() : int
Return values
int

Returns the number of whitelisted primitives this instance has defined

hasWhitelistedSuperglobals()

Query whether PHPSandbox instance has whitelisted superglobals, or superglobal keys

public hasWhitelistedSuperglobals([string|null $name = null ]) : int
Parameters
$name : string|null = null

The whitelist superglobal key to query

Return values
int

Returns the number of whitelisted superglobals or superglobal keys this instance has defined

hasWhitelistedTraits()

Query whether PHPSandbox instance has whitelisted traits.

public hasWhitelistedTraits() : int
Return values
int

Returns the number of whitelisted traits this instance has defined

hasWhitelistedTypes()

Query whether PHPSandbox instance has whitelisted types.

public hasWhitelistedTypes() : int
Return values
int

Returns the number of whitelisted types this instance has defined

hasWhitelistedUses()

Query whether PHPSandbox instance has whitelisted uses (or aliases.)

public hasWhitelistedUses() : int
Tags
alias

hasWhitelistedAliases();

Return values
int

Returns the number of whitelisted uses (or aliases) this instance has defined

hasWhitelistedVars()

Query whether PHPSandbox instance has whitelisted variables.

public hasWhitelistedVars() : int
Return values
int

Returns the number of whitelisted variables this instance has defined

hasWhitelistKeywords()

Query whether PHPSandbox instance has whitelisted keywords.

public hasWhitelistKeywords() : int
Return values
int

Returns the number of whitelisted keywords this instance has defined

import()

PHPSandbox __wakeup magic method

public import(array<string|int, mixed>|string $template, int $import_flag) : PHPSandbox
  • Import JSON template into sandbox
Parameters
$template : array<string|int, mixed>|string

The JSON array or string template to import

$import_flag : int

Binary flags signifying which parts of the JSON template to import

Tags
throws
Throwable

Throws exception if JSON template could not be imported

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

importJSON()

Import JSON template into sandbox

public importJSON(array<string|int, mixed>|string $template, int $import_flag) : PHPSandbox
Parameters
$template : array<string|int, mixed>|string

The JSON array or string template to import

$import_flag : int

Binary flags signifying which parts of the JSON template to import

Tags
alias

import();

throws
Throwable

Throws exception if JSON template could not be imported

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

is_blacklisted()

public is_blacklisted() :
Return values

is_blacklisted_alias()

public is_blacklisted_alias() :
Return values

is_blacklisted_class()

public is_blacklisted_class() :
Return values

is_blacklisted_const()

public is_blacklisted_const() :
Return values

is_blacklisted_func()

public is_blacklisted_func() :
Return values

is_blacklisted_global()

public is_blacklisted_global() :
Return values

is_blacklisted_interface()

public is_blacklisted_interface() :
Return values

is_blacklisted_keyword()

public is_blacklisted_keyword() :
Return values

is_blacklisted_magic_const()

public is_blacklisted_magic_const() :
Return values

is_blacklisted_namespace()

public is_blacklisted_namespace() :
Return values

is_blacklisted_operator()

public is_blacklisted_operator() :
Return values

is_blacklisted_primitive()

public is_blacklisted_primitive() :
Return values

is_blacklisted_superglobal()

public is_blacklisted_superglobal() :
Return values

is_blacklisted_trait()

public is_blacklisted_trait() :
Return values

is_blacklisted_type()

public is_blacklisted_type() :
Return values

is_blacklisted_use()

public is_blacklisted_use() :
Return values

is_blacklisted_var()

public is_blacklisted_var() :
Return values

is_defined_alias()

public is_defined_alias() :
Return values

is_defined_class()

public is_defined_class() :
Return values

is_defined_const()

public is_defined_const() :
Return values

is_defined_func()

public is_defined_func() :
Return values

is_defined_interface()

public is_defined_interface() :
Return values

is_defined_magic_const()

public is_defined_magic_const() :
Return values

is_defined_namespace()

public is_defined_namespace() :
Return values

is_defined_superglobal()

public is_defined_superglobal() :
Return values

is_defined_trait()

public is_defined_trait() :
Return values

is_defined_use()

public is_defined_use() :
Return values

is_defined_var()

public is_defined_var() :
Return values

is_whitelisted()

public is_whitelisted() :
Return values

is_whitelisted_alias()

public is_whitelisted_alias() :
Return values

is_whitelisted_class()

public is_whitelisted_class() :
Return values

is_whitelisted_const()

public is_whitelisted_const() :
Return values

is_whitelisted_func()

public is_whitelisted_func() :
Return values

is_whitelisted_global()

public is_whitelisted_global() :
Return values

is_whitelisted_interface()

public is_whitelisted_interface() :
Return values

is_whitelisted_keyword()

public is_whitelisted_keyword() :
Return values

is_whitelisted_magic_const()

public is_whitelisted_magic_const() :
Return values

is_whitelisted_namespace()

public is_whitelisted_namespace() :
Return values

is_whitelisted_operator()

public is_whitelisted_operator() :
Return values

is_whitelisted_primitive()

public is_whitelisted_primitive() :
Return values

is_whitelisted_superglobal()

public is_whitelisted_superglobal() :
Return values

is_whitelisted_trait()

public is_whitelisted_trait() :
Return values

is_whitelisted_type()

public is_whitelisted_type() :
Return values

is_whitelisted_use()

public is_whitelisted_use() :
Return values

is_whitelisted_var()

public is_whitelisted_var() :
Return values

isBlacklisted()

Check if PHPSandbox instance has blacklist type and name set

public isBlacklisted(string $type, string $name) : bool
Parameters
$type : string

String of blacklist $type to query

$name : string

String of blacklist $name to query

Return values
bool

Returns true if PHPSandbox instance has blacklisted $type and $name, false otherwise

isBlacklistedAlias()

Check if PHPSandbox instance has blacklisted alias name set

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

String of alias $name to query

Return values
bool

Returns true if PHPSandbox instance has blacklisted alias $name, false otherwise

isBlacklistedClass()

Check if PHPSandbox instance has blacklisted class name set

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

String of class $name to query

Return values
bool

Returns true if PHPSandbox instance has blacklisted class $name, false otherwise

isBlacklistedConst()

Check if PHPSandbox instance has blacklisted constant name set

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

String of constant $name to query

Return values
bool

Returns true if PHPSandbox instance has blacklisted constant $name, false otherwise

isBlacklistedFunc()

Check if PHPSandbox instance has blacklisted function name set

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

String of function $name to query

Return values
bool

Returns true if PHPSandbox instance has blacklisted function $name, false otherwise

isBlacklistedGlobal()

Check if PHPSandbox instance has blacklisted global name set

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

String of global $name to query

Return values
bool

Returns true if PHPSandbox instance has blacklisted global $name, false otherwise

isBlacklistedInterface()

Check if PHPSandbox instance has blacklisted interface name set

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

String of interface $name to query

Return values
bool

Returns true if PHPSandbox instance has blacklisted interface $name, false otherwise

isBlacklistedKeyword()

Check if PHPSandbox instance has blacklisted keyword name set

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

String of keyword $name to query

Return values
bool

Returns true if PHPSandbox instance has blacklisted keyword $name, false otherwise

isBlacklistedMagicConst()

Check if PHPSandbox instance has blacklisted magic constant name set

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

String of magic constant $name to query

Return values
bool

Returns true if PHPSandbox instance has blacklisted magic constant $name, false otherwise

isBlacklistedNamespace()

Check if PHPSandbox instance has blacklisted namespace name set

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

String of namespace $name to query

Return values
bool

Returns true if PHPSandbox instance has blacklisted namespace $name, false otherwise

isBlacklistedOperator()

Check if PHPSandbox instance has blacklisted operator name set

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

String of operator $name to query

Return values
bool

Returns true if PHPSandbox instance has blacklisted operator $name, false otherwise

isBlacklistedPrimitive()

Check if PHPSandbox instance has blacklisted primitive name set

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

String of primitive $name to query

Return values
bool

Returns true if PHPSandbox instance has blacklisted primitive $name, false otherwise

isBlacklistedSuperglobal()

Check if PHPSandbox instance has blacklisted superglobal or superglobal key set

public isBlacklistedSuperglobal(string $name[, string|null $key = null ]) : bool
Parameters
$name : string

String of blacklisted superglobal $name to query

$key : string|null = null

String of blacklisted superglobal $key to query

Return values
bool

Returns true if PHPSandbox instance has blacklisted superglobal key or superglobal, false otherwise

isBlacklistedTrait()

Check if PHPSandbox instance has blacklisted trait name set

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

String of trait $name to query

Return values
bool

Returns true if PHPSandbox instance has blacklisted trait $name, false otherwise

isBlacklistedType()

Check if PHPSandbox instance has blacklisted type name set

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

String of type $name to query

Return values
bool

Returns true if PHPSandbox instance has blacklisted type $name, false otherwise

isBlacklistedUse()

Check if PHPSandbox instance has blacklisted use (or alias) name set

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

String of use (or alias) $name to query

Tags
alias

isBlacklistedAlias();

Return values
bool

Returns true if PHPSandbox instance has blacklisted use (or alias) $name, false otherwise

isBlacklistedVar()

Check if PHPSandbox instance has blacklisted variable name set

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

String of variable $name to query

Return values
bool

Returns true if PHPSandbox instance has blacklisted variable $name, false otherwise

isDefinedAlias()

Check if PHPSandbox instance has $name alias defined

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

String of alias $name to query

Return values
bool

Returns true if PHPSandbox instance has defined aliases, false otherwise

isDefinedClass()

Check if PHPSandbox instance has $name class defined

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

String of class $name to query

Return values
bool

Returns true if PHPSandbox instance has defined class, false otherwise

isDefinedConst()

Check if PHPSandbox instance has $name constant defined

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

String of constant $name to query

Return values
bool

Returns true if PHPSandbox instance has defined constant, false otherwise

isDefinedFunc()

Check if PHPSandbox instance has $name function defined

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

String of function $name to query

Return values
bool

Returns true if PHPSandbox instance has defined function, false otherwise

isDefinedInterface()

Check if PHPSandbox instance has $name interface defined

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

String of interface $name to query

Return values
bool

Returns true if PHPSandbox instance has defined interface, false otherwise

isDefinedMagicConst()

Check if PHPSandbox instance has $name magic constant defined

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

String of magic constant $name to query

Return values
bool

Returns true if PHPSandbox instance has defined magic constant, false otherwise

isDefinedNamespace()

Check if PHPSandbox instance has $name namespace defined

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

String of namespace $name to query

Return values
bool

Returns true if PHPSandbox instance has defined namespace, false otherwise

isDefinedSuperglobal()

Check if PHPSandbox instance has $name superglobal defined, or if superglobal $name key is defined

public isDefinedSuperglobal(string $name[, string|null $key = null ]) : bool
Parameters
$name : string

String of superglobal $name to query

$key : string|null = null

String of key to to query in superglobal

Return values
bool

Returns true if PHPSandbox instance has defined superglobal, false otherwise

isDefinedTrait()

Check if PHPSandbox instance has $name trait defined

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

String of trait $name to query

Return values
bool

Returns true if PHPSandbox instance has defined trait, false otherwise

isDefinedUse()

Check if PHPSandbox instance has $name uses (or alias) defined

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

String of use (or alias) $name to query

Tags
alias

isDefinedAlias();

Return values
bool

Returns true if PHPSandbox instance has defined uses (or aliases) and false otherwise

isDefinedVar()

Check if PHPSandbox instance has $name variable defined

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

String of variable $name to query

Return values
bool

Returns true if PHPSandbox instance has defined variable, false otherwise

isWhitelisted()

Check if PHPSandbox instance has whitelist type and name set

public isWhitelisted(string $type, string $name) : bool
Parameters
$type : string

String of whitelist $type to query

$name : string

String of whitelist $name to query

Return values
bool

Returns true if PHPSandbox instance has whitelisted $type and $name, false otherwise

isWhitelistedAlias()

Check if PHPSandbox instance has whitelisted alias name set

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

String of alias $name to query

Return values
bool

Returns true if PHPSandbox instance has whitelisted alias $name, false otherwise

isWhitelistedClass()

Check if PHPSandbox instance has whitelisted class name set

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

String of class $name to query

Return values
bool

Returns true if PHPSandbox instance has whitelisted class $name, false otherwise

isWhitelistedConst()

Check if PHPSandbox instance has whitelisted constant name set

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

String of constant $name to query

Return values
bool

Returns true if PHPSandbox instance has whitelisted constant $name, false otherwise

isWhitelistedFunc()

Check if PHPSandbox instance has whitelisted function name set

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

String of function $name to query

Return values
bool

Returns true if PHPSandbox instance has whitelisted function $name, false otherwise

isWhitelistedGlobal()

Check if PHPSandbox instance has whitelisted global name set

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

String of global $name to query

Return values
bool

Returns true if PHPSandbox instance has whitelisted global $name, false otherwise

isWhitelistedInterface()

Check if PHPSandbox instance has whitelisted interface name set

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

String of interface $name to query

Return values
bool

Returns true if PHPSandbox instance has whitelisted interface $name, false otherwise

isWhitelistedKeyword()

Check if PHPSandbox instance has whitelisted keyword name set

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

String of keyword $name to query

Return values
bool

Returns true if PHPSandbox instance has whitelisted keyword $name, false otherwise

isWhitelistedMagicConst()

Check if PHPSandbox instance has whitelisted magic constant name set

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

String of magic constant $name to query

Return values
bool

Returns true if PHPSandbox instance has whitelisted magic constant $name, false otherwise

isWhitelistedNamespace()

Check if PHPSandbox instance has whitelisted namespace name set

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

String of namespace $name to query

Return values
bool

Returns true if PHPSandbox instance has whitelisted namespace $name, false otherwise

isWhitelistedOperator()

Check if PHPSandbox instance has whitelisted operator name set

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

String of operator $name to query

Return values
bool

Returns true if PHPSandbox instance has whitelisted operator $name, false otherwise

isWhitelistedPrimitive()

Check if PHPSandbox instance has whitelisted primitive name set

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

String of primitive $name to query

Return values
bool

Returns true if PHPSandbox instance has whitelisted primitive $name, false otherwise

isWhitelistedSuperglobal()

Check if PHPSandbox instance has whitelisted superglobal or superglobal key set

public isWhitelistedSuperglobal(string $name[, string|null $key = null ]) : bool
Parameters
$name : string

String of whitelisted superglobal $name to query

$key : string|null = null

String of whitelisted superglobal $key to query

Return values
bool

Returns true if PHPSandbox instance has whitelisted superglobal key or superglobal, false otherwise

isWhitelistedTrait()

Check if PHPSandbox instance has whitelisted trait name set

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

String of trait $name to query

Return values
bool

Returns true if PHPSandbox instance has whitelisted trait $name, false otherwise

isWhitelistedType()

Check if PHPSandbox instance has whitelisted type name set

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

String of type $name to query

Return values
bool

Returns true if PHPSandbox instance has whitelisted type $name, false otherwise

isWhitelistedUse()

Check if PHPSandbox instance has whitelisted use (or alias) name set

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

String of use (or alias) $name to query

Tags
alias

isWhitelistedAlias();

Return values
bool

Returns true if PHPSandbox instance has whitelisted use (or alias) $name, false otherwise

isWhitelistedVar()

Check if PHPSandbox instance has whitelisted variable name set

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

String of variable $name to query

Return values
bool

Returns true if PHPSandbox instance has whitelisted variable $name, false otherwise

normalize_alias()

public normalize_alias() :
Return values

normalize_class()

public normalize_class() :
Return values

normalize_func()

public normalize_func() :
Return values

normalize_interface()

public normalize_interface() :
Return values

normalize_keyword()

public normalize_keyword() :
Return values

normalize_magic_const()

public normalize_magic_const() :
Return values

normalize_namespace()

public normalize_namespace() :
Return values

normalize_operator()

public normalize_operator() :
Return values

normalize_primitive()

public normalize_primitive() :
Return values

normalize_superglobal()

public normalize_superglobal() :
Return values

normalize_trait()

public normalize_trait() :
Return values

normalize_type()

public normalize_type() :
Return values

normalize_use()

public normalize_use() :
Return values

prepare()

Prepare passed callable for execution

public prepare(callable $code[, bool $skip_validation = false ]) : string

This function validates your code and automatically whitelists it according to your specified configuration

Parameters
$code : callable

The callable to prepare for execution

$skip_validation : bool = false

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

Tags
throws
Throwable

Throws exception if error occurs in parsing, validation or whitelisting

Return values
string

The generated code (this can also be accessed via $sandbox->generated_code)

prepare_aliases()

public prepare_aliases() :
Return values

prepare_consts()

public prepare_consts() :
Return values

prepare_namespaces()

public prepare_namespaces() :
Return values

prepare_uses()

public prepare_uses() :
Return values

prepare_vars()

public prepare_vars() :
Return values

prepend()

Prepend trusted code

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

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

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

resetOptions()

Reset PHPSandbox options to their default values

public resetOptions() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

set_error_handler()

public set_error_handler() :
Return values

set_exception_handler()

public set_exception_handler() :
Return values

set_validation_error_handler()

public set_validation_error_handler() :
Return values

setAliasValidator()

Set validation callable for aliases

public setAliasValidator(callable $callable) : PHPSandbox

Validator callable must accept two parameters: a string of the normalized name of the checked element, and the PHPSandbox instance

Parameters
$callable : callable

Callable that validates the passed alias name

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setAppendedCode()

Set PHPSandbox appended code

public setAppendedCode([string $appended_code = '' ]) : PHPSandbox
Parameters
$appended_code : string = ''

Sets a string of the appended code

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setClassValidator()

Set validation callable for classes

public setClassValidator(callable $callable) : PHPSandbox

Validator callable must accept two parameters: a string of the normalized name of the checked element, and the PHPSandbox instance. NOTE: Normalized class names are lowercase

Parameters
$callable : callable

Callable that validates the passed class name

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setCode()

Set PHPSandbox generated code

public setCode([string $generated_code = '' ]) : PHPSandbox
Parameters
$generated_code : string = ''

Sets a string of the generated code

Tags
alias

setGeneratedCode();

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setConstValidator()

Set validation callable for constants

public setConstValidator(callable $callable) : PHPSandbox

Validator callable must accept two parameters: a string of the normalized name of the checked element, and the PHPSandbox instance

Parameters
$callable : callable

Callable that validates the passed constant name

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setErrorHandler()

Set callable to handle errors

public setErrorHandler(callable $handler[, int $error_types = E_ALL ]) : PHPSandbox

This function sets the sandbox error handler and the handled error types. The handler accepts the error number, the error message, the error file, the error line, the error context and the sandbox instance as arguments. If the error handler does not handle errors correctly then the sandbox's security may become compromised!

}, E_ALL); //ignore all errors, INSECURE

Parameters
$handler : callable

Callable to handle thrown Errors

$error_types : int = E_ALL

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

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setExceptionHandler()

Set callable to handle thrown exceptions

public setExceptionHandler(callable|null $handler) : PHPSandbox

This function sets the sandbox exception handler. The handler accepts the thrown exception and the sandbox instance as arguments. If the exception handler does not handle exceptions correctly then the sandbox's security may become compromised!

Parameters
$handler : callable|null

Callable to handle thrown exceptions

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setExecutingFile()

Set the currently executing filepath

public setExecutingFile(string|null $executing_file) : PHPSandbox
Parameters
$executing_file : string|null

The file currently being executed

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setFuncValidator()

Set validation callable for functions

public setFuncValidator(callable $callable) : PHPSandbox

Validator callable must accept two parameters: a string of the normalized name of the checked element, and the PHPSandbox instance. NOTE: Normalized function names include the namespace and are lowercase!

Parameters
$callable : callable

Callable that validates the normalized passed function name

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setGeneratedCode()

Set PHPSandbox generated code

public setGeneratedCode([string $generated_code = '' ]) : PHPSandbox
Parameters
$generated_code : string = ''

Sets a string of the generated code

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setGlobalValidator()

Set validation callable for globals

public setGlobalValidator(callable $callable) : PHPSandbox

Validator callable must accept two parameters: a string of the normalized name of the checked element, and the PHPSandbox instance

Parameters
$callable : callable

Callable that validates the passed global name

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setInterfaceValidator()

Set validation callable for interfaces

public setInterfaceValidator(callable $callable) : PHPSandbox

Validator callable must accept two parameters: a string of the normalized name of the checked element, and the PHPSandbox instance. NOTE: Normalized interface names are lowercase

Parameters
$callable : callable

Callable that validates the passed interface name

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setKeywordValidator()

Set validation callable for keywords

public setKeywordValidator(callable $callable) : PHPSandbox

Validator callable must accept two parameters: a string of the normalized name of the checked element, and the PHPSandbox instance

Parameters
$callable : callable

Callable that validates the passed keyword name

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setMagicConstValidator()

Set validation callable for magic constants

public setMagicConstValidator(callable $callable) : PHPSandbox

Validator callable must accept two parameters: a string of the normalized name of the checked element, and the PHPSandbox instance. NOTE: Normalized magic constant names are upper case and trimmed of __

Parameters
$callable : callable

Callable that validates the passed magic constant name

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setNamespaceValidator()

Set validation callable for namespaces

public setNamespaceValidator(callable $callable) : PHPSandbox

Validator callable must accept two parameters: a string of the normalized name of the checked element, and the PHPSandbox instance

Parameters
$callable : callable

Callable that validates the passed namespace name

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setOperatorValidator()

Set validation callable for operators

public setOperatorValidator(callable $callable) : PHPSandbox

Validator callable must accept two parameters: a string of the normalized name of the checked element, and the PHPSandbox instance

Parameters
$callable : callable

Callable that validates the passed operator name

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setOption()

Set PHPSandbox option

public setOption(string|array<string|int, mixed> $option[, bool|int|null $value = null ]) : PHPSandbox

You can pass an $option name to set to $value, an array of $option names to set to $value, or an associative array of $option names and their values to set.

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

String or array of strings or associative array of keys of option names to set $value to

$value : bool|int|null = null

Boolean, integer or null $value to set $option to (optional)

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setOptions()

Set PHPSandbox options by array

public setOptions(array<string|int, mixed>|string $options[, bool|int|null $value = null ]) : PHPSandbox

You can pass an array of option names to set to $value, or an associative array of option names and their values to set.

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

Array of strings or associative array of keys of option names to set $value to, or JSON array or string template to import

$value : bool|int|null = null

Boolean, integer or null $value to set $option to (optional)

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setParsedAST()

Set PHPSandbox parsed AST array

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

Sets an array of the parsed AST code

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setPreparedAST()

Set PHPSandbox prepared AST array

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

Sets an array of the prepared AST code

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setPreparedCode()

Set PHPSandbox prepared code

public setPreparedCode([string $prepared_code = '' ]) : PHPSandbox
Parameters
$prepared_code : string = ''

Sets a string of the prepared code

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setPreparsedCode()

Set PHPSandbox preparsed code

public setPreparsedCode([string $preparsed_code = '' ]) : PHPSandbox
Parameters
$preparsed_code : string = ''

Sets a string of the preparsed code

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setPrependedCode()

Set PHPSandbox prepended code

public setPrependedCode([string $prepended_code = '' ]) : PHPSandbox
Parameters
$prepended_code : string = ''

Sets a string of the prepended code

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setPrimitiveValidator()

Set validation callable for primitives

public setPrimitiveValidator(callable $callable) : PHPSandbox

Validator callable must accept two parameters: a string of the normalized name of the checked element, and the PHPSandbox instance

Parameters
$callable : callable

Callable that validates the passed primitive name

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setSuperglobalValidator()

Set validation callable for superglobals

public setSuperglobalValidator(callable $callable) : PHPSandbox

Validator callable must accept two parameters: a string of the normalized name of the checked element, and the PHPSandbox instance. NOTE: Normalized superglobal names are uppercase and without a leading _

Parameters
$callable : callable

Callable that validates the passed superglobal name

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setTraitValidator()

Set validation callable for traits

public setTraitValidator(callable $callable) : PHPSandbox

Validator callable must accept two parameters: a string of the normalized name of the checked element, and the PHPSandbox instance. NOTE: Normalized trait names are lowercase

Parameters
$callable : callable

Callable that validates the passed trait name

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setTypeValidator()

Set validation callable for types

public setTypeValidator(callable $callable) : PHPSandbox

Validator callable must accept two parameters: a string of the normalized name of the checked element, and the PHPSandbox instance

Parameters
$callable : callable

Callable that validates the passed type name

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setUseValidator()

Set validation callable for uses (aka aliases)

public setUseValidator(callable $callable) : PHPSandbox

Validator callable must accept two parameters: a string of the normalized name of the checked element, and the PHPSandbox instance

Parameters
$callable : callable

Callable that validates the passed use (aka alias) name

Tags
alias

setAliasValidator();

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setValidationErrorHandler()

Set callable to handle thrown validation Errors

public setValidationErrorHandler(callable|null $handler) : PHPSandbox

This function sets the sandbox validation Error handler. The handler accepts the thrown Error and the sandbox instance as arguments. If the error handler does not handle validation errors correctly then the sandbox's security may become compromised!

Parameters
$handler : callable|null

Callable to handle thrown validation Errors

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setValidator()

Set validation callable for specified $type

public setValidator(string $type, callable $callable) : PHPSandbox

Validator callable must accept two parameters: a string of the normalized name of the checked element, and the PHPSandbox instance

Parameters
$type : string

String of $type name to set validator for

$callable : callable

Callable that validates the passed element

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

setVarValidator()

Set validation callable for variables

public setVarValidator(callable $callable) : PHPSandbox

Validator callable must accept two parameters: a string of the normalized name of the checked element, and the PHPSandbox instance

Parameters
$callable : callable

Callable that validates the passed variable name

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefine()

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

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

You can pass a string of the $type and $name to undefine, or pass an associative array of definitions types and an array of key names to undefine

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

Associative array or string of definition type to undefine

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

Associative array or string of definition name to undefine

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefine_alias()

public undefine_alias() :
Return values

undefine_aliases()

public undefine_aliases() :
Return values

undefine_class()

public undefine_class() :
Return values

undefine_classes()

public undefine_classes() :
Return values

undefine_const()

public undefine_const() :
Return values

undefine_consts()

public undefine_consts() :
Return values

undefine_func()

public undefine_func() :
Return values

undefine_funcs()

public undefine_funcs() :
Return values

undefine_interface()

public undefine_interface() :
Return values

undefine_interfaces()

public undefine_interfaces() :
Return values

undefine_magic_const()

public undefine_magic_const() :
Return values

undefine_magic_consts()

public undefine_magic_consts() :
Return values

undefine_namespace()

public undefine_namespace() :
Return values

undefine_namespaces()

public undefine_namespaces() :
Return values

undefine_superglobal()

public undefine_superglobal() :
Return values

undefine_superglobals()

public undefine_superglobals() :
Return values

undefine_trait()

public undefine_trait() :
Return values

undefine_traits()

public undefine_traits() :
Return values

undefine_use()

public undefine_use() :
Return values

undefine_uses()

public undefine_uses() :
Return values

undefine_var()

public undefine_var() :
Return values

undefine_vars()

public undefine_vars() :
Return values

undefineAlias()

Undefine PHPSandbox alias

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

You can pass a string of alias $name to undefine, or an array of alias names to undefine

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

String of alias name, or array of alias names to undefine

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineAliases()

Undefine PHPSandbox aliases by array

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

You can pass an array of alias names to undefine, or an empty array or null argument to undefine all aliases

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

Array of alias names to undefine. Passing an empty array or no argument will result in undefining all aliases

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineClass()

Undefine PHPSandbox class

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

You can pass a string of class $name to undefine, or an array of class names to undefine

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

String of class name or an array of class names to undefine

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineClasses()

Undefine PHPSandbox classes by array

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

You can pass an array of class names to undefine, or an empty array or null argument to undefine all classes

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

Array of class names to undefine. Passing an empty array or no argument will result in undefining all classes

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineConst()

Undefine PHPSandbox constant

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

You can pass a string of constant $name to undefine, or an array of constant names to undefine

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

String of constant name or array of constant names to undefine

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineConsts()

Undefine PHPSandbox constants by array

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

You can pass an array of constant names to undefine, or an empty array or null argument to undefine all constants

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

Array of constant names to undefine. Passing an empty array or no argument will result in undefining all constants

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineFunc()

Undefine PHPSandbox function

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

You can pass a string of function $name to undefine, or pass an array of function names to undefine

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

String of function name or array of function names to undefine

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineFuncs()

Undefine PHPSandbox functions by array

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

You can pass an array of function names to undefine, or an empty array or null argument to undefine all functions

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

Array of function names to undefine. Passing an empty array or no argument will result in undefining all functions

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineInterface()

Undefine PHPSandbox interface

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

You can pass a string of interface $name to undefine, or an array of interface names to undefine

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

String of interface name or an array of interface names to undefine

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineInterfaces()

Undefine PHPSandbox interfaces by array

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

You can pass an array of interface names to undefine, or an empty array or null argument to undefine all interfaces

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

Array of interface names to undefine. Passing an empty array or no argument will result in undefining all interfaces

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineMagicConst()

Undefine PHPSandbox magic constant

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

You can pass an a string of magic constant $name to undefine, or array of magic constant names to undefine

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

String of magic constant name, or array of magic constant names to undefine

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineMagicConsts()

Undefine PHPSandbox magic constants by array

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

You can pass an array of magic constant names to undefine, or an empty array or null argument to undefine all magic constants

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

Array of magic constant names to undefine. Passing an empty array or no argument will result in undefining all magic constants

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineNamespace()

Undefine PHPSandbox namespace

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

You can pass a string of namespace $name to undefine, or an array of namespace names to undefine

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

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

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineNamespaces()

Undefine PHPSandbox namespaces by array

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

You can pass an array of namespace names to undefine, or an empty array or null argument to undefine all namespaces

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

Array of namespace names to undefine. Passing an empty array or no argument will result in undefining all namespaces

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineSuperglobal()

Undefine PHPSandbox superglobal or superglobal key

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

You can pass a string of superglobal $name to undefine, or a superglobal $key to undefine, or an array of superglobal names to undefine, or an an associative array of superglobal names and keys to undefine

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

String of superglobal $name, or array of superglobal names, or associative array of superglobal names and keys to undefine

$key : string|null = null

String of superglobal $key to undefine

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineSuperglobals()

Undefine PHPSandbox superglobals by array

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

You can pass an array of superglobal names to undefine, or an associative array of superglobals names and key to undefine, or an empty array or null to undefine all superglobals

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

Associative array of superglobal names and keys or array of superglobal names to undefine

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineTrait()

Undefine PHPSandbox trait

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

You can pass a string of trait $name to undefine, or an array of trait names to undefine

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

String of trait name or an array of trait names to undefine

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineTraits()

Undefine PHPSandbox traits by array

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

You can pass an array of trait names to undefine, or an empty array or null argument to undefine all traits

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

Array of trait names to undefine. Passing an empty array or no argument will result in undefining all traits

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineUse()

Undefine PHPSandbox use (or alias)

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

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

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

String of use (or alias) name, or array of use (or alias) names to undefine

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineUses()

Undefine PHPSandbox uses (or aliases) by array

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

Array of use (or alias) names to undefine. Passing an empty array or no argument will result in undefining all uses (or aliases)

Tags
alias

undefineAliases();

You can pass an array of use (or alias) names to undefine, or an empty array or null argument to undefine all uses (or aliases)

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineVar()

Undefine PHPSandbox variable

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

You can pass a string of variable $name to undefine, or an array of variable names to undefine

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

String of variable name or an array of variable names to undefine

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

undefineVars()

Undefine PHPSandbox variables by array

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

You can pass an array of variable names to undefine, or an empty array or null argument to undefine all variables

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

Array of variable names to undefine. Passing an empty array or no argument will result in undefining all variables

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unset_error_handler()

public unset_error_handler() :
Return values

unset_exception_handler()

public unset_exception_handler() :
Return values

unset_validation_error_handler()

public unset_validation_error_handler() :
Return values

unsetAliasValidator()

Unset validation callable for aliases

public unsetAliasValidator() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unsetClassValidator()

Unset validation callable for classes

public unsetClassValidator() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unsetConstValidator()

Unset validation callable for constants

public unsetConstValidator() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unsetErrorHandler()

Unset error handler

public unsetErrorHandler() : self

This function unsets the sandbox error handler.

Return values
self

Returns the PHPSandbox instance for fluent querying

unsetExceptionHandler()

Unset exception handler

public unsetExceptionHandler() : PHPSandbox

This function unsets the sandbox exception handler.

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unsetFuncValidator()

Unset validation callable for functions

public unsetFuncValidator() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unsetGlobalValidator()

Unset validation callable for globals

public unsetGlobalValidator() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unsetInterfaceValidator()

Unset validation callable for interfaces

public unsetInterfaceValidator() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unsetKeywordValidator()

Unset validation callable for keywords

public unsetKeywordValidator() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unsetMagicConstValidator()

Unset validation callable for magic constants

public unsetMagicConstValidator() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unsetNamespaceValidator()

Unset validation callable for namespaces

public unsetNamespaceValidator() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unsetOperatorValidator()

Unset validation callable for operators

public unsetOperatorValidator() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unsetPrimitiveValidator()

Unset validation callable for primitives

public unsetPrimitiveValidator() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unsetSuperglobalValidator()

Unset validation callable for superglobals

public unsetSuperglobalValidator() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unsetTraitValidator()

Unset validation callable for traits

public unsetTraitValidator() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unsetTypeValidator()

Unset validation callable for types

public unsetTypeValidator() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unsetUseValidator()

Unset validation callable for uses (aka aliases)

public unsetUseValidator() : PHPSandbox
Tags
alias

unsetAliasValidator();

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unsetValidationErrorHandler()

Unset validation error handler

public unsetValidationErrorHandler() : PHPSandbox

This function unsets the sandbox validation error handler.

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unsetValidator()

Unset validation callable for specified $type

public unsetValidator(string $type) : PHPSandbox
Parameters
$type : string

String of $type to unset

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

unsetVarValidator()

Unset validation callable for variables

public unsetVarValidator() : PHPSandbox
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

validate()

Validate passed callable for execution

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

The callable or string of code to validate

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

validation_error()

public validation_error() :
Return values

validationError()

Invoke sandbox error validation handler if it exists, throw Error otherwise

public validationError(Throwable|string $error, int $code[, Node|null $node = null ][, mixed $data = null ][, Throwable|null $previous = null ]) : mixed
Parameters
$error : Throwable|string

Exception to throw if exception is not handled, or error message string

$code : int

The error code

$node : Node|null = null

The error parser node

$data : mixed = null

The error data

$previous : Throwable|null = null

The previous exception thrown

Tags
throws
Throwable
Return values
mixed

whitelist()

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

public whitelist(string|array<string|int, mixed> $type[, string|array<string|int, mixed>|null $name = null ]) : 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

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

Associative array or string of whitelist type to set

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

Array or string of whitelist name to set

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

whitelist_alias()

public whitelist_alias() :
Return values

whitelist_class()

public whitelist_class() :
Return values

whitelist_const()

public whitelist_const() :
Return values

whitelist_func()

public whitelist_func() :
Return values

whitelist_global()

public whitelist_global() :
Return values

whitelist_interface()

public whitelist_interface() :
Return values

whitelist_keyword()

public whitelist_keyword() :
Return values

whitelist_magic_const()

public whitelist_magic_const() :
Return values

whitelist_namespace()

public whitelist_namespace() :
Return values

whitelist_operator()

public whitelist_operator() :
Return values

whitelist_primitive()

public whitelist_primitive() :
Return values

whitelist_superglobal()

public whitelist_superglobal() :
Return values

whitelist_trait()

public whitelist_trait() :
Return values

whitelist_type()

public whitelist_type() :
Return values

whitelist_use()

public whitelist_use() :
Return values

whitelist_var()

public whitelist_var() :
Return values

whitelistAlias()

Whitelist alias

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

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

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

String of alias names or array of alias names to whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

whitelistClass()

Whitelist class

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

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

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

String of class name or array of class names to whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

whitelistConst()

Whitelist constant

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

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

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

String of constant name or array of constant names to whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

whitelistFunc()

Whitelist function

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

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

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

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

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

whitelistGlobal()

Whitelist global

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

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

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

String of global name or array of global names to whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

whitelistInterface()

Whitelist interface

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

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

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

String of interface name or array of interface names to whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

whitelistKeyword()

Whitelist keyword

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

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

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

String of keyword name or array of keyword names to whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

whitelistMagicConst()

Whitelist magic constant

public whitelistMagicConst(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 whitelist

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

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

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

whitelistNamespace()

Whitelist namespace

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

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

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

String of namespace name or array of namespace names to whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

whitelistOperator()

Whitelist operator

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

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

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

String of operator name or array of operator names to whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

whitelistPrimitive()

Whitelist primitive

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

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

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

String of primitive name or array of primitive names to whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

whitelistSuperglobal()

Whitelist superglobal or superglobal key

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

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 whitelist

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 whitelist

$key : string|null = null

String of superglobal key to whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

whitelistTrait()

Whitelist trait

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

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

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

String of trait name or array of trait names to whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

whitelistType()

Whitelist type

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

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

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

String of type name or array of type names to whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

whitelistUse()

Whitelist use (or alias)

public whitelistUse(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 whitelist

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

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

Tags
alias

whitelistAlias();

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

whitelistVar()

Whitelist variable

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

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

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

String of variable name or array of variable names to whitelist

Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

autoDefine()

Automatically define variables passed to disassembled closure

protected autoDefine(FunctionParser $disassembled_closure) : PHPSandbox
Parameters
$disassembled_closure : FunctionParser
Return values
PHPSandbox

Returns the PHPSandbox instance for fluent querying

autoWhitelist()

Automatically whitelisted trusted code

protected autoWhitelist(string $code[, bool $appended = false ]) : mixed
Parameters
$code : string

String of trusted $code to automatically whitelist

$appended : bool = false

Flag if this code ir prended or appended (true = appended)

Tags
throws
Throwable

Throw exception if code cannot be parsed for whitelisting

Return values
mixed

Return result of error handler if $code could not be parsed

disassemble()

Disassemble callable to string

protected disassemble(callable $closure) : string
Parameters
$closure : callable

The callable to disassemble

Tags
throws
Throwable

Throw exception if callable is passed and FunctionParser library is missing

Return values
string

Return the disassembled code string

normalizeAlias()

Normalize alias name. This is an internal PHPSandbox function.

protected normalizeAlias(string|array<string|int, mixed> $name) : string|array<string|int, mixed>
Parameters
$name : string|array<string|int, mixed>

String of the alias $name, or array of strings to normalize

Return values
string|array<string|int, mixed>

Returns the normalized alias string or an array of normalized strings

normalizeClass()

Normalize class name. This is an internal PHPSandbox function.

protected normalizeClass(string|array<string|int, mixed> $name) : string|array<string|int, mixed>
Parameters
$name : string|array<string|int, mixed>

String of the class $name to normalize

Return values
string|array<string|int, mixed>

Returns the normalized class string or an array of normalized strings

normalizeFunc()

Normalize function name. This is an internal PHPSandbox function.

protected normalizeFunc(string|array<string|int, mixed> $name) : string|array<string|int, mixed>
Parameters
$name : string|array<string|int, mixed>

String of the function $name, or array of strings to normalize

Return values
string|array<string|int, mixed>

Returns the normalized function string or an array of normalized strings

normalizeInterface()

Normalize interface name. This is an internal PHPSandbox function.

protected normalizeInterface(string|array<string|int, mixed> $name) : string|array<string|int, mixed>
Parameters
$name : string|array<string|int, mixed>

String of the interface $name, or array of strings to normalize

Return values
string|array<string|int, mixed>

Returns the normalized interface string or an array of normalized strings

normalizeKeyword()

Normalize keyword name. This is an internal PHPSandbox function.

protected normalizeKeyword(string|array<string|int, mixed> $name) : string|array<string|int, mixed>
Parameters
$name : string|array<string|int, mixed>

String of the keyword $name, or array of strings to normalize

Return values
string|array<string|int, mixed>

Returns the normalized keyword string or an array of normalized strings

normalizeMagicConst()

Normalize magic constant name. This is an internal PHPSandbox function.

protected normalizeMagicConst(string|array<string|int, mixed> $name) : string|array<string|int, mixed>
Parameters
$name : string|array<string|int, mixed>

String of the magic constant $name, or array of strings to normalize

Return values
string|array<string|int, mixed>

Returns the normalized magic constant string or an array of normalized strings

normalizeNamespace()

Normalize namespace name. This is an internal PHPSandbox function.

protected normalizeNamespace(string|array<string|int, mixed> $name) : string|array<string|int, mixed>
Parameters
$name : string|array<string|int, mixed>

String of the namespace $name, or array of strings to normalize

Return values
string|array<string|int, mixed>

Returns the normalized namespace string or an array of normalized strings

normalizeOperator()

Normalize operator name. This is an internal PHPSandbox function.

protected normalizeOperator(string|array<string|int, mixed> $name) : string|array<string|int, mixed>
Parameters
$name : string|array<string|int, mixed>

String of the operator $name, or array of strings to normalize

Return values
string|array<string|int, mixed>

Returns the normalized operator string or an array of normalized strings

normalizePrimitive()

Normalize primitive name. This is an internal PHPSandbox function.

protected normalizePrimitive(string|array<string|int, mixed> $name) : string|array<string|int, mixed>
Parameters
$name : string|array<string|int, mixed>

String of the primitive $name, or array of strings to normalize

Return values
string|array<string|int, mixed>

Returns the normalized primitive string or an array of normalized strings

normalizeSuperglobal()

Normalize superglobal name. This is an internal PHPSandbox function.

protected normalizeSuperglobal(string|array<string|int, mixed> $name) : string|array<string|int, mixed>
Parameters
$name : string|array<string|int, mixed>

String of the superglobal $name, or array of strings to normalize

Return values
string|array<string|int, mixed>

Returns the normalized superglobal string or an array of normalized strings

normalizeTrait()

Normalize trait name. This is an internal PHPSandbox function.

protected normalizeTrait(string|array<string|int, mixed> $name) : string|array<string|int, mixed>
Parameters
$name : string|array<string|int, mixed>

String of the trait $name, or array of strings to normalize

Return values
string|array<string|int, mixed>

Returns the normalized trait string or an array of normalized strings

normalizeType()

Normalize type name. This is an internal PHPSandbox function.

protected normalizeType(string|array<string|int, mixed> $name) : string|array<string|int, mixed>
Parameters
$name : string|array<string|int, mixed>

String of the type $name, or array of strings to normalize

Return values
string|array<string|int, mixed>

Returns the normalized type string or an array of normalized strings

normalizeUse()

Normalize use (or alias) name. This is an internal PHPSandbox function.

protected normalizeUse(string|array<string|int, mixed> $name) : string|array<string|int, mixed>
Parameters
$name : string|array<string|int, mixed>

String of the use (or alias) $name, or array of strings to normalize

Tags
alias

normalizeAlias();

Return values
string|array<string|int, mixed>

Returns the normalized use (or alias) string or an array of normalized strings

prepareAliases()

Prepare defined aliases for execution

protected prepareAliases() : string
Tags
throws
Throwable

Throws exception if validation error occurs

Return values
string

Prepared string of aliases (or uses) output

prepareConsts()

Prepare defined constants for execution

protected prepareConsts() : string
Tags
throws
Throwable

Throws exception if validation error occurs

Return values
string

Prepared string of constants output

prepareNamespaces()

Prepare defined namespaces for execution

protected prepareNamespaces() : string
Tags
throws
Throwable

Throws exception if validation error occurs

Return values
string

Prepared string of namespaces output

prepareUses()

Prepare defined uses (or aliases) for execution

protected prepareUses() : string
Tags
alias

prepareAliases();

throws
Throwable

Throws exception if validation error occurs

Return values
string

Prepared string of aliases (or uses) output

prepareVars()

Prepare defined variables for execution

protected prepareVars() : string
Tags
throws
Throwable

Throws exception if validation error occurs

Return values
string

Prepared string of variable output

Search results