Skip to content

Commit d403a67

Browse files
committed
enumerators and enum_exists function are available in php version greater or equal to 8.1
1 parent b850b5c commit d403a67

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/JsonMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public function map($json, $object)
300300
&& is_a($type, 'Traversable', true)
301301
) {
302302
$array = $this->createInstance($type, false, $jvalue);
303-
} else if (enum_exists($type)) {
303+
} else if (PHP_VERSION_ID >= 80100 && enum_exists($type)) {
304304
$evalue = $type::tryFrom($jvalue);
305305
if ($evalue === null) {
306306
throw new JsonMapper_Exception(

tests/Enums_PHP81_Test.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public function testEnumMapping()
3838
*/
3939
public function testBackedEnumPropertyIsMappedFromString(): void
4040
{
41+
if (PHP_VERSION_ID < 80100) {
42+
$this->markTestSkipped('Enumerators are not supported for PHP versions below 8.1');
43+
}
44+
4145
$json = (object) [
4246
'stringBackedEnum' => 'foo',
4347
'intBackedEnum' => 2,
@@ -60,6 +64,10 @@ public function testBackedEnumPropertyIsMappedFromString(): void
6064
*/
6165
public function testBackedEnumPropertyWithInvalidStringThrowsJsonMapperException(): void
6266
{
67+
if (PHP_VERSION_ID < 80100) {
68+
$this->markTestSkipped('Enumerators are not supported for PHP versions below 8.1');
69+
}
70+
6371
$json = (object) [
6472
'stringBackedEnum' => 'not-a-valid-enum-value',
6573
'intBackedEnum' => 'not-a-valid-enum-value',

0 commit comments

Comments
 (0)