本文整理汇总了PHP中Variable::fromNodeInContext方法的典型用法代码示例。如果您正苦于以下问题:PHP Variable::fromNodeInContext方法的具体用法?PHP Variable::fromNodeInContext怎么用?PHP Variable::fromNodeInContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Variable
的用法示例。
在下文中一共展示了Variable::fromNodeInContext方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: visitStatic
/**
* @param Node $node
* A node to parse
*
* @return Context
* A new or an unchanged context resulting from
* parsing the node
*/
public function visitStatic(Node $node) : Context
{
$variable = Variable::fromNodeInContext($node->children['var'], $this->context, $this->code_base, false);
// If the element has a default, set its type
// on the variable
if (isset($node->children['default'])) {
$default_type = UnionType::fromNode($this->context, $this->code_base, $node->children['default']);
$variable->setUnionType($default_type);
}
// Note that we're not creating a new scope, just
// adding variables to the existing scope
$this->context->addScopeVariable($variable);
return $this->context;
}
示例2: visitVar
/**
* @param Node $node
* A node to parse
*
* @return Context
* A new or an unchanged context resulting from
* parsing the node
*/
public function visitVar(Node $node) : Context
{
$variable_name = AST::variableName($node);
// Check to see if the variable already exists
if ($this->context->getScope()->hasVariableWithName($variable_name)) {
$variable = $this->context->getScope()->getVariableWithName($variable_name);
// If we're assigning to an array element then we don't
// know what the constitutation of the parameter is
// outside of the scope of this assignment, so we add to
// its union type rather than replace it.
if ($this->is_dim_assignment) {
$variable->getUnionType()->addUnionType($this->right_type);
} else {
// If the variable isn't a pass-by-reference paramter
// we clone it so as to not disturb its previous types
// as we replace it.
if (!($variable instanceof Parameter && $variable->isPassByReference())) {
$variable = clone $variable;
}
if ($this->context->getIsConditional()) {
// If we're within a conditional, we shouldn't
// replace the type since the other side of
// the branch may have another type
$variable->getUnionType()->addUnionType($this->right_type);
} else {
$variable->setUnionType($this->right_type);
}
}
$this->context->addScopeVariable($variable);
return $this->context;
}
$variable = Variable::fromNodeInContext($this->assignment_node, $this->context, $this->code_base);
// Set that type on the variable
$variable->getUnionType()->addUnionType($this->right_type);
// Note that we're not creating a new scope, just
// adding variables to the existing scope
$this->context->addScopeVariable($variable);
return $this->context;
}
示例3: visitCatch
/**
* @param Node $node
* A node to parse
*
* @return Context
* A new or an unchanged context resulting from
* parsing the node
*/
public function visitCatch(Node $node) : Context
{
// Get the name of the class
$class_name = $node->children['class']->children['name'];
$clazz = null;
// If we can't figure out the class name (which happens
// from time to time), then give up
if (!empty($class_name)) {
$class_fqsen = FullyQualifiedClassName::fromStringInContext($class_name, $this->context);
// Check to see if the class actually exists
if ($this->code_base->hasClassWithFQSEN($class_fqsen)) {
$clazz = $this->code_base->getClassByFQSEN($class_fqsen);
} else {
Log::err(Log::EUNDEF, "call to method on undeclared class {$class_name}", $this->context->getFile(), $node->lineno);
}
}
$variable_name = AST::variableName($node->children['var']);
if (!empty($variable_name)) {
$variable = Variable::fromNodeInContext($node->children['var'], $this->context, $this->code_base, false);
if ($clazz) {
$variable->setUnionType($clazz->getUnionType());
}
$this->context->addScopeVariable($variable);
}
return $this->context;
}
示例4: visitVar
/**
* @param Node $node
* A node to parse
*
* @return Context
* A new or an unchanged context resulting from
* parsing the node
*/
public function visitVar(Node $node) : Context
{
$variable_name = AST::variableName($node);
// Check to see if the variable already exists
if ($this->context->getScope()->hasVariableWithName($variable_name)) {
$variable = $this->context->getScope()->getVariableWithName($variable_name);
$variable->setUnionType($this->right_type);
$this->context->addScopeVariable($variable);
return $this->context;
}
$variable = Variable::fromNodeInContext($this->assignment_node, $this->context, $this->code_base);
// Set that type on the variable
$variable->getUnionType()->addUnionType($this->right_type);
// Note that we're not creating a new scope, just
// adding variables to the existing scope
$this->context->addScopeVariable($variable);
return $this->context;
}