Menu

Commit [r101]  Maximize  Restore  History

Issue 25: Error: Notice: Trying to get property of non-object

tchule@hotmail.com 2012-02-09

changed /trunk/PhpCheckstyle/src/PHPCheckstyle.php
/trunk/PhpCheckstyle/src/PHPCheckstyle.php Diff Switch to side-by-side view
--- a/trunk/PhpCheckstyle/src/PHPCheckstyle.php
+++ b/trunk/PhpCheckstyle/src/PHPCheckstyle.php
@@ -2457,9 +2457,9 @@
 
 		// Manage new lines inside commments
 		$subTokens = preg_split('#(\r\n|\n|\r)#', $text, -1);
-		
+
 		foreach ($subTokens as $subToken) {
-	
+
 			if ($tok == T_DOC_COMMENT) {
 				$this->_ncssTotalLinesPhpdoc++;
 				$this->_ncssFileLinesPhpdoc++;
@@ -2686,7 +2686,14 @@
 	 * @return StatementItem
 	 */
 	private function _getCurrentStackItem() {
-		return end($this->_branchingStack);
+		$topItem = end($this->_branchingStack);
+		if ($topItem != null) {
+			return $topItem;
+		} else {
+			// In case of a empty stack, we are at the root of a PHP file (with no class or function).
+			// We return the default values
+			return new StatementItem(); 
+		}
 	}
 	/**
 	 * Check for silenced call to functons.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.