Guest User

Untitled

a guest
Feb 16th, 2018
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.05 KB | None | 0 0
  1. <?php
  2.  
  3. //Class ShoppingCard {
  4. //
  5. //}
  6. //
  7. //$product1 = new ShoppingCard();
  8. //$product2 = new ShoppingCard();
  9. //$product3 = new ShoppingCard();
  10. //
  11. //var_dump($product1 instanceof ShoppingCard);
  12. //var_dump($product2 instanceof Card);
  13. //
  14. //echo "<br><br><br>";
  15.  
  16. //class Shop {
  17. // private $name;
  18. //
  19. // public function naming() {
  20. // $this -> name = 'Adidas';
  21. // echo $this -> name;
  22. // }
  23. //
  24. //}
  25. //
  26. //$product = new Shop;
  27. //$product->naming();
  28. //
  29. //echo "<br><br><br>";
  30.  
  31. //class User {
  32. // public $name = 'Имя';
  33. // public $password = 'Пароль';
  34. // public $email = 'Мыло';
  35. // public $city = 'Город';
  36. //
  37.  
  38.  
  39. // public function Hello(){
  40. // echo "Hello! {$this->name}";
  41. // }
  42. //
  43. // function __construct($name, $password, $email, $city){
  44. // $this->name = $name;
  45. // $this->password = $password;
  46. // $this->email = $email;
  47. // $this->city = $city;
  48. // }
  49. // function getInfo(){
  50. // return "{$this->name}"."{$this->password}"."{$this->email}"."{$this->city}";
  51. // }
  52. //}
  53.  
  54.  
  55. //$user1 = new User('Alex', '123456', 'alegut2005@ukr.net', 'Zaporizhzhya');
  56. //echo "<br>".$user1->getInfo();
  57.  
  58. //$admin = new User();
  59. //$admin->name = "Andrey";
  60. //$admin->surname = "Ivanov";
  61. //echo "Пользователь: {$admin -> getInfo()}"
  62. //$user1 = new User();
  63. //echo $user1->name="Andrey";
  64. //$user1->surname="Ivanov";
  65. //echo $user1->surname;
  66.  
  67. //class User {
  68. // private static $name;
  69. //
  70. // public static function setName($name1){
  71. // self::$name = $name1;
  72. // }
  73. // public static function getName(){
  74. // return self::$name;
  75. // }
  76. //}
  77. //User::setName('Ivan');
  78. //echo User::getName()."<br>";
  79.  
  80.  
  81. //
  82. //class User {
  83. // public $name;
  84. // public $password;
  85. // public $email;
  86. // public $city;
  87. //
  88. // function __construct($name, $password, $email, $city){
  89. // $this->name = $name;
  90. // $this->password = $password;
  91. // $this->email = $email;
  92. // $this->city = $city;
  93. // }
  94. // function getInfo(){
  95. // $information = "{$this->name}"."{$this->password}"."{$this->email}"."{$this->city}";
  96. // return $information;
  97. // }
  98. //}
  99. //
  100. //class Moderator extends User {
  101. // public $info;
  102. // public $rights;
  103. //
  104. // function __construct($name, $password, $email, $city, $info, $rights){
  105. // parent::__construct($name, $password, $email, $city);
  106. // $this->info = $info;
  107. // $this->rights = $rights;
  108. // }
  109. // function getInfo(){
  110. // $information = parent::getInfo();
  111. // $information .= "{$this->info}"."{$this->rights}";
  112. // return $information;
  113. // }
  114. //}
  115. //
  116. //$mod = new Moderator('Alex', '123456', 'alegut2005@ukr.net', 'Zaporizhzhya', 'Moderator', 'True');
  117. //echo $mod->getInfo().'<br>';
  118. //
  119. //class Test {
  120. // protected $info;
  121. //}
  122.  
  123.  
  124. //
  125. //class Test2 extends Test {
  126. // public function test(){
  127. // $this->info = 'info';
  128. // echo $this->info;
  129. // }
  130. //}
  131. //$test2 = new Test2;
  132. //$test2->test();
  133. //$test2->info = 'information'; //нет доступа к protected
  134.  
  135.  
  136. // статические методы
  137.  
  138. //class user{
  139. // public static $name;
  140. //
  141. // public static function hello() {
  142. // echo "Hello ";
  143. // return self::$name;
  144. // }
  145. //}
  146. //
  147. //user::$name="Alexey";
  148. //echo user::$name;
  149. //echo user::hello();
  150.  
  151. // Константы
  152. //class user{
  153. // const SOME_CONST = 314;
  154. //}
  155. //
  156. //echo user::SOME_CONST;
  157.  
  158. // Абстрактные классы
  159.  
  160. //abstract class User {
  161. // public $name;
  162. // public $status;
  163. //
  164. // abstract public function getStatus();
  165. //}
  166. //
  167. //class Admin extends User {
  168. // public function getStatus(){
  169. // echo "Admin";
  170. // }
  171. //}
  172. ////$user1 = new User; //вернет FATAL_ERROR -нельзя создать объект абстрактного сласса
  173. //$user1 = new Admin;
  174. //$user1->getStatus();
  175.  
  176. // Интерфейсы
  177. //interface FirstInterFace {
  178. // public function getName();
  179. //}
  180. //interface SecondInterFace {
  181. // public function getStatus();
  182. //}
  183. //
  184. //interface ThirdInterFace extends FirstInterFace, SecondInterFace{
  185. //
  186. //}
  187. //
  188. //class Test implements FirstInterFace, SecondInterFace {
  189. // public $name = 'Alexey';
  190. // public $status = 'Admin';
  191. // public function getName(){
  192. // echo $this->name;
  193. // }
  194. // public function getStatus(){
  195. // echo $this->status;
  196. // }
  197. //}
  198. //$user1 = new Test;
  199. //echo $user1->getName();
  200. //echo $user1->getStatus();
  201.  
  202. // Трейты
  203.  
  204. //class Base {
  205. // public function sayHello(){
  206. // echo "Hello ";
  207. // }
  208. //}
  209. //trait sayWorld {
  210. // public function sayHello(){
  211. // parent::sayHello();
  212. // echo "World";
  213. // }
  214. //}
  215. //class myHelloWorld extends Base {
  216. // use sayWorld;
  217. //}
  218. //
  219. //$obj = new myHelloWorld();
  220. //$obj -> sayHello();
  221.  
  222. //или так
  223. //trait Hello {
  224. // public function sayHello(){
  225. // echo "Hello ";
  226. // }
  227. //}
  228. //trait World {
  229. // public function sayWorld(){
  230. // echo "World";
  231. // }
  232. //}
  233. //class myHelloWorld {
  234. // use Hello, World;
  235. //}
  236. //
  237. //$obj = new myHelloWorld();
  238. //$obj -> sayHello();
  239. //$obj -> sayWorld();
  240.  
  241. // Магический метод clone
  242.  
  243. //class User {
  244. // private $name;
  245. // private $city;
  246. // private $id;
  247. //
  248. // function __construct($name, $city) {
  249. // $this->name = $name;
  250. // $this->city = $city;
  251. // }
  252. // function setId($id){
  253. // $this->id = $id;
  254. // }
  255. //
  256. // public function __clone() {
  257. // $this->id = 0;
  258. // }
  259. //}
  260. //
  261. //$user1 = new User('Alexey', 'Zaporizhzhya');
  262. //$user1->setId(5432);
  263. //$user2 = clone $user1;
  264. //var_dump($user2);
  265.  
  266.  
  267. // Магические методы set, get
  268. //class Getset {
  269. // private $number =1;
  270. //
  271. // public function __get($name) {
  272. // echo "You get {$name}";
  273. // }
  274. // public function __set($name, $value) {
  275. // echo "You set {$name} to ";
  276. // }
  277. //}
  278. //$obj = new GetSet();
  279. //echo $obj->number;
  280. //echo $obj->number = 68;
  281.  
  282.  
  283. // Исключения
  284. $file = 'namespace.php';
  285.  
  286. try{
  287. if(!file_exists($file)) {
  288. throw new Exception('Flie not found');
  289. }
  290. }catch (Exception $e){
  291. echo $e->getMessage();
  292. }
  293.  
  294.  
  295. ?>
Add Comment
Please, Sign In to add comment