Advertisement
Guest User

Welche Methode ist besser?

a guest
May 25th, 2015
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php
  2.  // Methode 1: Im Konstruktor Objekte erzeugen und Variablen initialisieren, restlichen Code außerhalb der Klasse   //verarbeiten
  3.  class Auto {
  4.   public $reifen;
  5.   public $farbe;
  6.  
  7.   public function __construct(){
  8.    $this->reifen = 4;
  9.    $this->farbe = 'rot';
  10.   }
  11.  }
  12.  $auto = new Auto;
  13.  
  14.  if($_GET['auto'] == 'VW'){
  15.   echo 'Volkswagen';
  16.  } else if($_GET['auto'] == 'BMW'){
  17.   echo 'Bayerische Motoren Werke';
  18.  }
  19.  
  20.  
  21.  // Methode 2: Im Konstruktor Objekte erzeugen und Variablen initialisieren und restlichen Code verarbeiten
  22.  class Auto {
  23.   public $reifen;
  24.   public $farbe;
  25.  
  26.   public function __construct(){
  27.    $this->reifen = 4;
  28.    $this->farbe = 'rot';
  29.  
  30.    if($_GET['auto'] == 'VW'){
  31.     echo 'Volkswagen';
  32.    } else if($_GET['auto'] == 'BMW'){
  33.     echo 'Bayerische Motoren Werke';
  34.    }
  35.   }
  36.  }
  37.  $auto = new Auto;
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement