Webbserverprogrammering 1

Show sourcecode

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

webbsrvprg/exercises/klasserochobjekt/

index.php
ovn_ko1 copy.php
ovn_ko1.php
ovn_ko2.php
ovn_ko3.php
ovn_ko4.php
ovn_ko5.php
ovn_ko7.php

ovn_ko4.php

58 lines UTF-8 Windows (CRLF)
<?php
error_reporting
(-1); // Report all type of errors
ini_set('display_errors'1); // Display all errors
ini_set('output_buffering'0); // Do not buffer outputs, write directly
?>

<!DOCTYPE html>
<html lang="sv">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>KLASSER</title>
</head>

<body>
    <?php
    
class boll  {
        private 
$color;
        private 
$radius;
        function 
__construct($color$radius){
            
$this->color $color;
            
$this->radius $radius;
        }
        function 
getInfo(){
            
// Används inte
            
return("Den här bollen är $this->color och har radien $this->radius l.e.<br>");
        }
    }
    class 
bounceball extends boll {
        private 
$bounciness;
        function 
__construct($color$radius$bounciness)
        {
            
parent::__construct($color,$radius);
            
$this->bounciness $bounciness;
        }
        public function 
bounce(){
            echo(
"Boing. Studsade $this->bounciness meter upp <br>");
        }
    }
    class 
bowlingball extends boll {
        public function 
bounce(){
            echo(
"BANG. Inte en studsboll:(<br>");
        }
    }
    
$bollar = [];
    
$bollar[0] = new bounceball("lila"210);
    
$bollar[1] = new bowlingball("grön"123);
    
$bollar[2] = new bounceball("blå"1234567876543234562);
    for (
$i 0$i<count($bollar); $i++){
        echo(
$bollar[$i]->getInfo());
        
$bollar[$i]->bounce();
        echo(
"<br>");
    }
    
?>
</body>

</html>