Skip to content

Commit

Permalink
Merge pull request #7 from thunderer/php74-method-property-exists-issue
Browse files Browse the repository at this point in the history
PHP 7.4 method and property exists functions bug mitigation
  • Loading branch information
thunderer authored Mar 18, 2020
2 parents b4a4454 + cab4257 commit e807702
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ php:
- 7.1
- 7.2
- 7.3
- 7.4
- hhvm
- nightly

Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
test: test-phpunit
test-phpunit:
PHP_VERSION=7.3 docker-compose run --rm php php -v && php vendor/bin/phpunit --coverage-text
PHP_VERSION=7.4 docker-compose run --rm php php -v
PHP_VERSION=7.4 docker-compose run --rm php php vendor/bin/phpunit --coverage-text
test-phpunit-local:
php -v
php vendor/bin/phpunit --coverage-text
Expand All @@ -9,7 +10,8 @@ travis:
PHP_VERSION=7.1 make travis-job
PHP_VERSION=7.2 make travis-job
PHP_VERSION=7.3 make travis-job
PHP_VERSION=7.3 docker-compose run --rm composer composer config --unset platform
PHP_VERSION=7.4 make travis-job
PHP_VERSION=7.4 docker-compose run --rm composer composer config --unset platform
travis-job:
docker-compose run --rm composer composer config platform.php ${PHP_VERSION}
docker-compose run --rm composer composer update -q
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"php": "^7.1"
"php": "^7.1|^8.0"
},
"require-dev": {
"ext-json": "*",
Expand Down
4 changes: 3 additions & 1 deletion src/Enum/EnumTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ final private static function resolveMembers(): void
return;
}

if(false === method_exists($class, 'resolve')) {
// reflection instead of method_exists because of PHP 7.4 bug #78632
// @see https://bugs.php.net/bug.php?id=78632
if(false === (new \ReflectionClass($class))->hasMethod('resolve')) {
throw PlatenumException::fromMissingResolve($class);
}
$members = static::resolve();
Expand Down
4 changes: 3 additions & 1 deletion src/Enum/StaticEnumTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ trait StaticEnumTrait
final private static function resolve(): array
{
$class = static::class;
if(false === property_exists($class, 'mapping')) {
// reflection instead of property_exists because of PHP 7.4 bug #78632
// @see https://bugs.php.net/bug.php?id=78632
if(false === (new \ReflectionClass($class))->hasProperty('mapping')) {
throw PlatenumException::fromMissingMappingProperty($class);
}

Expand Down

0 comments on commit e807702

Please sign in to comment.