A PHP variable has a value and a type. In most practice cases we consider only about the value of the variable. But there may be times we have to consider the type of the variable as well.
For an example value NULL (or 0 or whatever of following you likeĀ to call it) can be assigned to a variable with different types like this.
$x = NULL;
NULL data type. Yea it is the real NULL.
$x = 0;
Integer data type.
$x = 0.0;
Float data type.
$x = FALSE;
Boolean data type.
$x = “”;
String data type.
You can check the operator ‘===’ (triple equal operator) to check equality of both their values and types simultaneously.
You can have a good idea about this by looking at the following piece of code.
// lets check the equality of NULL and 0 with// double equal operatorif(NULL == 0){echo"NULL == 0 is TRUE</br>";
}else{echo"NULL == 0 is FALSE</br>";
}// now lets check the equality of NULL and 0 with// triple equal operatorif(NULL === 0){echo"NULL === 0 is TRUE</br>";
}else{echo"NULL === 0 is FALSE</br>";
}
This will eventually print the following result.
NULL == 0 is TRUE
NULL === 0 is FALSE
PHP variables including class variables get the NULL value and NULL type by default. So if no one assign them a value it remains NULL.
So in a case you have to check for unused variables (or for “NULL”-ness of a variable) you should always use the triple equal operator (===) with NULL token. Otherwise you may mistakenly treat not NULL things like ‘0′ or empty string (”") as null that may have been valid data for your application.
Details - More information about the details, mostly supposed to be read by the client application.
Role - Indicates which SOAP header caused the fault. This is very rarely used in faults send from the business logic.
Sending SOAP Faults
In WSF/PHP you have the WSFault class to deal with SOAP faults. You can send a fault in your service logic by throwing an instance of WSFault class like this.
/**
* divide mathematical operation
* @param int $dividend
* (maps to xs:int)
* @param int $divisor
* (maps to xs:int)
* @return float $result
* (maps to xs:float)
*/function divide($dividend, $divisor){// dividing from 0 is invalid, we wil *throw* fault in such cases..if($divisor == 0){
throw new WSFault("Sender", "dividing from 0 is invalid");
}$result = (float)$dividend/$divisor;
returnarray("result" => $result);
}
Here I have throw an WSFault whenever I encounter my divisor is zero. And the WSF/PHP will take care of building the SOAP message according to the given version (default is to SOAP 1.2) and send back to the client.
Handling SOAP Faults
Similar to the service, client API also treat the SOAP fault as an instance of WSFault. So whenever you do a web service request, put inside try, catch block so you can catch exception in case of fault is received. Here is an example of handling fault while calling the divide operation in the above example.
// creating the client, we retrieved the wsdl from service url + ?wsdl$client = new WSClient(array("wsdl" => "http://localhost/myblog/fault_service.php?wsdl"));
$proxy = $client->getProxy();
try {// calling the operation$response = $proxy->divide(array("dividend" => 5, "divisor" => 0));
// printing the resultecho$response["result"];
} catch(Exception $e){// if the instance is WSFault we print the code and the reasonif($e instanceof WSFault){printf("Soap Fault Reason: %s\n", $e->Reason);
printf("Soap Fault Code: %s \n", $e->Code);
}else{printf("Message = %s\n",$e->getMessage());
}}
As you can see WSF/PHP covers the complexity of building and handling SOAP faults, Rather it gives you an API with the use of PHP Exception Construct that you already familiar with.