Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //poniżej napisz kod definiujący klasę
- class Member {
- private $userName;
- private $password;
- private $accesLevel = 0;
- function __construct($userName, $password) {
- if (is_string($userName) && is_string($password)) {
- if (strlen($userName) >= 5) {
- $this->setUsername($userName);
- } else {
- $this->userName = $this->generateRandomString();
- }
- if (strlen($password) >= 5) {
- $this->setPassword($password);
- } else {
- $this->password = $this->generateRandomString();
- }
- }
- echo "Stworzono członka " . $this->userName. " o haśle " . $this->password . "\n<br>";
- }
- function __destruct() {
- echo "<br>\nObiekt użytkownika " . $this->getuserName() . " został zniszczony";
- }
- private function getuserName() {
- return $this->userName;
- }
- private function setuserName($userName) {
- $this->userName = $userName;
- }
- private function setPassword($password) {
- $this->password = $password;
- }
- private function getpassword() {
- return $this->password;
- }
- public function info(){
- echo "Użytkownik " . $this->userName . " o haśle " . $this->getpassword() . "<br>\n";
- }
- private function generateRandomString($length = 5) {
- $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $charactersLength = strlen($characters);
- $randomString = '';
- for ($i = 0; $i < $length; $i++) {
- $randomString .= $characters[rand(0, $charactersLength - 1)];
- }
- return $randomString;
- }
- }
- $obj= new Member('Stefan', "Armata");
- $obj2= new Member('Michał', "Arm");
- $obj->info();
- $obj3= new Member('Stef', "Wiśnia");
- $obj4= new Member('Małgosia', "Kałach");
- $obj4->info();
- $obj5= new Member('Heller', "Tomasz");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement