Skip to content

Instantly share code, notes, and snippets.

@dbellettini
Created July 25, 2018 17:01
Show Gist options
  • Save dbellettini/338536fa16abe0146655ebd4ea937e51 to your computer and use it in GitHub Desktop.
Save dbellettini/338536fa16abe0146655ebd4ea937e51 to your computer and use it in GitHub Desktop.
Why PHP sucks, try to run this!
<?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