Context
in package
Table of Contents
Properties
- $assigned_var_ids : array<string, int>
- A list of vars that have been assigned to
- $branch_point : int|null
- If we've branched from the main scope, a byte offset for where that branch happened
- $break_types : array<int, "loop"|"switch">
- What does break mean in this context?
- $byref_constraints : array<string, ReferenceConstraint>
- A list of variables that have been passed by reference (where we know their type)
- $calling_function_id : string|null
- $calling_method_id : lowercase-string|null
- $case_scope : CaseScope|null
- $check_classes : bool
- $check_consts : bool
- $check_functions : bool
- $check_methods : bool
- $check_variables : bool
- $clauses : array<int, Clause>
- A list of clauses in Conjunctive Normal Form
- $collect_exceptions : bool
- Whether or not to track exceptions
- $collect_initializations : bool
- Whether or not to do a deep analysis and collect initializations from private or final methods
- $collect_mutations : bool
- Whether or not to do a deep analysis and collect mutations to this context
- $collect_nonprivate_initializations : bool
- Whether or not to do a deep analysis and collect initializations from public non-final methods
- $cond_referenced_var_ids : array<string, bool>
- A list of variables that have been referenced in conditionals
- $constants : array<string, Union>
- $error_suppressing : bool
- $external_mutation_free : bool
- $finally_scope : FinallyScope|null
- $has_returned : bool
- $if_body_context : Context|null
- $ignore_variable_method : bool
- $ignore_variable_property : bool
- $include_location : CodeLocation|null
- $initialized_methods : array<string, bool>
- Stored to prevent re-analysing methods when checking for initialised properties
- $inside_assignment : bool
- Whether or not we're inside an assignment
- $inside_call : bool
- Whether or not we're inside a function/method call
- $inside_class_exists : bool
- Whether or not we're inside a class_exists call, where we don't care about possibly undefined classes
- $inside_conditional : bool
- Whether or not we're inside the conditional of an if/where etc.
- $inside_general_use : bool
- Whether or not we're inside any other situation that treats a variable as used
- $inside_isset : bool
- Whether or not we're inside an isset call
- $inside_loop : bool
- $inside_negation : bool
- $inside_return : bool
- Whether or not we're inside a return expression
- $inside_throw : bool
- Whether or not we're inside a throw
- $inside_try : bool
- Whether or not we're inside a try block.
- $inside_unset : bool
- Whether or not we're inside an unset call, where we don't care about possibly undefined variables
- $is_global : bool
- $loop_scope : LoopScope|null
- $mutation_free : bool
- $parent : string|null
- $parent_remove_vars : array<string, true>
- $phantom_classes : array<lowercase-string, true>
- A list of classes checked with class_exists
- $phantom_files : array<string, bool>
- A list of files checked with file_exists
- $possibly_assigned_var_ids : array<string, bool>
- A list of vars that have been may have been assigned to
- $possibly_thrown_exceptions : array<string, array<string|int, CodeLocation>>
- A list of classes or interfaces that may have been thrown
- $protected_var_ids : array<string, bool>
- $pure : bool
- $reconciled_expression_clauses : array<int, string|int>
- A list of hashed clauses that have already been factored in
- $referenced_counts : array<string, int<0, max>>
- Keeps track of how many times a var_in_scope has been referenced. May not be set for all $vars_in_scope.
- $referenced_globals : array<string, true>
- A set of globals that are referenced somewhere.
- $references_in_scope : array<string, string>
- Maps references to referenced variables for the current scope.
- $references_possibly_from_confusing_scope : array<string, CodeLocation>
- A set of references that might still be in scope from a scope likely to cause confusion. This applies to references set inside a loop or if statement, since it's easy to forget about PHP's weird scope rules, and assigning to a reference will change the referenced variable rather than shadowing it.
- $references_to_external_scope : array<string, true>
- Set of references to variables in another scope. These references will be marked as used if they are assigned to.
- $self : string|null
- $strict_types : bool
- $vars_in_scope : array<string, Union>
- $vars_possibly_in_scope : array<string, bool>
Methods
- __destruct() : mixed
- decrementReferenceCount() : void
- Decrement the reference count of the variable that $ref_id is referring to. This needs to be done before $ref_id is changed to no longer reference its currently referenced variable, for example by unsetting, reassigning to another reference, or being shadowed by a global.
- defineGlobals() : void
- filterClauses() : array<int, Clause>
- getNewOrUpdatedVarIds() : array<int, string>
- getRedefinedVars() : array<string, Union>
- getScopeSummary() : string
- hasVariable() : bool
- insideUse() : bool
- isPhantomClass() : bool
- isSuppressingExceptions() : bool
- mergeExceptions() : void
- mergeFunctionExceptions() : void
- remove() : void
- removeDescendents() : void
- This method is used after assignments to variables to remove any existing items in $vars_in_scope that are now made redundant by an update to some data
- removeMutableObjectVars() : void
- removePossibleReference() : void
- Remove a variable from the context which might be a reference to another variable, or referenced by another variable. Leaves the variable as possibly-in-scope, unlike remove().
- removeReconciledClauses() : Clause>}
- removeVarFromConflictingClauses() : void
- update() : void
- Updates the parent context, looking at the changes within a block and then applying those changes, where necessary, to the parent context
- updateChecks() : void
- updateReferencesPossiblyFromConfusingScope() : void
- Updates the list of possible references from a confusing scope, such as a reference created in an if that might later be reused.
Properties
$assigned_var_ids
A list of vars that have been assigned to
public
array<string, int>
$assigned_var_ids
= []
$branch_point
If we've branched from the main scope, a byte offset for where that branch happened
public
int|null
$branch_point
= null
$break_types
What does break mean in this context?
public
array<int, "loop"|"switch">
$break_types
= []
'loop' means we're breaking out of a loop, 'switch' means we're breaking out of a switch
$byref_constraints
A list of variables that have been passed by reference (where we know their type)
public
array<string, ReferenceConstraint>
$byref_constraints
= []
$calling_function_id
public
string|null
$calling_function_id
= null
$calling_method_id
public
lowercase-string|null
$calling_method_id
= null
$case_scope
public
CaseScope|null
$case_scope
= null
$check_classes
public
bool
$check_classes
= true
$check_consts
public
bool
$check_consts
= true
$check_functions
public
bool
$check_functions
= true
$check_methods
public
bool
$check_methods
= true
$check_variables
public
bool
$check_variables
= true
$clauses
A list of clauses in Conjunctive Normal Form
public
array<int, Clause>
$clauses
= []
$collect_exceptions
Whether or not to track exceptions
public
bool
$collect_exceptions
= false
$collect_initializations
Whether or not to do a deep analysis and collect initializations from private or final methods
public
bool
$collect_initializations
= false
$collect_mutations
Whether or not to do a deep analysis and collect mutations to this context
public
bool
$collect_mutations
= false
$collect_nonprivate_initializations
Whether or not to do a deep analysis and collect initializations from public non-final methods
public
bool
$collect_nonprivate_initializations
= false
$cond_referenced_var_ids
A list of variables that have been referenced in conditionals
public
array<string, bool>
$cond_referenced_var_ids
= []
$constants
public
array<string, Union>
$constants
= []
$error_suppressing
public
bool
$error_suppressing
= false
$external_mutation_free
public
bool
$external_mutation_free
= false
Set by @psalm-external-mutation-free
$finally_scope
public
FinallyScope|null
$finally_scope
= null
$has_returned
public
bool
$has_returned
= false
$if_body_context
public
Context|null
$if_body_context
= null
$ignore_variable_method
public
bool
$ignore_variable_method
= false
$ignore_variable_property
public
bool
$ignore_variable_property
= false
$include_location
public
CodeLocation|null
$include_location
= null
$initialized_methods
Stored to prevent re-analysing methods when checking for initialised properties
public
array<string, bool>
$initialized_methods
= []
$inside_assignment
Whether or not we're inside an assignment
public
bool
$inside_assignment
= false
$inside_call
Whether or not we're inside a function/method call
public
bool
$inside_call
= false
$inside_class_exists
Whether or not we're inside a class_exists call, where we don't care about possibly undefined classes
public
bool
$inside_class_exists
= false
$inside_conditional
Whether or not we're inside the conditional of an if/where etc.
public
bool
$inside_conditional
= false
This changes whether or not the context is cloned
$inside_general_use
Whether or not we're inside any other situation that treats a variable as used
public
bool
$inside_general_use
= false
$inside_isset
Whether or not we're inside an isset call
public
bool
$inside_isset
= false
Inside issets Psalm is more lenient about certain things
$inside_loop
public
bool
$inside_loop
= false
$inside_negation
public
bool
$inside_negation
= false
$inside_return
Whether or not we're inside a return expression
public
bool
$inside_return
= false
$inside_throw
Whether or not we're inside a throw
public
bool
$inside_throw
= false
$inside_try
Whether or not we're inside a try block.
public
bool
$inside_try
= false
$inside_unset
Whether or not we're inside an unset call, where we don't care about possibly undefined variables
public
bool
$inside_unset
= false
$is_global
public
bool
$is_global
= false
$loop_scope
public
LoopScope|null
$loop_scope
= null
$mutation_free
public
bool
$mutation_free
= false
Set by @psalm-immutable
$parent
public
string|null
$parent
= null
$parent_remove_vars
public
array<string, true>
$parent_remove_vars
= []
$phantom_classes
A list of classes checked with class_exists
public
array<lowercase-string, true>
$phantom_classes
= []
$phantom_files
A list of files checked with file_exists
public
array<string, bool>
$phantom_files
= []
$possibly_assigned_var_ids
A list of vars that have been may have been assigned to
public
array<string, bool>
$possibly_assigned_var_ids
= []
$possibly_thrown_exceptions
A list of classes or interfaces that may have been thrown
public
array<string, array<string|int, CodeLocation>>
$possibly_thrown_exceptions
= []
$protected_var_ids
public
array<string, bool>
$protected_var_ids
= []
$pure
public
bool
$pure
= false
$reconciled_expression_clauses
A list of hashed clauses that have already been factored in
public
array<int, string|int>
$reconciled_expression_clauses
= []
$referenced_counts
Keeps track of how many times a var_in_scope has been referenced. May not be set for all $vars_in_scope.
public
array<string, int<0, max>>
$referenced_counts
= []
$referenced_globals
A set of globals that are referenced somewhere.
public
array<string, true>
$referenced_globals
= []
$references_in_scope
Maps references to referenced variables for the current scope.
public
array<string, string>
$references_in_scope
= []
With $b = &$a, this will contain ['$b' => '$a'].
All keys and values in this array are guaranteed to be set in $vars_in_scope.
To check if a variable was passed or returned by reference, or references an object property or array item, see Union::$by_ref.
$references_possibly_from_confusing_scope
A set of references that might still be in scope from a scope likely to cause confusion. This applies to references set inside a loop or if statement, since it's easy to forget about PHP's weird scope rules, and assigning to a reference will change the referenced variable rather than shadowing it.
public
array<string, CodeLocation>
$references_possibly_from_confusing_scope
= []
$references_to_external_scope
Set of references to variables in another scope. These references will be marked as used if they are assigned to.
public
array<string, true>
$references_to_external_scope
= []
$self
public
string|null
$self
= null
The name of the current class. Null if outside a class.
$strict_types
public
bool
$strict_types
= false
$vars_in_scope
public
array<string, Union>
$vars_in_scope
= []
$vars_possibly_in_scope
public
array<string, bool>
$vars_possibly_in_scope
= []
Methods
__destruct()
public
__destruct() : mixed
decrementReferenceCount()
Decrement the reference count of the variable that $ref_id is referring to. This needs to be done before $ref_id is changed to no longer reference its currently referenced variable, for example by unsetting, reassigning to another reference, or being shadowed by a global.
public
decrementReferenceCount(string $ref_id) : void
Parameters
- $ref_id : string
defineGlobals()
public
defineGlobals() : void
filterClauses()
public
static filterClauses(string $remove_var_id, array<string|int, Clause> $clauses[, Union|null $new_type = null ][, StatementsAnalyzer|null $statements_analyzer = null ]) : array<int, Clause>
Parameters
- $remove_var_id : string
- $clauses : array<string|int, Clause>
- $new_type : Union|null = null
- $statements_analyzer : StatementsAnalyzer|null = null
Return values
array<int, Clause>getNewOrUpdatedVarIds()
public
static getNewOrUpdatedVarIds(Context $original_context, Context $new_context) : array<int, string>
Parameters
Return values
array<int, string>getRedefinedVars()
public
getRedefinedVars(array<string, Union> $new_vars_in_scope[, bool $include_new_vars = false ]) : array<string, Union>
Parameters
- $new_vars_in_scope : array<string, Union>
- $include_new_vars : bool = false
Return values
array<string, Union>getScopeSummary()
public
getScopeSummary() : string
Return values
stringhasVariable()
public
hasVariable(string $var_name) : bool
Parameters
- $var_name : string
Return values
boolinsideUse()
public
insideUse() : bool
Return values
boolisPhantomClass()
public
isPhantomClass(string $class_name) : bool
Parameters
- $class_name : string
Return values
boolisSuppressingExceptions()
public
isSuppressingExceptions(StatementsAnalyzer $statements_analyzer) : bool
Parameters
- $statements_analyzer : StatementsAnalyzer
Return values
boolmergeExceptions()
public
mergeExceptions(Context $other_context) : void
Parameters
- $other_context : Context
mergeFunctionExceptions()
public
mergeFunctionExceptions(FunctionLikeStorage $function_storage, CodeLocation $codelocation) : void
Parameters
- $function_storage : FunctionLikeStorage
- $codelocation : CodeLocation
remove()
public
remove(string $remove_var_id[, bool $removeDescendents = true ]) : void
Parameters
- $remove_var_id : string
- $removeDescendents : bool = true
removeDescendents()
This method is used after assignments to variables to remove any existing items in $vars_in_scope that are now made redundant by an update to some data
public
removeDescendents(string $remove_var_id, Union $existing_type[, Union|null $new_type = null ][, StatementsAnalyzer|null $statements_analyzer = null ]) : void
Parameters
removeMutableObjectVars()
public
removeMutableObjectVars([bool $methods_only = false ]) : void
Parameters
- $methods_only : bool = false
removePossibleReference()
Remove a variable from the context which might be a reference to another variable, or referenced by another variable. Leaves the variable as possibly-in-scope, unlike remove().
public
removePossibleReference(string $remove_var_id) : void
Parameters
- $remove_var_id : string
removeReconciledClauses()
public
static removeReconciledClauses(array<string|int, Clause> $clauses, array<string, bool> $changed_var_ids) : Clause>}
Parameters
- $clauses : array<string|int, Clause>
- $changed_var_ids : array<string, bool>
Tags
Return values
Clause>}removeVarFromConflictingClauses()
public
removeVarFromConflictingClauses(string $remove_var_id[, Union|null $new_type = null ][, StatementsAnalyzer|null $statements_analyzer = null ]) : void
Parameters
- $remove_var_id : string
- $new_type : Union|null = null
- $statements_analyzer : StatementsAnalyzer|null = null
update()
Updates the parent context, looking at the changes within a block and then applying those changes, where necessary, to the parent context
public
update(Context $start_context, Context $end_context, bool $has_leaving_statements, array<string|int, mixed> $vars_to_update, array<string, bool> &$updated_vars) : void
Parameters
updateChecks()
public
updateChecks(Context $op_context) : void
Parameters
- $op_context : Context
updateReferencesPossiblyFromConfusingScope()
Updates the list of possible references from a confusing scope, such as a reference created in an if that might later be reused.
public
updateReferencesPossiblyFromConfusingScope(Context $confusing_scope_context, StatementsAnalyzer $statements_analyzer) : void
Parameters
- $confusing_scope_context : Context
- $statements_analyzer : StatementsAnalyzer