Attempt to assign property “username” on null

Recently we upgraded PHP at 8.1 at our company and one crucial file has stopped working.

function checkVATGR($username,$password,$AFMcalledby="",$AFMcalledfor)
{
    $client = new SoapClient( "https://www1.gsis.gr/webtax2/wsgsis/RgWsPublic/RgWsPublicPort?WSDL",array('trace' => true) );
    //$version = $client->rgWsPublicVersionInfo();
    $authHeader = new stdClass();
    $authHeader->UsernameToken->Username = "$username";
    $authHeader->UsernameToken->Password = "$password";
    $Headers[] = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'Security', $authHeader,TRUE);
    $client->__setSoapHeaders($Headers);
    $result = $client->rgWsPublicAfmMethod(
        array(
            'afmCalledBy'=>"$AFMcalledby",
            'afmCalledFor'=>"$AFMcalledfor",
            )
        );
    return $result;
}    

The full code can be found at github . I do realize, based also on this question, that it has to do with SOAP and that is backwards incompatible with PHP 7.

How could the code be modified to continue working? I have no idea how SOAP works and it would take me a while to learn it whereas we need the company application to continue working.