Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

Webserver1/Ovningar/Klasser/

klass1.php
klass2och3.php
klass4.php
klass5och6.php

klass1.php

42 lines ASCII Windows (CRLF)
<!DOCTYPE html>
<html lang="sv">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Very classy</title>
</head>
<body>
  <?php
    
class Ball {
      public 
$color "red";
      public 
$radius 15.0;

      function 
get_color() {
        return 
$this->color;
      }
      function 
set_color($color) {
        
$this->color $color;
      }

      function 
get_radius() {
        return 
$this->radius;
      }
      function 
set_radius($radius) {
        
$this->radius $radius;
      }
    }

    
$ball1 = new Ball();
    
$ball1->set_color("blue");

    
$ball2 = new Ball();
    
$ball2->set_radius(20.0);

    echo 
"<p> Ball 1: ";
    echo 
"color: "$ball1->get_color(), ", radius:"$ball1->get_radius();
    echo 
"</p> <p> Ball 2: ";
    echo 
"color: "$ball2->get_color(), ", radius:"$ball2->get_radius();
    echo 
"</p>";
  
?>
</body>
</html>