Jump to content

$HTTP_RAW_POST_DATA


ksmatthews

Recommended Posts

Hi There,

 

I am trying to develop some basic web services using NuSOAP and I came across this line of code in a SOAP client script ...

 

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';

$server->service($HTTP_RAW_POST_DATA);

 

What does it do ?

 

Is there a forum dedicated to php web services development ?

 

regards,

 

Steven M

Link to comment
Share on other sites

<?php
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>

 

This code is disallowing $HTTP_RAW_POST_DATA to contain the value null.  There is a subtle difference between null and '' which can be differentiated using the === equality operator.  $HTTP_RAW_POST_DATA contains the raw contents of an HTTP POST Request.  Usually something like: foo=1&bar=2&baz=3.

 

Best,

 

Patrick

Link to comment
Share on other sites

$HTTP_RAW_POST_DATA is not always set. A different case entirely from having a null value.

 

Hmm... you sure?

 

<?php
$foo = null;

if($foo === $bar){
echo 'Patrick - 1 Jenk - 0 ';
}
?>

 

I think that PHP initializes all variables to null unless explicitly assigned a (non null) value.

 

Patrick

Link to comment
Share on other sites

$HTTP_RAW_POST_DATA is not always set. A different case entirely from having a null value.

 

Hmm... you sure?

 

<?php
$foo = null;

if($foo === $bar){
echo 'Patrick - 1 Jenk - 0 ';
}
?>

 

I think that PHP initializes all variables to null unless explicitly assigned a (non null) value.

 

Patrick

Now turn on all errors and watch that "E_NOTICE undefined variable $bar" error message fly. Jenk 2 - Patrick 0.
Link to comment
Share on other sites

E_NOTICE's:

 

[...] Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.

 

Perhaps you could explain to me, sans E_NOTICE, how a variable which is unset is "a different case entirely from having a null value".  Afterall null was invented in order to designate absence of value. 

 

<?php
$foo = null;

if($foo === $bar){
echo '$foo is equal to an undefined $bar'."\n";
}

if(!isset($foo)){
echo '$foo IS set (to null)'."\n";
}
?>

 

Patrick - 1 Jenk - null :-p

 

...

Link to comment
Share on other sites

Php simply assigns null values to used (in expressions), but uninitialized variables. Initializing variables in php is just good practice (and I take every single notice the engine spits out as an error myself personally), not much more. If you ignore the notices, there is indeed no noticable difference between variables with null values and unset variables. The only exception to this I can think of is when using arrays and array_key_exists(). But that is, I believe, the only case when there is a behavioral difference between the two.

 

On topic, you can set 'always_populate_raw_post_data' to 1 in php.ini of avoid $HTTP_RAW_POST_DATA altogether and use the php://input wrapper, which is actually the preferred method according to the manual.

 

[you]darn sms punks[/you]

Link to comment
Share on other sites

E_NOTICE's:

 

[...] Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.

 

Perhaps you could explain to me, sans E_NOTICE, how a variable which is unset is "a different case entirely from having a null value".  Afterall null was invented in order to designate absence of value. 

 

<?php
$foo = null;

if($foo === $bar){ // no E_NOTICE for $foo, only for $bar - Jenk 3 - Patrick 0.
echo '$foo is equal to an undefined $bar'."\n";
}

if(!isset($foo)){
echo '$foo IS set (to null)'."\n";
}
?>

 

Patrick - 1 Jenk - null :-p

 

...

If a variable has been unset with unset()' date=' it will no longer be set. [b']isset() will return FALSE if testing a variable that has been set to NULL.[/b] Also note that a NULL byte ("\0") is not equivalent to the PHP NULL constant.
Jenk 4 - Patrick 0.
Link to comment
Share on other sites

As a note, remember that in the php engine variables and values exist separately. So null indicates the absence of value, but not the absence of the variable itself. But as I said in my previous post, this obscure difference rarely manifests itself beyond 'undefined' notices.

 

[shameless_childishness]

John 1000 - Patrick and Jenk 0. :-* Where do I collect my teddy bear?  :D

[/shameless_childishness]

Link to comment
Share on other sites

I knew that, but you have to look at it like this:

 

The name 'John' is the value, an object, we are the variables. We both have 1000 points, because we reference the same value. But then, in a twist of faith, you are reassigned the value associated with object 'Jenk', and now your points property says you got 0. So basically the hash table just got shuffled a little and you drew the shortest straw.. :P

 

So I win. Hand over Teddy.  ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.