I think by declaring $_POST
as an input parameter of the function, you've redefined it in the local scope and lost the global data because you try to re-assing it ($_POST
is a superglobal). For what you've done, some good existing Q&A material are:
Even those are older, the information they give about the topic are still valid in PHP because those superglobals haven't changed meanings over the years.
However in all current stable PHP Versions (that is PHP 5.4 and up) your code produces a fatal error (Online Demo in 80+ PHP Versions):
Fatal error: Cannot re-assign auto-global variable _POST
This might explain that you don't get any output. See Nothing is seen. The page is empty and white. (also known as White Page or Screen Of Death) in the Reference - What does this error mean in PHP?. You might not see any error message because you don't display it or you don't look into the log-file, see How to get useful error messages in PHP?.
So what can you do? Next to understanding the basics of PHP error handling - and I suggest you to enable error logging and locate the error log to get fluent with it - you need to change the code as outlined in the two reference questions linked above.
Either get rid of $_POST
as an input to the function, or change the name to something else like $postData
.
function call(array $postData)
{
$xml = $postData['xml'];
$doc = simplexml_load_string($xml);
}
The just call the function with:
call($_POST);
Or if you only pass some little parameters with that array, write them out:
function call($xmlString)
{
$doc = simplexml_load_string($xmlString);
}
Usage:
call($_POST['xml']);
This will allow you to use different form names with the same code. Very useful because you don't tie things too hard together but leave some wiggling room.