in2code-de / femanagerextended

Example extension how to extend femanager for TYPO3
5 stars 4 forks source link

Warning - parameter createAction - PHP7 compatibility #3

Closed 7elix closed 6 years ago

7elix commented 7 years ago

Hi Alex,

there seems to be an issue with php7 + typo3 7.6 + overloading controller / action in my demo setup.

The EXT: femanagerextended follows the Best Practise declaration in https://docs.typo3.org/typo3cms/extensions/femanager/BestPractice/Index.html but

PHP Warning: Declaration of In2code\Femanagerextended\Controller\NewController::createAction(In2code\Femanagerextended\Domain\Model\User $user) should be compatible with In2code\Femanager\Controller\NewController::createAction(In2code\Femanager\Domain\Model\User $user)

Might be based on typoscript registration in tx_extbase.objects or php7 strict_types or ? Any hint?

olek07 commented 7 years ago

Hello! I have the same problem in my own extension. There are no problems with php 5.6, but with php 7, I get the warning: Declaration of Gigabonus\Gbfemanager\Controller\EditController::updateAction(Gigabonus\Gbfemanager\Domain\Model\User $user = NULL) should be compatible with In2code\Femanager\Controller\EditController::updateAction(In2code\Femanager\Domain\Model\User $user)

carodb commented 7 years ago

Did you guys check out: https://forge.typo3.org/issues/76290? Any luck with the mentioned fixes?

Haco commented 7 years ago

The Link is not accessible anymore. Any Info?

mediaessenz commented 7 years ago

See https://stackoverflow.com/questions/45563671/how-to-extend-femanager-controller-under-php-7

groetzner-net commented 7 years ago

I saw the comment on stackoverflow, but where must the initializeAction exactly be implemented. In the new Controller or in the original Controller? Can someone post a full example, please.

carodb commented 7 years ago

To follow best practices, override in your own new controller.


<?php
namespace ext\myExt\Controller;

class NewController extends \In2code\Femanager\Controller\NewController
{
    /**
     * Initialize create action for setting the right custom data type for the user.
     */
    public function initializeCreateAction() {
        if ($this->arguments->hasArgument('user')) {
            // Workaround to avoid php7 warnings of wrong type hint.
            /** @var \ext\myExt\Xclass\Extbase\Mvc\Controller\Argument $user */
            $user = $this->arguments['user'];
            $user->setDataType(\ext\myExt\Domain\Model\User::class);
        }
    }

  // Other custom functions...

}
groetzner-net commented 7 years ago

Can you also provide the Xclass Argument.php, please.

carodb commented 7 years ago

Hope it helps!


<?php
namespace ext\myExt\Xclass\Extbase\Mvc\Controller;

class Argument extends \TYPO3\CMS\Extbase\Mvc\Controller\Argument
{
    /**
     * Set data type for femanager workaround.
     * Workaround to avoid php7 warnings of wrong type hint.
     *
     * @param $dataType
     * @return $this
     */
    public function setDataType($dataType) {
        $this->dataType = $dataType;
        return $this;
    }
}
Nageshwar commented 6 years ago

I am getting the same error, please let me know if it worked for anyone? and how?

carodb commented 6 years ago

Yeah, worked for me with the given solution :)