libvips / php-vips

php binding for libvips
MIT License
618 stars 25 forks source link

Avoid “Deprecate dynamic properties” warning in PHP 8.2 #159

Closed chregu closed 2 years ago

chregu commented 2 years ago

PHP 8.2 deprecates access to dynamic properties, if not explicitly allowed through set/get or an annotation. Therefor PHPStan fails for some reason in \Jcupitt\Vips\ImageAutodoc, even though it is defined in the Image class, see for example here https://github.com/rokka-io/imagine-vips/actions/runs/3236307918/jobs/5301940309

Adding set and get to ImageAutodoc prevents this "fail".

More details about this here https://wiki.php.net/rfc/deprecate_dynamic_properties

(PHP 8.2 is not released yet and "normal" code runs normally, just PHPStan fails currently).

This should also prevent a fatal error, if that is really removed in PHP 9.0 (set/get won't be removed, just implicit dynamic properties)

kleisauke commented 2 years ago

Perhaps an alternative solution is to mark the Image class or abstract ImageAutodoc class with the #[AllowDynamicProperties] attribute? This should be fully backwards-compatible with earlier PHP versions according to the RFC mentioned above.

jcupitt commented 2 years ago

Ooop, sorry Kleis, I missed your comment. Shall I revert?

kleisauke commented 2 years ago

I wasn't sure whether PHPStan supports that attribute and if that would fix it, so perhaps a revert is not necessary.

chregu commented 2 years ago

That's the other alternative, but then that maybe will break with PHP 9 again (Don't think that's totally decided yet). The abstract functions for set and get seem to be the future proof way.