You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Rasmus Lerdorf <ra...@lerdorf.on.ca> on 1997/08/28 05:42:45 UTC

mod_javascript

We talked a bit about a server-side Javascript implementation for Apache.
I am still not going to go too much out of my way to make mod_php look
like Javascript, but as I mentioned the mod_php parser is currently being
rewritten.  The following script now works perfectly:

<?

/* pretty nifty object oriented code! */

class user {
  var $first_name;
  var $family_name;
  var $address;
  var $phone_num;
  cfunction display()
  {
    echo "User information\n";
    echo "----------------\n\n";
    echo "First name:\t  ".$this->first_name."\n";
    echo "Family name:\t  ".$this->family_name."\n";
    echo "Address:\t  ".$this->address."\n";
    echo "Phone:\t\t  ".$this->phone_num."\n";
    echo "\n\n";
  }
  cfunction initialize($first_name,$family_name,$address,$phone_num)
  {
    $this->first_name = $first_name;
    $this->family_name = $family_name;
    $this->address = $address;
    $this->phone_num = $phone_num;
  }
};


function test $u (  /* one can pass classes as arguments */
  $u->display();
  $t = $u;
  $t->address = "New address...";
  return $t;  /* and also return them as return values */
);

$user1 = new $user;  /* initialize a new object of class $user.  the 'new'
                        operator is silently ignored */
$user2 = new $user;  /* ditto */

$user1->initialize("Zeev","Suraski","Ben Gourion 3, Kiryat Bialik,
Israel","+972-4-8713139");
$user2->initialize("Andi","Gutmans","Haifa, Israel","+972-4-8231621");
$user1->display();
$user2->display();

$tmp = test($user2);
$tmp->display();

?>

This is getting very close to Javascript, if not in exact syntax, then at
least in spirit.

By the way, the two names listed in the example are the two main guys
writing the new mod_php parser.  

-Rasmus