in2code-de / femanagerextended

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

PHP7 Incompatible #1

Closed DanielNemanic closed 8 years ago

DanielNemanic commented 8 years ago

Getting this error:

1: PHP Warning: Declaration of In2code\Femanagerextended\Controller\EditController::updateAction(In2code\Femanagerextended\Domain\Model\User $user) should be compatible with In2code\Femanager\Controller\EditController::updateAction(In2code\Femanager\Domain\Model\User $user) in PATH\typo3conf\ext\femanagerextended\Classes\Controller\EditController.php line 27

Is use femanager 2.5.

einpraegsam commented 8 years ago

I tested it with femanager 2.5.0, TYPO3 7.6, PHP 7 and femanagerextended 1.1.0 - I can't see a problem with the updateAction() declaration. Maybe you're using a very old version of femanagerextended. Note: the version in TER is supported by another author and the version here on github is a different one.

DanielNemanic commented 8 years ago

Maybe you can find the error. I also used this git version, and received the error above.

Caches cleared. Folders deleted under typo3temp. Composer dump-autoload done

femanagerextended.zip

DanielNemanic commented 8 years ago

Clean installation of Typo3 7.6.9. PHP 7.0.6 No other Extensions installed just a std ts for fluid. Downloaded femanger 2.5 via TER. Using femanagerextended 1.1 via zip from this repository.

Getting this error: Could not analyse class: "In2code\Femanagerextended\Controller\NewController" maybe not loaded or no autoloader? 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) in PATH\T3Test\typo3conf\ext\femanagerextended\Classes\Controller\NewController.php line 21

DanielNemanic commented 8 years ago

For all with the same problem:

https://forge.typo3.org/issues/76290

j-lang commented 6 years ago

https://forge.typo3.org/issues/76290 does not exist, how can this be solved? The same issue comes by using https://github.com/einpraegsam/femanagerextended

carodb commented 6 years ago

Have you checked: https://github.com/einpraegsam/femanagerextended/issues/3 ?

j-lang commented 6 years ago

Checked this: Registered xclass in ext_localconf.php: <?php $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument'] = array( 'className' => 'vendor\\extension\\Xclass\\Extbase\\Mvc\\Controller\\Argument' );

This error-message is the result: #1289386765: Could not analyse class: "vendor\extension\Controller\NewController" maybe not loaded or no autoloader? PHP Warning: Declaration of vendor\extension\Controller\NewController::createAction($user) should be compatible with In2code\Femanager\Controller\NewController::createAction(In2code\Femanager\Domain\Model\User $user) in /html/typo3/typo3conf/ext/extension/Classes/Controller/NewController.php line 0

Is there some other code necessary to register xclass, I did not need it before?

But I don´t understand what is wrong with inheritance in php7 and typo3?

carodb commented 6 years ago

Can you post your custom NewController?

j-lang commented 6 years ago

I started today with import of Femanagerextended and added three parts:

  1. Xclass
  2. register Xlass in ext_localconf.php
  3. Added code to NewController

Xclass: Argument.php

<?php
namespace In2code\Femanagerextended\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;
    }
}

ext_localconf.php

<?php
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument'] = array(
    'className' => 'In2code\\Femanagerextended\\Xclass\\Extbase\\Mvc\\Controller\\Argument'
);

Xclass is registered:

TYPO3\CMS\Extbase\Mvc\Controller\Argument registriert eine XCLASS von In2code\Femanagerextended\Xclass\Extbase\Mvc\Controller\Argument

NewController.php

<?php
namespace In2code\Femanagerextended\Controller;

use In2code\Femanagerextended\Domain\Model\User;

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 \In2code\Femanagerextended\Xclass\Extbase\Mvc\Controller\Argument $user */
            $user = $this->arguments['user'];
            $user->setDataType(\In2code\Femanagerextended\Domain\Model\User::class);
        }
    }

    /**
     * action create
     *
     * @param User $user
     * @validate $user In2code\Femanager\Domain\Validator\ServersideValidator
     * @validate $user In2code\Femanager\Domain\Validator\PasswordValidator
     * @return void
     */
    public function createAction(User $user)
    {
        parent::createAction($user);
    }
}
carodb commented 6 years ago

Can you try replacing the user in your createAction?

public function createAction(\In2code\Femanager\Domain\Model\User $user) {...}

This works for me.

j-lang commented 6 years ago

Thank you, That works for me too.

webdev2027 commented 6 years ago

Hi, I've answered to this stack overflow post https://stackoverflow.com/questions/45563671/how-to-extend-femanager-controller-under-php-7/51130418#51130418 Now it works with PHP7 and TYPO3 8.7.

GhanshyamBhava commented 1 year ago

I started today with import of Femanagerextended and added three parts:

  1. Xclass
  2. register Xlass in ext_localconf.php
  3. Added code to NewController

Xclass: Argument.php

<?php
namespace In2code\Femanagerextended\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;
    }
}

ext_localconf.php

<?php
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\\CMS\\Extbase\\Mvc\\Controller\\Argument'] = array(
    'className' => 'In2code\\Femanagerextended\\Xclass\\Extbase\\Mvc\\Controller\\Argument'
);

Xclass is registered:

TYPO3\CMS\Extbase\Mvc\Controller\Argument registriert eine XCLASS von In2code\Femanagerextended\Xclass\Extbase\Mvc\Controller\Argument

NewController.php

<?php
namespace In2code\Femanagerextended\Controller;

use In2code\Femanagerextended\Domain\Model\User;

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 \In2code\Femanagerextended\Xclass\Extbase\Mvc\Controller\Argument $user */
            $user = $this->arguments['user'];
            $user->setDataType(\In2code\Femanagerextended\Domain\Model\User::class);
        }
    }

    /**
     * action create
     *
     * @param User $user
     * @validate $user In2code\Femanager\Domain\Validator\ServersideValidator
     * @validate $user In2code\Femanager\Domain\Validator\PasswordValidator
     * @return void
     */
    public function createAction(User $user)
    {
        parent::createAction($user);
    }
}

This not working for my TYPO3 10.4, femanagaer 6.3.4 and PHP 7.4