CRM query from Outlook fails

useing Suite/Sugar-Version:SuiteCRM 7.14.3, Sugar Version 6.5.25 (Build 344)
searching for entrys from the addin leads to an error
Error: Unknown error in SOAP call: service died unexpectedly

on serverside the logged line is:

[Fri Mar 22 10:54:05.585930 2024] [proxy_fcgi:error] [pid 671338:tid 139976004040384] [client 83.150.2.35:62659] AH01071: Got error 'PHP message: PHP Warning:  Array to string conversion in /var/www/crm/include/nusoap/nusoap.php on line 8930; PHP message: PHP Fatal error:  Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, non-static method SugarWebServiceImplv2_1::get_entry_list() cannot be called statically in /var/www/crm/include/nusoap/nusoap.php:5437\nStack trace:\n#0 /var/www/crm/include/nusoap/nusoap.php(5054): nusoap_server->invoke_method()\n#1 /var/www/crm/service/core/NusoapSoap.php(94): nusoap_server->service()\n#2 /var/www/crm/service/core/webservice.php(70): NusoapSoap->serve()\n#3 /var/www/crm/service/v2_1/soap.php(56): require_once('...')\n#4 {main}\n  thrown in /var/www/crm/include/nusoap/nusoap.php on line 5437'

PHP 8 introduced breaking change to call_user_func_array()
• call_user_func_array() 1 array keys will now be interpreted as parameter names, instead of being silently ignored.

/suitecrm/service/core/REST/SugarRestJSON.php

public function serve(){
$GLOBALS['log']->info('Begin: SugarRestJSON->serve');
$json_data = !empty($_REQUEST['rest_data'])? $GLOBALS['RAW_REQUEST']['rest_data']: '';
if(empty($_REQUEST['method']) || !method_exists($this->implementation, $_REQUEST['method'])){
$er = new SoapError();
$er->set_error('invalid_call');
$this->fault($er);
}else{
$method = $_REQUEST['method'];
$json = getJSONObj();
$data = $json->decode($json_data);
if(!is_array($data))$data = array($data);
if (!isset($data['application_name']) && isset($data['application'])){
$data['application_name'] = $data['application'];
}
$res = call_user_func_array(array( $this->implementation, $method),$data);
$GLOBALS['log']->info('End: SugarRestJSON->serve');
return $res;
} // else
} // fn

Change this line:

$res = call_user_func_array(array( $this->implementation, $method),$data);

To this:

$res = $this->implementation->{$method}(...array_values($data));

This needs a PR as I don’t see one on github for this bug…

I’d be happy to do a PR, I think it needs some expert discussion though. I had some help from ChatGPT to fix this for me and it’s a little advanced for my PHP skills. It totally fixes my problem, but not 100% it’s the right fix.

There was also some discussion that this change is not necessary and that a change to the actual call is necessary…Rest API v4_1 is not working with php 8.1 and 8.2 - #15 by blqt

My use case was Mautic integration with SutieCRM and this code change avoided the PHP error and solved the problem for me, other users have reported back it solves it for them.

I’d love your input! If you think for sure this needs to be changed in the core, I’ll do the PR.

It should help to look at how other PHP web applications deal with this issue.

This is how Drupal does, they changed their calls to keep the parameter variables matching exactly, as expected by PHP 8: https://www.drupal.org/project/rules/issues/3210303#comment-14070697

Looks like your solution bypasses the new named parameters way, and just calls the function while expecting the parameter order to match, as is done in PHP 7 and below.

As long as it works!

At the bare minimum, there should be a warning in the release notes stating that API callers who use mismatched variable names must rename these variables exactly the same as in the called function, when running on PHP 8.0 and newer.

1 Like