Skip to content

Commit 8216514

Browse files
committed
Merge pull request Alexia#17 from macbre/deprecated-new-operator-with-reference
Add a check for new operator with reference
2 parents e0f5bde + 73ac58e commit 8216514

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

classes/tests/critical.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class critical {
2727
'variableInterpolation',
2828
'duplicateFunctionParameter',
2929
'reservedNames',
30-
'deprecatedFunctions'
30+
'deprecatedFunctions',
31+
'newOperatorWithReference',
3132
];
3233

3334
/**
@@ -116,5 +117,21 @@ public function _deprecatedFunctions($line) {
116117
}
117118
return false;
118119
}
120+
121+
/**
122+
* New objects cannot be assigned by reference
123+
*
124+
* @access public
125+
* @param string Line to test against.
126+
* @return boolean Line matches test.
127+
*/
128+
public function _newOperatorWithReference($line) {
129+
$regex = "#&\s?new\s#";
130+
131+
if (preg_match($regex, $line)) {
132+
return true;
133+
}
134+
return false;
135+
}
119136
}
120-
?>
137+
?>

testcases.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,8 @@ trait numeric { /*...*/ }
122122
mysql_tablename();
123123
mysql_thread_id();
124124
mysql_unbuffered_query();
125-
?>
125+
126+
// New objects cannot be assigned by reference
127+
class C {}
128+
$c =& new C;
129+
$c =&new C;

0 commit comments

Comments
 (0)