XF 2.2 Argument #2 ($structure)

DreamNetworks

Active member
Hi All,

Can someone explain me why I get this error?

Code:
ErrorException: [E_WARNING] DN\XFRMOptions\Listener::resourceItemEntityStructure(): Argument #2 ($structure) must be passed by reference, value given in src/XF/Entity/Option.php at line 208
XF::handlePhpError() in src/XF/Entity/Option.php at line 208
XF\Entity\Option->verifyOptionValue() in src/XF/Mvc/Entity/Entity.php at line 791
XF\Mvc\Entity\Entity->_verifyValueCustom() in src/XF/Mvc/Entity/Entity.php at line 636
XF\Mvc\Entity\Entity->set() in src/XF/Mvc/Entity/Entity.php at line 570
XF\Mvc\Entity\Entity->__set() in src/XF/Repository/Option.php at line 113
XF\Repository\Option->updateOptions() in src/XF/Admin/Controller/Option.php at line 84
XF\Admin\Controller\Option->actionUpdate() in src/XF/Mvc/Dispatcher.php at line 352
XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 259
XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 115
XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 57
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2351
XF\App->run() in src/XF.php at line 517
XF::runApp() in admin.php at line 13

Greetz,
Alex
 
The second argument into the DN\XFRMOptions\Listener::resourceItemEntityStructure() function you created needs to be passed by reference. In other words the variable name $structure should be prefixed with an & character.
 
PHP:
class Listener
{
    public static function resourceItemEntityStructure(
        \XF\Mvc\Entity\Manager $em,
        \XF\Mvc\Entity\Structure &$structure
    ): void {
        if (\XF::options()->DisableTaglineValidation) {
            unset($structure->columns['tag_line']['required']);
        }
    }
}

Maybe I'm a noob, but this is my code, that should be fine already right?
 
At any point did you forget to add the & then added it later? My only feasible explanation is some sort of sticky opcache that is essentially still serving the wrong code even though it’s now correct on the file system.

Sometimes restarting the web server and/or php-fpm can reset the opcache so that’s worth a try.
 
Hi @Chris D ,

This is my Listener.php

Code:
<?php

namespace DN\XFRMOptions;

use \XF\Mvc\Entity\Structure;

class Listener
{
    public static function resourceItemEntityStructure(\XF\Mvc\Entity\Manager $em, \XF\Mvc\Entity\Structure &$structure): void
{
       if (\XF::options()->disabletaglinevalidation) {
            unset($structure->columns['tag_line']['required']);
        }
    }
}

I'm using PHP 8.1, I have tried what you have said. But no cache is active now. And still get the same error:

Code:
ErrorException: [E_WARNING] DN\XFRMOptions\Listener::resourceItemEntityStructure(): Argument #2 ($structure) must be passed by reference, value given in src/XF/Entity/Option.php at line 208
XF::handlePhpError() in src/XF/Entity/Option.php at line 208
XF\Entity\Option->verifyOptionValue() in src/XF/Mvc/Entity/Entity.php at line 791
XF\Mvc\Entity\Entity->_verifyValueCustom() in src/XF/Mvc/Entity/Entity.php at line 636
XF\Mvc\Entity\Entity->set() in src/XF/Mvc/Entity/Entity.php at line 570
XF\Mvc\Entity\Entity->__set() in src/XF/Repository/Option.php at line 113
XF\Repository\Option->updateOptions() in src/XF/Admin/Controller/Option.php at line 84
XF\Admin\Controller\Option->actionUpdate() in src/XF/Mvc/Dispatcher.php at line 352
XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 259
XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 115
XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 57
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2351
XF\App->run() in src/XF.php at line 517
XF::runApp() in admin.php at line 13
 
The code is correct. The error is incorrect.

Opcache is enabled by default. So unless you’ve explicitly disabled it, it may be running.

Disabling it and restarting web/PHP may change things.

If not, I can’t really help you any further. The code is correct and PHP is somehow interpreting the code wrong which clearly shouldn’t be possible.
 
Really strange, i have set opcache off, restarted all php versions 7.4 and 8.0 and 8.1 restarted the nginx reverse proxy and apache webserver. Changed to php 7.4 and back but on both I get the same error. This is the error on 7.4


Code:
ErrorException: [E_WARNING] Parameter 2 to DN\XFRMOptions\Listener::resourceItemEntityStructure() expected to be a reference, value given in src/XF/Entity/Option.php at line 208
XF::handlePhpError() in src/XF/Entity/Option.php at line 208
XF\Entity\Option->verifyOptionValue() in src/XF/Mvc/Entity/Entity.php at line 791
XF\Mvc\Entity\Entity->_verifyValueCustom() in src/XF/Mvc/Entity/Entity.php at line 636
XF\Mvc\Entity\Entity->set() in src/XF/Mvc/Entity/Entity.php at line 570
XF\Mvc\Entity\Entity->__set() in src/XF/Repository/Option.php at line 113
XF\Repository\Option->updateOptions() in src/XF/Admin/Controller/Option.php at line 84
XF\Admin\Controller\Option->actionUpdate() in src/XF/Mvc/Dispatcher.php at line 352
XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 259
XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 115
XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 57
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2351
XF\App->run() in src/XF.php at line 517
XF::runApp() in admin.php at line 13

I'm really out of ideas now xD
 
Damn, that was stupid from me... I use the validation callback in the option... while there isn't any validation required.

Thanks for the help guys!
 
Back
Top Bottom