Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
dvprog_14 [2019-12-06 16:11]
Daniel Viström
dvprog_14 [2020-05-18 20:20]
Daniel Viström
Line 12: Line 12:
  
 ==== Exempel 1 ==== ==== Exempel 1 ====
- 
 <code php> <code php>
 <?php <?php
- +include 'counter.php';
-// Klassen kan ligga i samma fil som huvudprogrammet, men försök att lägga det i separat fil som i exempel 2. +
- +
-class Counter{ +
- +
-  private $value; +
-   +
-  public function __construct(){ +
-    $this->value = 0; +
-  } +
-   +
-  public function klick(){ +
-    $this->value++; +
-  } +
-   +
-  public function getValue(){ +
-    return $this->value; +
-  } +
-   +
-  public function zero(){ +
-    $this->value = 0; +
-  } +
-+
- +
- +
-// Här börjar huvudprogrammet. +
 include 'head.php'; include 'head.php';
  
Line 65: Line 38:
 include 'foot.php'; include 'foot.php';
  
 +</code>
 +
 +Klassen **Counter** ligger i en separat fil, **counter.php**. \\ 
 +Klassen kan ligga i samma fil som huvudprogrammet, men försök att lägga det i separat fil.
 +
 +<code php>
 +<?php
 +class Counter{
 +
 +  private $value;
 +  
 +  public function __construct(){
 +    $this->value = 0;
 +  }
 +  
 +  public function klick(){
 +    $this->value++;
 +  }
 +  
 +  public function getValue(){
 +    return $this->value;
 +  }
 +  
 +  public function zero(){
 +    $this->value = 0;
 +  }
 +}
 </code> </code>