*/ public function register() { return [\T_NEW]; } /** * Processes this test, when one of its tokens is encountered. * * @since 5.5 * * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * @param int $stackPtr The position of the current token in the * stack passed in $tokens. * * @return void */ public function process(File $phpcsFile, $stackPtr) { if (ScannedCode::shouldRunOnOrAbove('5.3') === false) { return; } $tokens = $phpcsFile->getTokens(); $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); if ($prevNonEmpty === false || $tokens[$prevNonEmpty]['type'] !== 'T_BITWISE_AND') { return; } $error = 'Assigning the return value of new by reference is deprecated in PHP 5.3'; $isError = false; $errorCode = 'Deprecated'; if (ScannedCode::shouldRunOnOrAbove('7.0') === true) { $error .= ' and has been removed in PHP 7.0'; $isError = true; $errorCode = 'Removed'; } MessageHelper::addMessage($phpcsFile, $error, $stackPtr, $isError, $errorCode); } }