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 [2020-05-18 20:17]
Daniel Viström
dvprog_14 [2020-05-18 20:19]
Daniel Viström
Line 12: Line 12:
  
 ==== Exempel 1 ==== ==== Exempel 1 ====
- 
-<code php> 
-<?php 
- 
-// Klassen kan ligga i samma fil som huvudprogrammet, men försök att lägga det i separat fil. 
- 
-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 php> <code php>
 <?php <?php
Line 66: Line 37:
 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>