TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

March 28, 2024, 09:13:06 AM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,104
  • Total Topics: 21,212
  • Online today: 212
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 120
  • Total: 120

Too few arguments to function TinyPortal\Integrate::hookRedirect()

Started by Arminus, October 07, 2022, 11:40:52 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Arminus

Link to my forum: www dot roberge dot de
SMF version: 2.1.2
TP version: 2.2.2
Default Forum Language: German
Theme name and version: Curve 2
Browser Name and Version: Firefox
Mods installed:
Related Error messages:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function TinyPortal\Integrate::hookRedirect(), 2 passed in /var/www/roberge.de2/html/Sources/Subs.php on line 5772 and exactly 3 expected in /var/www/roberge.de2/html/TinyPortal/Integrate.php:812 Stack trace: #0 /var/www/roberge.de2/html/Sources/Subs.php(5772): TinyPortal\Integrate::hookRedirect('?action=modul;s...', false) #1 /var/www/roberge.de2/html/Sources/Alps/includes/function_module.php(344): call_integration_hook('integrate_redir...', Array) #2 /var/www/roberge.de2/html/Sources/Alps/includes/search-includes/stichworturl.php(37): redirectboard('?action=modul;s...') #3 /var/www/roberge.de2/html/Sources/Alps/includes/function_search.php(53): stichwortUrl() #4 /var/www/roberge.de2/html/Sources/Alps/includes/function_search.php(22): ModulIndex() #5 /var/www/roberge.de2/html/suche.php(428): search_main() #6 {main} thrown in /var/www/roberge.de2/html/TinyPortal/Integrate.php on line 812

Although for the repro, this is called top-level from custom code, the issue is between Sources/Subs.php(5772) and TinyPortal/Integrate.php:812 - patching the latter to remove the 3rd argument (which isn't used by that function anyway?) "solves" the issue.

Is there a bug in TinyPortal/Integrate.php:812 ?

@rjen

Never seen this error before.

can you tell us what exacty you are doing to trigger this error?
How can we reproduce it?

Any particular function or action?
Running Latest TP on SMF2.1 at: www.fjr-club.nl

Arminus

I inherited the forum maintenance from someone else, so I don't have a clear picture yet. (and this problem never happened until we installed TinyPortal, so there is some incompatibility there...)

Anyway:

this is TinyPortal/Integrate.php with 3 params, 2 of which aren't even used in that function:

public static function hookRedirect(&$setLocation, &$refresh, &$permanent)

According to the stack trace, it gets called from Sources/Subs.php on line 5772 with $results[$function] = call_user_func_array($call, $parameters);
and only 2 prams?!
which in turn gets called by this line in some custom code which I haven't written:
call_integration_hook('integrate_redirect', array(&$setLocation, &$refresh));

I'm afraid my PHP understanding is rather limited, I'm more a Java/JS/Python guy, so I really don't understand how these hooks work. I just interpreted the different function signatures as not matching and thus removed the apparently superfluous/unused 3rd param in hookRedirect to make it work as a short-term hack for the site.

I can only guess that this call_integration_hook needs a 3rd parameter?! Whatever &$permanent may be in hookRedirect.

And by the way: I accidentally misspelled my nickname for this forum and can't seem to change it, letter swap, should be Arminus ;)

Thanks for helping!

@rjen

Sorry, but I have been using TinyPortal for years and I never had this issue, nor has it been reported before.

So it is either something very specific or related to your forum configuration.
Where is this custom code coming from? That may very well be the explantion that you are this first one having this issue...

Unless the issue is something I can reproduce I cannot troubleshoot it.

So I have to ask again: when does this error occur exactly?
Is it directly after installing TinyPortal? Or is it when a specific function is used?

As for the coding specifics, I will leave that to tino, who will probably reply some time later.

What I do notice is that your error refers to position 812 and the function hookRedirect is on line 821?
Running Latest TP on SMF2.1 at: www.fjr-club.nl

@rjen

By the way: I have changed your user name to Arminus.
Password is unchanged...
Running Latest TP on SMF2.1 at: www.fjr-club.nl

Arminus

Quote from: @rjen on October 07, 2022, 01:52:47 PM
Where is this custom code coming from? That may very well be the explantion that you are this first one having this issue...
From someone who wrote this code years ago.

Quote from: @rjen on October 07, 2022, 01:52:47 PMUnless the issue is something I can reproduce I cannot troubleshoot it.
I understand that...

Quote from: @rjen on October 07, 2022, 01:52:47 PM
So I have to ask again: when does this error occur exactly?
Is it directly after installing TinyPortal? Or is it when a specific function is used?
The error happens when this custom code is called from a form to search in table which is unrelated to SMF or TinyPortal but integrated via a menu into the site.

Quote from: @rjen on October 07, 2022, 01:52:47 PM
As for the coding specifics, I will leave that to tino, who will probably reply some time later.
From my POV, that custom code would need to call the integrate_redirect hook not with 2 but with 3 parameters.

Without TinyPortal installed, this call with 2 params apparently never caused a problem, with TinyPortal installed, it seems to call a different hook which now requires 3 params, but I don't know what that 3rd param (&$permanent) should be because it isn't actually used in TinyPortal's hookRedirect. I suppose I could just add a dummy param in the custom code, but that's just the same kind of blind hack I did on the opposite end so far. So it would really be interesting to know what the purpose of this param is so that I can possibly fix that in other places inside the custom code.

Quote from: @rjen on October 07, 2022, 01:52:47 PM
What I do notice is that your error refers to position 812 and the function hookRedirect is on line 821?
In my copy of TinyPortal/Integrate.php that function is indeed on line 812.

And thanks for changing my nickname!

tino

We use three parameters as the core code in SMF passes three in.

https://github.com/SimpleMachines/SMF/blob/090a5b403f8f9846e3ce96aab40d931bcdddf225/Sources/Subs.php#L4081

call_user_func_array is a php function which takes the first call as the function name and the second is an array of parameters, in this instance from SMF it's array(&$setLocation, &$refresh, &$permanent)

I think that code you have is from SMF 1.1 as that was formally two parameters, If we changed it to two it would break the SMF call so unfortunately the code at fault is your custom code. We don't use permanent as you've notice but other modifications might so we accept it passed in by reference and don't manipulate it at all. 

Arminus

Quote from: tino on October 08, 2022, 04:06:11 PM
I think that code you have is from SMF 1.1 as that was formally two parameters,
Yes that code is some years old, so that is the explanation then. Thanks for pointing that out, I hate to patch things by just hacking some symptom.

Quote from: tino on October 08, 2022, 04:06:11 PM
If we changed it to two it would break the SMF call so unfortunately the code at fault is your custom code. We don't use permanent as you've notice but other modifications might so we accept it passed in by reference and don't manipulate it at all.
I wouldn't expect it to change on your side, I'm passing false now as 3rd param so all is fine.

tino

Quote from: Arminus on October 10, 2022, 04:32:59 PM
I wouldn't expect it to change on your side, I'm passing false now as 3rd param so all is fine.

I would copy SMF personally, and have the following.

(&$setLocation, &$refresh, &$permanent)

As other applications which extend that hook may manipulate that value and having a false will throw an error.