ksmatthews Posted May 19, 2007 Share Posted May 19, 2007 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 Quote Link to comment Share on other sites More sharing options...
utexas_pjm Posted May 22, 2007 Share Posted May 22, 2007 <?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 Quote Link to comment Share on other sites More sharing options...
Jenk Posted May 22, 2007 Share Posted May 22, 2007 $HTTP_RAW_POST_DATA is not always set. A different case entirely from having a null value. Also note it is a deprecated variable, look at using the $_SERVER global array instead. Quote Link to comment Share on other sites More sharing options...
utexas_pjm Posted May 22, 2007 Share Posted May 22, 2007 $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 Quote Link to comment Share on other sites More sharing options...
Jenk Posted May 22, 2007 Share Posted May 22, 2007 $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. Quote Link to comment Share on other sites More sharing options...
utexas_pjm Posted May 22, 2007 Share Posted May 22, 2007 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 ... Quote Link to comment Share on other sites More sharing options...
448191 Posted May 22, 2007 Share Posted May 22, 2007 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] Quote Link to comment Share on other sites More sharing options...
Jenk Posted May 23, 2007 Share Posted May 23, 2007 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. Quote Link to comment Share on other sites More sharing options...
448191 Posted May 23, 2007 Share Posted May 23, 2007 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? [/shameless_childishness] Quote Link to comment Share on other sites More sharing options...
Jenk Posted May 23, 2007 Share Posted May 23, 2007 My name is John, too. I win Quote Link to comment Share on other sites More sharing options...
448191 Posted May 23, 2007 Share Posted May 23, 2007 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.. So I win. Hand over Teddy. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.