Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.5]: Deprecation notices because of dynamic properties #14009

Closed
alexgit2k opened this issue Dec 8, 2023 · 1 comment
Closed

[4.5]: Deprecation notices because of dynamic properties #14009

alexgit2k opened this issue Dec 8, 2023 · 1 comment

Comments

@alexgit2k
Copy link

alexgit2k commented Dec 8, 2023

Description

Craft CMS still uses dynamic properties which are deprecated since PHP 8.2, see https://php.watch/versions/8.2/dynamic-properties-deprecated

In PHP 9.0, dynamic properties will result in a fatal error!

Steps to reproduce

  1. composer require phpstan/phpstan
  2. vendor/bin/phpstan analyse

Expected behavior

No deprecation notices

Actual behavior

Deprecation notices like:

Access to an undefined property craft\base\ElementInterface::$applicationDeadline. 
Access to an undefined property craft\base\ElementInterface::$badgeIcon. 
Access to an undefined property craft\base\ElementInterface::$benefitRelations. 
Access to an undefined property craft\base\ElementInterface::$cardColor. 
Access to an undefined property craft\base\ElementInterface::$cardImage. 
Access to an undefined property craft\base\ElementInterface::$cardLink. 
Access to an undefined property craft\base\ElementInterface::$cardLogo. 
Access to an undefined property craft\base\ElementInterface::$customEventDate. 
Access to an undefined property craft\base\ElementInterface::$disableCardImage. 
Access to an undefined property craft\base\ElementInterface::$duplicateOf. 
Access to an undefined property craft\base\ElementInterface::$eventEnd. 
Access to an undefined property craft\base\ElementInterface::$eventStart. 
Access to an undefined property craft\base\ElementInterface::$eventTargetGroup. 
Access to an undefined property craft\base\ElementInterface::$hardDelete. 
Access to an undefined property craft\base\ElementInterface::$id. 
Access to an undefined property craft\base\ElementInterface::$image. 
Access to an undefined property craft\base\ElementInterface::$kicker. 
Access to an undefined property craft\base\ElementInterface::$logo. 
Access to an undefined property craft\base\ElementInterface::$metaDescription. 
Access to an undefined property craft\base\ElementInterface::$moreInformation. 
Access to an undefined property craft\base\ElementInterface::$noindex. 
Access to an undefined property craft\base\ElementInterface::$ogDescription. 
Access to an undefined property craft\base\ElementInterface::$ogImage. 
Access to an undefined property craft\base\ElementInterface::$partnerCompany. 
Access to an undefined property craft\base\ElementInterface::$place. 
Access to an undefined property craft\base\ElementInterface::$productDates. 
Access to an undefined property craft\base\ElementInterface::$productTargetGroup. 
Access to an undefined property craft\base\ElementInterface::$scholarshipDescription. 
Access to an undefined property craft\base\ElementInterface::$showApplicationDeadline. 
Access to an undefined property craft\base\ElementInterface::$siteId. 
Access to an undefined property craft\base\ElementInterface::$title. 
Access to an undefined property craft\base\ElementInterface::$updatingFromDerivative. 
Access to an undefined property craft\base\ElementInterface::$uri. 
Access to an undefined property craft\base\ElementInterface::$useCustomEventDate. 
Access to an undefined property craft\base\FieldInterface::$handle. 
Access to an undefined property craft\base\FieldInterface::$id. 

Solution

Declare the properties or mark classes to allow dynamic properties, see https://www.php.net/manual/en/class.allowdynamicproperties.php

Craft CMS version

4.5

PHP version

8.2

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@brandonkelly
Copy link
Member

brandonkelly commented Dec 9, 2023

Craft doesn’t ever use dynamic properties – any class that extends yii\base\BaseObject will throw an exception if you try.

The issue is that PHPStan doesn’t recognize our @mixin ElementTrait here:

* @mixin ElementTrait

That works for PhpStorm, but PHPStan is more strict about it.

For now, you can just have PHPStan ignore those issues, as we’ve done for Craft 5 here:

cms/phpstan.neon

Lines 56 to 57 in 94c91e9

- '#^Access to an undefined property .*Interface\b.*::\$\w+\.$#'
- '#Cannot access property \$\w+ on .*Interface\.$#'

In the future, we are expecting this will be fixed via a new @phpstan-require-use tag we can add to interfaces which expect implementers to use a trait (phpstan/phpstan#9899).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants