<div class="btn-group btn-group-lg" role="group" aria-label="Basic example">
<button type="button" class="btn btn-secondary">Left</button>
<button type="button" class="btn btn-secondary">Middle</button>
<button type="button" class="btn btn-secondary">Right</button>
</div>
<div class="btn-group" role="group" aria-label="Basic example">
<button type="button" class="btn btn-secondary">Left</button>
<button type="button" class="btn btn-secondary">Middle</button>
<button type="button" class="btn btn-secondary">Right</button>
</div>
<div class="btn-group btn-group-sm" role="group" aria-label="Basic example">
<button type="button" class="btn btn-secondary">Left</button>
<button type="button" class="btn btn-secondary">Middle</button>
<button type="button" class="btn btn-secondary">Right</button>
</div>
const cloneObj = function(obj){
// return JSON.parse(JSON.stringify(obj)); // "JSON"
// return {...obj} // "Spread"
// return Object.assign({}, obj); // "Object.assign"
};
Makes our code more modular and reusable
Makes our code easier to maintain
Makes it easier to debug when things go wrong
Makes it possible to hide / protect CLASS properties / methods (encapsulation)
Makes it possible to use other class properties / methods (inheritance)
Makes it possible to use polymorphism
color
, length
, top speed
Methods (behavior): start
, stop
, accelerate
signal
get_class
functionclass User {
public $username;
public $friends;
public function addFriend($friend_name) {
$this->friends[] = $friend_name;
}
}
$user1 = new User();
echo get_class($user1);
class User {
public $username;
public $friends;
public function addFriend($friend_name) {
$this->friends[] = $friend_name;
}
}
$user1 = new User();
print_r( get_class_vars('User') );
class User {
public $username = 'George';
public $friends = ['Tom','David'];
public function addFriend($friend_name) {
$this->friends[] = $friend_name;
}
}
$user1 = new User();
print_r( get_class_methods('User') );
__construct
gets called when a new object of the class gets createdclass User {
public $username;
public $friends = ['Tom','David'];
function __construct($name) {
$this->username = $name;
// print "In BaseClass constructor\n";
}
public function addFriend($friend_name) {
$this->friends[] = $friend_name;
}
}
$user1 = new User('George');
echo $user1->username;
__destruct
gets called when we delete an object manually.
If we don't delete the object during the code execution, it will be called automatically at the end of the code executionclass User {
public $username;
public $friends = ['Tom','David'];
function __construct($name) {
$this->username = $name;
print $this->username . "'s object is created'\n";
}
function __destruct() {
print $this->username . "'s object is deleted'\n";
}
}
$user1 = new User('George');
$user2 = new User('David');
echo $user1->username . "\n";
__destruct
method to call and the old object gets deleted
(the same result when we run unset($old_object)
)class User {
public $username;
public $friends = ['Tom','David'];
function __construct($name) {
$this->username = $name;
print $this->username . "'s object is created'\n";
}
function __destruct() {
print $this->username . "'s object is deleted'\n";
}
}
$user1 = new User('Tom');
$user1 = new User('George');
unset($user1);
$user2 = new User('David');
echo "\n\n";
After executing the above code the result will be the following:Tom's object is created'
George's object is created'
Tom's object is deleted'
George's object is deleted'
David's object is created'
David's object is deleted'
In this example when George's object gets created, Tom's object gets deleted immediately.
The reason is that we no longer have Tom's object in $user1
variable