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:17]
Daniel Viström
Line 12: Line 12:
  
 ==== Exempel 1 ==== ==== Exempel 1 ====
 +<code php>
 +<?php
 +include 'head.php';
 +
 +$a = new Counter();
 +echo $a->getValue() . '<br>';
  
 +// $a->value--; // Går inte att komma åt eftersom attributet är private.
 +
 +$i = 0;
 +while ($i < 20){
 +  $a->klick();
 +  $i++;
 +}
 +echo $a->getValue() . '<br>';
 +
 +$b = new Counter();
 +$b->klick();
 +echo $b->getValue() . '<br>';
 +
 +$b->zero();
 +echo $b->getValue() . '<br>';
 +
 +include 'foot.php';
 +
 +</code>
 <code php> <code php>
 <?php <?php
  
-// Klassen kan ligga i samma fil som huvudprogrammet, men försök att lägga det i separat fil som i exempel 2.+// Klassen kan ligga i samma fil som huvudprogrammet, men försök att lägga det i separat fil.
  
 class Counter{ class Counter{
Line 38: Line 63:
   }   }
 } }
- 
- 
-// Här börjar huvudprogrammet. 
- 
-include 'head.php'; 
- 
-$a = new Counter(); 
-echo $a->getValue() . '<br>'; 
- 
-// $a->value--; // Går inte att komma åt eftersom attributet är private. 
- 
-$i = 0; 
-while ($i < 20){ 
-  $a->klick(); 
-  $i++; 
-} 
-echo $a->getValue() . '<br>'; 
- 
-$b = new Counter(); 
-$b->klick(); 
-echo $b->getValue() . '<br>'; 
- 
-$b->zero(); 
-echo $b->getValue() . '<br>'; 
- 
-include 'foot.php'; 
- 
 </code> </code>