return by itself will not send anything to the client. If you echo the result of sendResponse() , then yes, the client will receive XML:
echo sendResponse($type,$cause);
Notice that I removed $ from the sendResponse call - PHP will consider it a variable if you use $ .
It is recommended that you add a header to tell the client that the XML is being sent, and the encoding, but this is not essential for the XML transport:
header("Content-type: text/xml; charset=utf-8");
You can use the concatenation character . after declaring the XML header:
public function sendResponse($type,$cause) { $response = '<?xml version="1.0" encoding="utf-8"?>'; $response .= '<response><status>'.$type.'</status>'; $response = $response.'<remarks>'.$cause.'</remarks></response>'; return $response; } .... .... header("Content-type: text/xml; charset=utf-8"); echo sendResponse($type,$cause);
source share