Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It doesn’t have to do with SOAP. $authHeader = new stdClass(); creates an empty stdClass instance, that has no properties of its own. So you can’t assign anything to $authHeader->UsernameToken->Username – because $authHeader->UsernameToken does not exist to begin with.

Try and do $authHeader->UsernameToken = new stdClass(); first (directly after the $authHeader = new stdClass(); line) – that should fix it.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading