Created
November 20, 2020 22:30
-
-
Save elishaukpong/9cb97defb2bec8d81ff66bd0a9a8a9dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//NULLSAFE OPERATOR | |
//class User { | |
// public function profile(){ | |
// return new Profile; | |
// } | |
//} | |
// | |
// | |
//class Profile { | |
// public function employment() | |
// { | |
// return 'Web Developer'; | |
// } | |
//} | |
// | |
// | |
//$user = new User; | |
// | |
//echo $user->profile()?->employment(); | |
// | |
//MATCH EXPRESSION | |
//class Conversation{} | |
// | |
//class Reply{} | |
// | |
//class Comment{} | |
// | |
//$obj = new Conversation; | |
////$obj = new Reply; | |
// | |
//$type = match (get_class($obj)){ | |
// 'Conversation' => 'started_converstation', | |
// 'Reply' => 'replied_to__converstation', | |
// 'Comment' => 'commented_on__converstation', | |
//}; | |
// | |
// | |
//echo $type; | |
//CONSTRUCTOR PROPERTY PROMOTION | |
//class User | |
//{ | |
// | |
// /** | |
// * User constructor. | |
// * @param $name | |
// */ | |
// public function __construct(protected string $name = 'User') | |
// { | |
// } | |
// | |
//} | |
// | |
// | |
//class Plan | |
//{ | |
// | |
// /** | |
// * Plan constructor. | |
// * @param $name | |
// */ | |
// public function __construct(protected string $name = 'Monthly') | |
// { | |
// } | |
// | |
//} | |
// | |
//class Signup | |
//{ | |
// | |
// /** | |
// * Signup constructor. | |
// * @param User $user | |
// * @param Plan $plan | |
// */ | |
// public function __construct(protected User $user, protected Plan $plan) | |
// { | |
// } | |
// | |
// | |
//} | |
// | |
// | |
//$user = new User('Elisha Ukpong'); | |
//$plan = new Plan('Yearly'); | |
// | |
//$signup = new Signup($user, $plan); | |
// | |
//var_dump($signup); | |
//$object::class | |
//class Conversation{} | |
// | |
//class Reply{} | |
// | |
//class Comment{} | |
// | |
//$obj = new Conversation; | |
////$obj = new Reply; | |
// | |
//$type = match ($obj::class){ | |
// 'Conversation' => 'started_converstation', | |
// 'Reply' => 'replied_to__converstation', | |
// 'Comment' => 'commented_on__converstation', | |
//}; | |
// | |
// | |
//echo $type; | |
//NAMED PARAMETERS | |
//class Invoice | |
//{ | |
// private $description; | |
// private $total; | |
// private $date; | |
// private $paid; | |
// | |
// /** | |
// * Invoice constructor. | |
// * @param $description | |
// * @param $total | |
// * @param $date | |
// * @param $paid | |
// */ | |
// public function __construct($description, $total, $date, $paid) | |
// { | |
// $this->description = $description; | |
// $this->total = $total; | |
// $this->date = $date; | |
// $this->paid = $paid; | |
// } | |
// | |
//} | |
// | |
//$invoice = new Invoice( | |
// description:'Customer installation', | |
// paid: true, | |
// total:10000, | |
// date: new DateTime() | |
//); | |
// | |
// | |
//var_dump($invoice); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment