From 0e600665bbab5a6f71991eeade690a4ed8b1729d Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Fri, 5 Feb 2016 10:20:06 -0500 Subject: [PATCH] Also catch static invocations of non-static methods --- lib/StatementsChecker.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/StatementsChecker.php b/lib/StatementsChecker.php index b1e13e673..50d07f269 100644 --- a/lib/StatementsChecker.php +++ b/lib/StatementsChecker.php @@ -860,6 +860,7 @@ class StatementsChecker } else { $absolute_class = ($this->_namespace ? '\\' : '') . $this->_namespace . '\\' . $this->_class_name; } + } elseif ($this->_check_classes) { ClassChecker::checkClassName($stmt->class, $this->_namespace, $this->_aliased_classes, $this->_file_name); $absolute_class = ClassChecker::getAbsoluteClassFromName($stmt->class, $this->_namespace, $this->_aliased_classes); @@ -881,6 +882,17 @@ class StatementsChecker throw new CodeException('Method ' . $method_id . ' is not static', $this->_file_name, $stmt->getLine()); } } + else { + if ($stmt->class->parts[0] === 'self' && $stmt->name !== '__construct') { + if (!isset(self::$_static_methods[$method_id])) { + self::_extractReflectionMethodInfo($method_id); + } + + if (!self::$_static_methods[$method_id]) { + throw new CodeException('Cannot call non-static method ' . $method_id . ' as if it were static', $this->_file_name, $stmt->getLine()); + } + } + } $return_types = $this->_getMethodReturnTypes($method_id);