Skip to content

Commit 14edb7b

Browse files
Enum::CONST(): never return same instance
Enums shouldn't be compared with ===, but static accessors are now cached so === was working. Let's return a clone each time so === won't be true for values retrieved from these accessors. Note: this actually had no impact on the performance gains from a few commits ago.
1 parent facf0bf commit 14edb7b

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/Enum.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public static function __callStatic($name, $arguments)
232232
}
233233
return self::$instances[$class][$name] = new static($array[$name]);
234234
}
235-
return self::$instances[$class][$name];
235+
return clone self::$instances[$class][$name];
236236
}
237237

238238
/**

tests/EnumTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public function testStaticAccess()
143143
$this->assertEquals(new EnumFixture(EnumFixture::FOO), EnumFixture::FOO());
144144
$this->assertEquals(new EnumFixture(EnumFixture::BAR), EnumFixture::BAR());
145145
$this->assertEquals(new EnumFixture(EnumFixture::NUMBER), EnumFixture::NUMBER());
146+
$this->assertNotSame(EnumFixture::NUMBER(), EnumFixture::NUMBER());
146147
}
147148

148149
/**

0 commit comments

Comments
 (0)