XF 2.2 Pub controller class calls init() for some reason when using fastUpdate()

asprin

Active member
In my server logs, I'm seeing this message as part of an addon that I'm working on

PHP:
Error: Call to undefined function Asprin\FB\Pub\Controller\int() src/addons/Asprin/FB/Pub/Controller/Foo.php:293

The stack trace is as follows:
PHP:
#0 src/addons/Asprin/FB/Pub/Controller/Foo.php(201): Asprin\FB\Pub\Controller\Foo->swapThem(391, 396, 7)
#1 src/XF/Mvc/Dispatcher.php(352): Asprin\FB\Pub\Controller\Foo->actionCheckSwap(Object(XF\Mvc\ParameterBag))
#2 src/XF/Mvc/Dispatcher.php(263): XF\Mvc\Dispatcher->dispatchClass('Asprin\\FB:Foo...', 'CheckSwap', Object(XF\Mvc\RouteMatch), Object(Asprin\FB\Pub\Controller\Foo), NULL)
#3 src/XF/Mvc/Dispatcher.php(115): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(Asprin\FB\Pub\Controller\Foo), NULL)
#4 src/XF/Mvc/Dispatcher.php(57): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#5 src/XF/App.php(2351): XF\Mvc\Dispatcher->run()
#6 src/XF.php(517): XF\App->run()
#7 index.php(20): XF::runApp('XF\\Pub\\App')
#8 {main}

The class is as follows (the lines specified in stack trace are mentioned below)
PHP:
<?php

namespace Asprin\FB\Pub\Controller;

use XF\Mvc\ParameterBag;
use XF\Pub\Controller\AbstractController;

use Asprin\FB\Utils as Utils;


class Foo extends AbstractController
{
    public function actionCheckSwap(ParameterBag $params)
    {
        /*
        . some
        . lines
        . of
        . code
        . here
        */
       
        $this->swapThem($what, $with_what, $pos); // line 201
    }
   
    public function swapThem($what, $with_what, $pos)
    {
        /*
        . some
        . lines
        . of
        . code
        . here
        */
       
        $foo = $bar->User->Foo; // line 292
        $foo->fastUpdate('counter', ((int)$bar->actioned + 1)); // line 293
    }
   
}

Going by the culprit line 293, is this happening because $foo is turning out to null/empty? The problem is that it's not happening always, it's random so I've been having a hard time reproducing the error.

But even if it's a case of null/empty, the error message should say something along the lines of call to undefined function on null or something?
 
Cannot believe I misread that. It was not init() but int(). So typecasting a value to int is causing the issue.

What I still don't understand though is why it's causing an issue because (int) <value> is pretty standard PHP code, isn't it?

PHP:
$foo->fastUpdate('counter', ((int)$bar->actioned + 1));
 
Back
Top Bottom