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

klass2och3.php

32 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>Even classier</title>
</head>
<body>
  <?php
    
class Ball {
      public 
$color = "red";
      public 
$radius = 15.0;

      function 
__construct($color, $radius) {
        
$this->color = $color;
        
$this->radius = $radius;
      }
      function 
get_info() {
        return 
"color: " . $this->color . ", radius:" . $this->radius;
      }
    }

    
$ball1 = new Ball("Red", 15.0);
    
$ball2 = new Ball("Blue", 10.0);
    
$ball3 = new Ball("Green", 30.0);

    echo 
"<p> Ball 1: " . $ball1->get_info() . "</p>";
    echo 
"<p> Ball 2: " . $ball2->get_info() . "</p>";
    echo 
"<p> Ball 3: " . $ball3->get_info() . "</p>";
  
?>
</body>
</html>