Erweiterung Ich arbeite an einer Möglichkeit, Kontonummern zu überprüfen. Die $ account_number wird zur Verifizierung von einer anderen Funktion übergeben. Ich habe ein Scoping-Problem für meine Variablen festgestellt, das von Funktion zu Klasse überging. Ich habe es funktioniert, aber ich habe $ GLOBALS verwendet, um das Problem zu umgehen. Ich habe das Gefühl, dass es einen besseren Weg geben muss. Hier ist, was ich habe:PHP-Variable Umfang Problem in der Klasse SOAP
$acct;
$subAcct;
$chart;
$object;
$subObject;
$project;
function verifyACCT($account_number){
//Strip all but numbers and letters, truncate to first seven digits, and convert to uppercase
$account_number = strtoupper(preg_replace("/[^a-z0-9]/i", "", $account_number));
$GLOBALS['$acct'] = substr($account_number, 0, 7);
$GLOBALS['$subAcct'] = substr($account_number, 8);
$GLOBALS['$chart'] = "XX";
$GLOBALS['$object'] = "0000";
$GLOBALS['$subObject'] = null;
$GLOBALS['$project'] = null;
class ACCTSoapClient extends SoapClient {
public function __doRequest($request, $location, $action, $version, $one_way=0) {
$request = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<isValidAccountString xmlns="http://URL/">
<chartOfAccountsCode xmlns="">'.$GLOBALS['$chart'].'</chartOfAccountsCode>
<accountNumber xmlns="">'.$GLOBALS['$acct'].'</accountNumber>
<subAccountNumber xmlns="">'.$GLOBALS['$subAcct'].'</subAccountNumber>
<objectCode xmlns="">'.$GLOBALS['$object'].'</objectCode>
<subObjectCode xmlns="">'.$GLOBALS['$subObject'].'</subObjectCode>
<projectCode xmlns="">'.$GLOBALS['$project'].'</projectCode>
</isValidAccountString>
</soap:Body>
</soap:Envelope>';
return parent::__doRequest($request, $location, $action, $version, $one_way);
}
}
$client = new ACCTSoapClient("https://URL?wsdl", array("connection_timeout"=>5, 'exceptions' => 0));
try {
$result = $client->isValidAccountString(null);
return ($result->return); //boolean (1 for valid, null for invalid)
} catch(SoapFault $e) {
echo 1;
} catch(Exception $e) {
echo 1;
}
}