Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Assigning the return value of new by reference is deprecated #1

Open
wants to merge 2 commits into from

1 participant

@boedah

Hi Stanislav,

currently in the process of migrating some sites to PHP5.3 and found your check script very valuable.

I added a check for those PHP4-style "referenced object creation", which now emit a deprecation warning.
This also seems to happen at compile time, which is not mentioned in the docs.

So a

error_reporting(0);
die;
$f =& new Foo;

also triggers the deprecation error if it is not excluded in php.ini.

Best regards,
Peter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 9, 2011
  1. @boedah
  2. @boedah

    used linenum

    boedah authored
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 3 deletions.
  1. +10 −3 migrate.php
View
13 migrate.php
@@ -64,6 +64,7 @@ class Checker
const TOSTRING = 'tostring-noparam';
const NOSTATIC = 'no-static';
const NOTPUBLIC = 'not-public';
+ const NEW_REFERENCE = 'new-reference';
protected $_messages = array(
self::DEPRECATED => "Function '%s' is deprecated, its use is no longer recommended",
@@ -72,6 +73,7 @@ class Checker
self::TOSTRING => "__toString() method should not take any parameters",
self::NOSTATIC => "Magic method %s can not be declared as static",
self::NOTPUBLIC => "Magic method %s should be declared as public",
+ self::NEW_REFERENCE => "Assigning the return value of new by reference is deprecated",
);
protected $_deprecated = array(
@@ -321,11 +323,14 @@ public function check($filename)
}
// compact array
$tokens = array_values($tokens);
-
+ $linenum = 0;
while(list($i, $token) = each($tokens)) {
+ if (is_array($token)) {
+ $linenum = $token[2];
+ }
if($this->debug >= 3) {
if(is_int($token[0])) {
- echo sprintf("%d: Token %s(%d) -> %s\n", $token[2], token_name($token[0]), $token[0], substr($token[1], 0, 20));
+ echo sprintf("%d: Token %s(%d) -> %s\n", $linenum, token_name($token[0]), $token[0], substr($token[1], 0, 20));
} else {
echo sprintf("Token '%s'\n", $token);
}
@@ -351,7 +356,9 @@ public function check($filename)
&& $tokens[$i-2][0] != T_NEW) {
// function call
$this->checkFunctionCall($tokens[$i-1]);
- }
+ } else if ($token[0] == '=' && $tokens[$i+1][0] == '&' && $tokens[$i+2][0] === T_NEW) {
+ $this->warning(self::NEW_REFERENCE, $linenum);
+ }
}
return $this;
}
Something went wrong with that request. Please try again.