×
Clear all filters including search bar
Valeri Tandilashvili's Personal Professional Blog
who()
method of the child class B
from parent class A
class A {
public static function who() {
echo __CLASS__;
}
public static function test() {
self::who();
}
}
class B extends A {
public static function who() {
echo __CLASS__;
}
}
B::test();
The code will call who()
method of parent class and print its name A
If we need test()
to call who()
method of child class B
from parent class, then we can use late static binding
technique.
To achieve it, we use static
keyword:class A {
public static function who() {
echo __CLASS__;
}
public static function test() {
static::who(); // Here comes Late Static Bindings
}
}
class B extends A {
public static function who() {
echo __CLASS__;
}
}
B::test();
SELECT *,
IF(points>=90, "Brilliant", IF(points>=80, "Gold", IF(points>=60, "Silver", "Lazy"))) AS class
FROM `students`
ORDER BY points DESC
The same result using UNION
keywordSELECT *, 'Brilliant' AS class
FROM `students`
WHERE points >= 90
UNION
SELECT *, 'Gold'
FROM `students`
WHERE points >= 80
AND points < 90
UNION
SELECT *, 'Silver'
FROM `students`
WHERE points >= 60
AND points < 80
UNION
SELECT *, 'Lazy'
FROM `students`
WHERE points < 60
ORDER BY points DESC
The same result using CASE WHEN
conditional statementSELECT *,
CASE
WHEN points>90 THEN "Brilliant"
WHEN points>80 THEN "Gold"
WHEN points>60 THEN "Silver"
ELSE "Lazy"
END as 'class'
FROM `students`
ORDER BY points DESC
JSONP
is a technique to get data from server without cross-domain issues.
JSONP does not use the XMLHttpRequest
, instead it uses <script>
tag.
window.onload = function() {
var s = document.createElement("script");
s.src = "https://www.w3schools.com/js/demo_jsonp.php";
document.write(s.outerHTML);
};
// This function will run after the content is fully loaded from the server
function myFunc(myObj) {
document.write(myObj.name + " is " + myObj.age + " and he lives in " + myObj.city);
}
Requesting a content from another domain can cause problems, due to cross-domain policy. <script>
tag does not have this problem and that is the reason why it uses the tag instead of using XMLHttpRequest
object.
...
Content of the remote demo_jsonp.php
filemyFunc({"name":"John", "age":30, "city":"New York"});
toString
methodlet user = {
name: "John",
age: 30,
toString() {
return `{name1: "${this.name}", age1: ${this.age}}`;
}
};
document.write(user);
// document.write(JSON.stringify(user));
The code above will produce the following result:{name1: "John", age1: 30}
Interface IBar {
public function method3();
}
Interface IArray {
public function method2();
}
Interface IFoo extends IBar, IArray {
public function method1();
}
class class1 implements IFoo {
public function method1() {
}
public function method2() {
}
// public function method3() {
// }
}
Class class1
implements IFoo
interface which extends other two interfaces itself.
Because the class has not implemented method3
method (commented), then the following error will be generated:Fatal error: Class class1 contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (IBar::method3)
.flex-container > div {
flex:2;
}
The selector above has class name and tag name, therefore it's more specific than this selector:.search {
flex:4;
}
That's why the second selector has no effect in this example.
With more specific selector, like this:.flex-container .search {
flex:4;
}
the .search item will be twice as wide as the other flex items..parent {
position: relative;
}
.parent h1 {
position: absolute;
top: 10px;
}
https://youtu.be/aFtByxWjfLY?t=200callback function
name is the same as the callback
variable passed to the URL
https://api.github.com/users/yui?callback=handleJSONP_variable
The content returned from the request:handleJSONP_variable({"meta": {
"Content-Type": "application/javascript; charset=utf-8",
"Cache-Control": "public, max-age=60, s-maxage=60",
"Vary": "Accept",
"status": 200,
...
}, "data": {
"login": "yui",
"name": "YUI Library",
"company": null,
"blog": "http://yuilibrary.com/",
"location": "Sunnyvale, CA",
"email": null,
"public_repos": 31,
...
}})
h2
elements that has parent with both cl1
and cl2
classes.cl1.cl2 h2{
color: red;
}
.container {
display: flex;
justify-content: center;
align-items: center;
}