Results: 1578
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
__get
and
__set
magic methods allows us to get and set any variable without having individual getter and setter methods:
class Foo {
    protected $properties = array();

    public function __get( $key )
    {
        if(array_key_exists($key, $this->properties)){
            return $this->properties[$key];
        }
        return $this->properties[ $key ];
    }
    public function __set( $key, $value )
    {
        $this->properties[ $key ] = $value;
    }
}
$foo = new Foo();
$foo->name = 'David';

echo $foo->name;
In this example, we can set any variable, even if it does not exist. Every variable will be addd to
properties
array
by Valeri Tandilashvili
4 years ago
0
PHP
OOP
3
__get
and
__set
methods are called when there is an attempt either to use or to set a new value to any of the class property
class Person{
    public $firstName;
 
    public function __get($propertyName){
        echo "attempted to read property: $propertyName" . PHP_EOL;
    } 
    public function __set($propertyNane, $propertyValue){
        echo "attempted to set new value to property: $propertyNane" . PHP_EOL;
    } 
}
 
$p = new Person();
 
$p->firstName = 'Doe';
echo $p->firstName . PHP_EOL;
 
$p->lastName = 'John';
echo $p->lastName;
If the property is
public
, the methods are not going to be called (if the property does not exist, or exists but is not public, the methods will get called) If we make
$firstName
property
private
or
protected
, the methods will be called for the
$firstName
property
__get
,
__set
,
__call
and
__callStatic
are invoked when the method or property is inaccessible
by Valeri Tandilashvili
4 years ago
0
PHP
OOP
PHP Object Oriented Programming (OOP)
3
element.
childNodes
returns an array of an element's child nodes. JS
function setText() {
    let a = document.getElementById("demo");
     let arr = a.childNodes;
     for(let x=0;x<arr.length;x++) {
       arr[x].innerHTML = "new text";
     }
}

//calling the function with setTimeout to make sure the HTML is loaded
setTimeout(setText, 500);
HTML of the example
<div id ="demo">
  <p>some text</p>
  <p>some other text</p>
</div>
Note: The code above changes the text of both paragraphs to
new text
by Valeri Tandilashvili
3 years ago
0
JavaScript
DOM
3
element.
childNodes
returns an array of an element's child nodes. element.
firstChild
returns the first child node of an element. element.
lastChild
returns the last child node of an element. element.
hasChildNodes
returns true if an element has any child nodes, otherwise false. element.
nextSibling
returns the next node at the same tree level. element.
previousSibling
returns the previous node at the same tree level. element.
parentNode
returns the parent node of an element.
by Valeri Tandilashvili
3 years ago
0
JavaScript
DOM
3
we can not use $this (object properties) inside static methods
class Wheather {
    public $nonStatic = 0;
    public static $tempConditions = ['cold', 'mild', 'warm'];
    public static $someProperty = 5;

    static function celsiusToFarenheit($celsius) {
        return $celsius * 9 / 5 + 32 + $this->nonStatic;
    }
}

echo Wheather::celsiusToFarenheit(0);
echo "\n";
In this case we will get the error:
Fatal error:  Uncaught Error: Using $this when not in object context
by Valeri Tandilashvili
4 years ago
0
PHP
OOP
3
we can use static properties inside object methods (non-static methods)
We can use static properties inside non-static methods but we can't use
$this
inside static methods
class Circle {
    public static $pi = 3.1415926535;
    public $radius;
    
    public function __construct($radius) {
        $this->radius = $radius;
    }
    
    public function getArea() {
        return pow($this->radius, 2) * self::$pi;
    }
    
    public function getPerimeter() {
        return $this->radius * 2 * self::$pi;
    }
}

$circle1 = new Circle(5);
echo "\nArea: " . $circle1->getArea();
echo "\nPerimeter: " . $circle1->getPerimeter();
by Valeri Tandilashvili
4 years ago
0
PHP
OOP
3
<h1>Example heading <span class="badge badge-primary">New</span></h1>
<h2>Example heading <span class="badge badge-secondary">New</span></h2>
<h3>Example heading <span class="badge badge-warning">New</span></h3>
<h4>Example heading <span class="badge badge-success">New</span></h4>
<h5>Example heading <span class="badge badge-secondary">New</span></h5>
<h6>Example heading <span class="badge badge-secondary">New</span></h6>
by Valeri Tandilashvili
4 years ago
0
Bootstrap
badge
Bootstrap official doc
2
JSON object can have another JSON object as a child
var myObj = {
    "name":"John",
    "age":30,
    "cars": {
        "car1":"Ford",
        "car2":"BMW",
        "car3":"Fiat"
    }
}

// Accessing nested object properties
document.write(myObj.cars.car2);
document.write("<br />");
document.write(myObj.cars["car2"]);
document.write("<br />");
document.write(myObj["cars"]["car2"]);
by Valeri Tandilashvili
3 years ago
0
JSON
JavaScript
JS JSON
2
Comment is not supported in JSON but we can do the trick - to add the
comment
inside the object as a
property
{  
    "employee": {  
        "name": "George",   
        "a0ge": "30",   
        "city": "Tbilisi",   
        "comments": "The best student ever"  
    }  
}
by Valeri Tandilashvili
3 years ago
0
JSON
comments
JSON Tutorial
2
At first we need to create two
datetime
objects using
createFromFormat
static method of
DateTime
built-in class
$first_date = DateTime::createFromFormat('Y-m-d', "2020-12-23");
$second_date = DateTime::createFromFormat('Y-m-d', "2020-12-30");
Using
diff()
method of
DateTime
class we actually calculate differences between the two dates and we get the result in days
$difference_between_the_days = $second_date->diff($first_date)->format("%a");
	
echo $difference_between_the_days;
by Valeri Tandilashvili
4 years ago
0
PHP
datetime
2
Results: 1578