Luracast / Restler

Simple and effective multi-format Web API Server to host your PHP API as Pragmatic REST and/or RESTful API
http://luracast.com/products/restler/
GNU Lesser General Public License v2.1
1.36k stars 315 forks source link

[BUGFIX] Fix PHP 8.0 deprecation warnings in Routes.php #650

Closed shaneneuerburg closed 3 years ago

shaneneuerburg commented 3 years ago

This is a backwards compatible fix that resolves PHP 8.0 deprecation warnings:

https://www.php.net/manual/en/reflectionparameter.isarray.php https://www.php.net/manual/en/reflectionparameter.getclass.php

For PHP prior to 8.0, this will retain the original method calls. For 8.0+, it will use the new getType method on ReflectionParameter.

Arul- commented 3 years ago

@shaneneuerburg thanks for contributing to Restler

Can you also make a pull request to the latest version of restler currently located in https://github.com/Arul-/reactive-restler ?

Arul- commented 3 years ago

I checked it out, existing code that checks for PHP 7.0.0 itself solves the problem with PHP 8

$type = version_compare(phpversion(), '7.0.0', '<') ?
                    // PHP < 7.0
                    ($param->isArray() ? 'array' : $param->getClass()) :
                    // PHP >= 7.0
                    ($param->getType() && $param->getType()->getName() === 'array' ? 'array' : (
                    $param->getType() && !$param->getType()->isBuiltin()
                        ? new ReflectionClass($param->getType()->getName())
                        : null
                    ));

is good enough! are you sure you are receiving warnings?

Arul- commented 3 years ago

I was wrong! sorry for the confusion, let me manually merge it to the v5 branch which soon appears in the master

Arul- commented 3 years ago

Manually merged in 3ab80a512fa90a7d89d5ef81dcb4c441f5ae6c91