0

I try to solve this error:

main.CRITICAL: Deprecated Functionality: Creation of dynamic property VENDOR\MODULE\Model\RedsysFactory::$helper is deprecated in /var/www/vhosts/xxxxxx.com/httpdocs/app/code/VENDOR/MODULE/Model/FILE.php on line 71 [] [] main.ERROR: Please provide payment for the order. [] []

LINE 71 SAID: $this->helper = $helper;

I try to use this code:

    /**
 * Use the fully-qualified AllowDynamicProperties, otherwise the #[AllowDynamicProperties] attribute on "MyClass" WILL NOT WORK.
 */
use \AllowDynamicProperties;

#[AllowDynamicProperties]
class MyClass
{

but don´t work

Any idea

1
  • hi dear, can you share the full code? Commented Feb 12, 2024 at 5:08

3 Answers 3

1

Define the helper class like this

<?php
namespace ....

use Vendor\Modulename\Helper\Data;


class MyClass
{
    protected $helper;
    
    
    public function __construct(
        Data $helper
    ) {
        $this->helper = $helper;
        
    }
    
}
1

Dynamic properties have been deprecated in php 8.2 and will gives fatal error from php 9.0 so declaring explicitly the properties is a more long-term solution than just use AllowDynamicProperties.

You can find a correct usage of this attribute here:

#[\AllowDynamicProperties]
class MyClass { }

or

use AllowDynamicProperties;

#[AllowDynamicProperties]
class MyClass { }

In my Magento 2 projects I explicitly declared the missing properties writing this script to avoid to do it manually. It:

  • recursively open all the php files in a Magento module
  • thanks to ReflectionClass get information on constructor and properties
  • generate the property declarations missing
  • add the declarations in the php file.
3
  • i have putted fix_dynamic_properties.php on webroot of magento and executed php fix_dynamic_properties.php 0 0 app/code/MyVendor/MyModule/ but its giving me error like PHP Fatal error: Uncaught UnexpectedValueException: RecursiveDirectoryIterator::__construct(1): Failed to open directory: No such file or directory can you help what is wrong ? Commented Jan 15 at 10:38
  • @RizwanKhan there was an error in the third parameter validation, I just fixed it, if you try it again it works. Commented Jan 16 at 11:37
  • Thanks, i'll try, Also I got a short workaround shortcut in phpstorm for this type of fix. Commented Jan 17 at 5:26
1

You get this error if you call your class like below

use Vendor\Modulename\Helper\Data as Helper;

class MyClass
{
    public function __construct(
        Helper $helper
    ) {
        $this->helper = $helper;
    }
}

You need to modify this as

use Vendor\Modulename\Helper\Data as Helper;

class MyClass
{
    protected $helper;

    public function __construct(
        Helper $helper
    ) {
        $this->helper = $helper;
    }
}

First code you have not declared your property.

Secode code when you add the property as

protected $helper;

Its not a dynamic property any more

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.