×
Clear all filters including search bar
Valeri Tandilashvili's Personal Professional Blog
traits in the same class, the traits must not have the same method declaredtrait Laser {
public function who() {
echo 'I am a Laser' . PHP_EOL;
}
}
trait Projector {
public function who() {
echo 'I am a Laser' . PHP_EOL;
}
}
class Galaxy {
use Laser;//, Projector;
use Projector;
}
Fatal error: Trait method who has not been applied, because there are collisions with other trait methods on Galaxygetmypid - Gets PHP's process IDecho 'Current process ID:' . getmypid();
The output will be:Current process ID:4868index.php filespl_autoload_register(function($class) {
// echo 'register class:'.$class."<br>";
require_once("classes/{$class}.php");
});
// echo 'hey there on line 7'."<br>";
$cat = new Cat;
$dog = new Dog;
$tortoise = new Tortoise;
echo $cat->talk();
echo $dog->talk();
echo $tortoise->talk();
Content of classes/Talkative.php file interface Talkative {
public function talk();
}
Content of classes/Cat.php file class Cat implements Talkative {
public function talk() {
return 'Meow' . '<br>';
}
}
Content of classes/Dog.php file class Dog implements Talkative {
public function talk() {
return 'Woof' . '<br>';
}
}
Content of classes/Tortoise.php file class Tortoise implements Talkative {
public function talk() {
return 'Yak yak yak yak ...' . '<br>';
}
}
Filenames and class names must be THE SAMEMakes 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 polymorphismnpm list --depth 0
Shows all packages with only their dependencies (one level deep)npm list --depth 1lastName declared by the keyword let is not added to the global window object.
That is why the variable is equal to undefined // Declaring variable using keyword "var"
var firstName = "Jet"
// Declaring variable using keyword "let"
let lastName = "Li"
// Declaring variable without using any keyword
carMark = "Tesla"
function driveCar() {
console.log(this.firstName + ' ' + this.lastName + ' is driving a car '+this.carMark)
}
driveCar()
The result will be:Jet undefined is driving a car TeslaBecause declaring variable with var keyword and without any declaration keyword are the same.
Both add the variable to the global window object.
After running the above code, global object window will have firstName and lastName attributeswindow.firstName; // "Jet"
window.lastName; // undefined
window.carMark; // "Tesla"var el = document.getElementById("myimg");
el.src = "https://www.sololearn.com/Images/home-new/1073.png";
HTML<img id="myimg" src="https://www.sololearn.com/Images/home-new/1068.png" alt="" />
Note: Practically all attributes of an element can be changed using JavaScript// Anonymous function
document.addEventListener('click', function(){
console.log('You clicked me!');
})
The same function with arrow function syntax// Arrow function
document.addEventListener('click', () => {
console.log('You clicked me!');
})
Even more minimalistic arrow function// More minimalistic arrow function
document.addEventListener('click', () => console.log('You clicked me!'))CROSS JOIN is the same as INNER or implicit joins.
Without conditions, both result in Cartesian product:SELECT
students.*,
notes.*
FROM `notes`
CROSS JOIN `students`
JOIN example:SELECT
students.*,
notes.*
FROM `notes`
JOIN `students` JOIN is the short form of INNER JOIN SELECT
students.*,
notes.*
FROM `notes`
INNER JOIN `students`
Implicit join exampleSELECT
students.*,
notes.*
FROM `notes`, `students`
Both the queries return the exact same resultregister_shutdown_function('myexit');
function myexit()
{
echo "</schedule>";
}