예제 #1
0
 /**
  * @param                                    $fileName
  * @param \PhpParser\Node\Expr\PropertyFetch $node
  */
 function run($fileName, $node, ClassLike $inside = null, Scope $scope = null)
 {
     if ($node->var instanceof Variable) {
         if (is_string($node->var->name) && $node->var->name == 'this') {
             if ($inside instanceof Trait_) {
                 return;
             }
             if (!$inside) {
                 $this->emitError($fileName, $node, self::TYPE_SCOPE_ERROR, "Can't use \$this outside of a class");
                 return;
             }
             if (!is_string($node->name)) {
                 // Variable method name.  Yuck!
                 return;
             }
             //echo "Access ".$node->var->name."->".$node->name."\n";
             $property = Util::findProperty($inside, $node->name, $this->symbolTable);
             if (!$property) {
                 //$this->emitError($fileName, $node, "Unknown property", "Accessing unknown property of $inside->namespacedName: \$this->" . $node->name);
                 return;
             }
         }
     }
 }
예제 #2
0
 function inferPropertyFetch(Node\Expr\PropertyFetch $expr, $inside, $scope)
 {
     $class = $this->inferType($inside, $expr->var, $scope);
     if (!empty($class) && $class[0] != "!") {
         if (gettype($expr->name) == 'string') {
             $classDef = $this->index->getClass($class);
             if ($classDef) {
                 $prop = Util::findProperty($classDef, strval($expr->name), $this->index);
                 if ($prop) {
                     /*
                     						$type = $prop->getAttribute("namespacedType") ?: "";
                     						if(!empty($type)) {
                     							if($type[0]=='\\') {
                     								$type=substr($type,1);
                     							}
                     							return $type;
                     						}*/
                 }
             }
         }
     }
     return Scope::MIXED_TYPE;
 }