Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think by declaring <code>$_POST</code> 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 (<a href="http://php.net/language.variables.superglobals" rel="nofollow noreferrer"><code>$_POST</code> is a superglobal</a>). For what you've done, some good existing Q&amp;A material are:</p> <ul> <li><a href="https://stackoverflow.com/q/1354691/367456">PHP: $_GET and $_POST in functions? (Aug 2009)</a></li> <li><a href="https://stackoverflow.com/q/1660912/367456">passing POST array to php function (Nov 2009)</a></li> </ul> <p>Even those are older, the information they give about the topic are still valid in PHP because those <em>superglobals</em> haven't changed meanings over the years.</p> <p>However in all <em>current</em> stable PHP Versions (that is PHP 5.4 and up) your code produces a fatal error (<a href="http://3v4l.org/aiYXR" rel="nofollow noreferrer">Online Demo in 80+ PHP Versions</a>):</p> <blockquote> <p>Fatal error: Cannot re-assign auto-global variable _POST</p> </blockquote> <p>This might explain that you don't get any output. See <a href="https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/12772851#12772851"><em>Nothing is seen. The page is empty and white. (also known as White Page or Screen Of Death)</em></a> in the <a href="https://stackoverflow.com/q/12769982/367456">Reference - What does this error mean in PHP?</a>. You might not see any error message because you don't display it or you don't look into the log-file, see <a href="https://stackoverflow.com/q/845021/367456">How to get useful error messages in PHP?</a>.</p> <p>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.</p> <p>Either get rid of <code>$_POST</code> as an input to the function, or change the name to something else like <code>$postData</code>.</p> <pre><code>function call(array $postData) { $xml = $postData['xml']; $doc = simplexml_load_string($xml); } </code></pre> <p>The just call the function with:</p> <pre><code>call($_POST); </code></pre> <p>Or if you only pass some little parameters with that array, write them out:</p> <pre><code>function call($xmlString) { $doc = simplexml_load_string($xmlString); } </code></pre> <p>Usage:</p> <pre><code>call($_POST['xml']); </code></pre> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload