Index: trunk/tools/code-utils/check-vars.php |
— | — | @@ -416,13 +416,29 @@ |
417 | 417 | |
418 | 418 | $this->checkClassName( $token ); |
419 | 419 | $currentToken[0] = self::CLASS_NAME; |
420 | | - } else if ( in_array( $token[0], array( T_REQUIRE, T_REQUIRE_ONCE, T_INCLUDE, T_INCLUDE_ONCE ) ) ) { |
| 420 | + } elseif ( in_array( $token[0], array( T_REQUIRE, T_REQUIRE_ONCE, T_INCLUDE, T_INCLUDE_ONCE ) ) ) { |
421 | 421 | $this->mStatus = self::IN_FUNCTION_REQUIRE; |
422 | 422 | $requirePath = ''; |
423 | 423 | continue; |
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
| 427 | + if ( self::isMeaningfulToken( $token ) && ( $lastMeaningfulToken[0] == T_THROW ) ) { |
| 428 | + if ( $token[0] == T_VARIABLE ) { |
| 429 | + // Probbly rethrowing from a catch, skip |
| 430 | + } elseif ( $token[0] == T_NEW ) { |
| 431 | + // Correct, a new class instance |
| 432 | + // TODO: Verify it inherits from Exception |
| 433 | + } else { |
| 434 | + // We only want the last interpretation, see r77752 |
| 435 | + // throw Exception; -> Exception is a constant |
| 436 | + // throw Exception("Foo"); -> Exception() is a function |
| 437 | + // throw new Exception("Foo"); -> Exception is a class. |
| 438 | + |
| 439 | + $this->warning( "Not using new when throwing token {$token[1]} in line $token[2], function {$this->mFunction}" ); |
| 440 | + } |
| 441 | + } |
| 442 | + |
427 | 443 | /* Try to guess the class of the variable */ |
428 | 444 | if ( in_array( $token[0], array( T_OBJECT_OPERATOR, T_PAAMAYIM_NEKUDOTAYIM ) ) ) { |
429 | 445 | $currentToken['base'] = $lastMeaningfulToken; |