Created
July 25, 2018 17:01
-
-
Save dbellettini/338536fa16abe0146655ebd4ea937e51 to your computer and use it in GitHub Desktop.
Why PHP sucks, try to run this!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use PHPUnit\Framework\TestCase; | |
class NastyBugTest extends TestCase | |
{ | |
public function testBug() | |
{ | |
$data = [ | |
'c' => [ | |
[ | |
'q' => 1, | |
], | |
[ | |
'q' => 2, | |
], | |
[ | |
'q' => 3, | |
], | |
] | |
]; | |
$before = $data; | |
foreach ($data['c'] as &$c) { | |
} | |
$after = $data; | |
$this->assertSame($before, $after); | |
foreach ($data['c'] as $c) { | |
} | |
$after = $data; | |
$this->assertSame($before, $after); | |
} | |
public function testFix() | |
{ | |
$data = [ | |
'c' => [ | |
[ | |
'q' => 1, | |
], | |
[ | |
'q' => 2, | |
], | |
[ | |
'q' => 3, | |
], | |
] | |
]; | |
$before = $data; | |
foreach ($data['c'] as &$c1) { | |
} | |
$after = $data; | |
$this->assertSame($before, $after); | |
foreach ($data['c'] as $c2) { | |
} | |
$after = $data; | |
$this->assertSame($before, $after); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment