Quiz Number 8

SWE 432, Fall 2009
October 29


  1. Is PHP client-side or server-side technology?
    Answer: Server side.
  2. Explain the notion of coercion. Give an example in PHP.
    Answer: A coercion is an implicit forced conversion of one data type to another. In the PHP example below, the string "5" is coerced to be an integer.
       if ("5" < 7) return true;       // "5" coerced to integer; returns true.
    
  3. What are the final (key,value) pairs in the following PHP array?
       $arr[2] = "Alice";
       $arr["October"] = 31;
       $arr["November"] = 30;
       unset($arr["October"]);
    

    Answer: There are two key,value pairs:
       2 => "Alice",
       "November" => 30
    
    See the example as a PHP script.

  4. Consider the following HTML skeleton input form:
    < form  action = "http://www.somewhere.com/fun.php" method = "post" >
         < input  type = "text" name = "stripes" size = "3" >
         < input  type = "submit" value = "Send Stripes" >
    < /form  >
    
    
    Explain how the PHP script fun.php would access the text in the textbox named stripes after the client pressed the Send Stripes button.
    Answer: The PHP script would access the _POST array (or the _REQUEST array) as in:
       $stripes = $_REQUEST["stripes"];
    
    (Note: This used to say _RESPONSE. The right variable, of course, is _REQUEST.)