Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.

Commit 014bd53

Browse files
authored
Merge pull request #123 from mahone3297/dev_assign_of_new_by_reference
[bug fix] assigning the reurn value of new by referece is now deprecated.
2 parents f33c672 + 5f1b689 commit 014bd53

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

src/Visitor/Usage/FindLanguageDeprecations.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public function setPhpFileInfo(PhpFileInfo $phpFileInfo)
3232
*/
3333
public function enterNode(Node $node)
3434
{
35-
if ($node instanceof Node\Expr\AssignRef) {
35+
if ($node instanceof Node\Expr\AssignRef && $node->expr instanceof Node\Expr\New_) {
3636
$this->phpFileInfo->addDeprecatedLanguageUsage(
37-
new DeprecatedLanguageUsage('assign by reference(&=)', 'Since PHP 5.3 use normal assignment instead.', $node->getLine())
37+
new DeprecatedLanguageUsage('Assigning the return value of new by reference is now deprecated.', 'Since PHP 5.3 use normal assignment instead.', $node->getLine())
3838
);
3939
}
4040

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace SensioLabs\DeprecationDetector\Tests\Visitor\Usage;
4+
5+
use SensioLabs\DeprecationDetector\FileInfo\PhpFileInfo;
6+
use SensioLabs\DeprecationDetector\FileInfo\Usage\DeprecatedLanguageUsage;
7+
use SensioLabs\DeprecationDetector\Visitor\Usage\FindLanguageDeprecations;
8+
9+
class FindLanguageDeprecationsTest extends FindTestCase
10+
{
11+
// http://php.net/manual/en/migration53.deprecated.php
12+
public function testAssignOfNewByReference()
13+
{
14+
$source = <<<'EOC'
15+
<?php
16+
17+
$foo =& new Foo();
18+
19+
EOC;
20+
$splFileInfo = $this->prophesize('Symfony\Component\Finder\SplFileInfo');
21+
$phpFileInfo = $this->parsePhpFileFromStringAndTraverseWithVisitor(
22+
$file = PhpFileInfo::create($splFileInfo->reveal()),
23+
$source,
24+
new FindLanguageDeprecations()
25+
);
26+
27+
$this->assertEquals(
28+
array(
29+
new DeprecatedLanguageUsage('Assigning the return value of new by reference is now deprecated.', 'Since PHP 5.3 use normal assignment instead.', 3),
30+
),
31+
$phpFileInfo->getDeprecatedLanguageUsages()
32+
);
33+
}
34+
35+
public function testAssignByReference()
36+
{
37+
$source = <<<'EOC'
38+
<?php
39+
40+
$foo =& $bar;
41+
42+
EOC;
43+
$splFileInfo = $this->prophesize('Symfony\Component\Finder\SplFileInfo');
44+
$phpFileInfo = $this->parsePhpFileFromStringAndTraverseWithVisitor(
45+
$file = PhpFileInfo::create($splFileInfo->reveal()),
46+
$source,
47+
new FindLanguageDeprecations()
48+
);
49+
50+
$this->assertEquals(
51+
array(),
52+
$phpFileInfo->getDeprecatedLanguageUsages()
53+
);
54+
}
55+
}

0 commit comments

Comments
 (0)