Results: 1022
checkbox & radio differences
We can check as many checkboxes as we want, but we can only check one radio as long as they have the same name.
this
inside
fn()
function refers to the global
window
object. That is why
firstName
and
lastName
attributes are not accessible using
this
keyword
let john = {
  firstName: 'John',
  lastName: 'Doe',
  driveCar() {
    function fn () {
      console.log(this.firstName + ' ' + this.lastName + ' is driving a car');  // "undefined undefined is driving a car"
      console.log(this);
    }
    fn(); // fn.call(this);
    console.log(this.firstName + ' ' + this.lastName + ' is driving a car'); 
    console.log(this)
  }
}

john.driveCar(); 
In order to fix the issue, one of the ways is to use
call
function and pass the object that we want
this
to refer to inside the
fn()
function
fn.call(this);
Inside
driveCar()
function
this
refers to the
john
object because it is called through
john
object
john.driveCar();
Checks username value against the rule: must be at least 6 characters long and at most 12 characters long, only allowed alphanumeric symbols
if (!preg_match('/^[a-zA-Z0-9]{6,12}$/', $username)) {
    $this->addError('username', 'username must be 6-12 chars & alphanumeric');
}
class implements several interfaces CODE
One class implements several interfaces and takes responsibility to define all methods from both interfaces. Also defines several private methods additionally
interface int1 {
    // Force Extending class to define these methods
    function getArea();
} 

interface int2 {
    function getPerimeter();
} 

class Circle implements int1, int2 {
    static $PI = 3.1415926536;
    public $radius;
    
    public function __construct($radius) {
        $this->radius = $radius;
    }

    public function getPI() {
        return self::$PI;
    }
    
    public function getArea() {
        return pow($this->radius, 2) * self::$PI;
    }
    
    public function getDiameter() {
        return $this->radius * 2;
    }
    
    public function getPerimeter() {
        return $this->radius * 2 * self::$PI;
    }
}

$circle1 = new Circle(5);
echo "\nPI: " . $circle1->getPI();
echo "\nArea: " . $circle1->getArea();
echo "\nDiameter: " . $circle1->getDiameter();
echo "\nPerimeter: " . $circle1->getPerimeter();
interface example CODE
In this example class
Circle
implements
CircleAbstract
interface. Therefore it must define
getArea()
and
getPerimeter()
methods
interface CircleAbstract {
    // Force Extending class to define these methods
    function getArea();
    function getPerimeter();
} 

class Circle implements CircleAbstract {
    static $PI = 3.1415926536;
    public $radius;
    
    public function __construct($radius) {
        $this->radius = $radius;
    }

    public function getPI() {
        return self::$PI;
    }
    
    public function getArea() {
        return pow($this->radius, 2) * self::$PI;
    }
    
    public function getDiameter() {
        return $this->radius * 2;
    }
    
    public function getPerimeter() {
        return $this->radius * 2 * self::$PI;
    }
}

$circle1 = new Circle(5);
echo "\nPI: " . $circle1->getPI();
echo "\nArea: " . $circle1->getArea();
echo "\nDiameter: " . $circle1->getDiameter();
echo "\nPerimeter: " . $circle1->getPerimeter();
The child class extends parent class means that it borrows properties and methods from its parent
class User {
    public function მარტივიჯამი($num1,$num2) {
        return $num1 + $num2;
    }
}
class Admin extends User{
    
}
$admin1 = new Admin('Tom');

echo $admin1->მარტივიჯამი(4,5);
public
- visible from anywhere
private
- visible only for the owner class
protected
- visible only for the owner and it's child classes
class User {
    public $username;
    public $friends = ['Tom','David'];

    function __construct($name) {
        $this->username = $name;
        print $this->username . "'s object is created'\n";
    }

    private function მარტივიჯამი($num1,$num2) {
        return $num1 + $num2;
    }
}
class Admin extends User{
    function sumNumbers($num1,$num2) {
        return $this->მარტივიჯამი($num1,$num2);
    }
}
$admin1 = new Admin('Tom');

echo $admin1->sumNumbers(4,5);
clone
function clones the object and
__clone
method is going to call when the object gets cloned
class User {
    public $username;
    public $friends = ['Tom','David'];

    function __construct($name) {
        $this->username = $name;
        print $this->username . "'s object is created'\n";
    }

    function __clone() {
        print $this->username . "'s object is cloned'\n";
    }
}
$user1 = new User('Tom');
$user2 = clone $user1;
Note: There must not be more than one
<main>
element in a document. The
<main>
element must NOT be a descendant of an
<article>
,
<aside>
,
<footer>
,
<header>
, or
<nav>
element.
tag "iframe"
<iframe src="https://amazon.com">sorry</iframe>
<iframe>
is used to display another web site inside our web page. Also youtube videos can be embedded into iframes
Results: 1022