Skip to content

Instantly share code, notes, and snippets.

@pjastr
Last active March 28, 2018 14:32
Show Gist options
  • Save pjastr/8c39c14a13726138d728cfbb885e52b9 to your computer and use it in GitHub Desktop.
Save pjastr/8c39c14a13726138d728cfbb885e52b9 to your computer and use it in GitHub Desktop.

Kod w programowaniu proceduralnym (strukturalnym)

Plik index.php:

<?php
$imieOsoba1="Jan";
$wiekOsoba1="20";
$imieOsoba2="Krzysztof";
$wiekOsoba2="45";
echo $imieOsoba1.",".$wiekOsoba1.'<br/>';
echo $imieOsoba2.",".$wiekOsoba2;
?>

Kod w programowaniu obiektowym

plik Osoba.php

<?php
class Osoba {
    public $imie;
    public $wiek;
    
    public function __construct($imie, $wiek)
    {
      $this->imie = $imie;
      $this->wiek = $wiek;
    } 
    
    public function pobierzOpis()
    {
        return $this->imie.", ".$this->wiek;
    }
     
}

plik index.php

<?php
require('./Osoba.php');
$osoba1= new Osoba("Jan", 20);
$osoba2= new Osoba("Krzysztof", 45);

echo $osoba1->pobierzOpis().'<br/>';
echo $osoba2->pobierzOpis();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment