7. Непрямий виклик методу змінної
масиву
class Test {
public function world($x){
echo "Hello, $x";
return $this;
}
}
$f = array('Test','world');
$f('you'); // Hello, you
9. Traits OR Horizontal Reuse OR Multiple
Inheritance
trait Hello {
public function hello() {
return "Hello";
}
}
trait City {
public function city($name) {
return $name;
}
}
class Welcome {
use Hello, City;
}
$var = new Welcome();
echo $var->hello(). ' '. $var->city("Montreal"); // Hello Montreal
10. Traits OR Horizontal Reuse OR Multiple
Inheritance
trait Hello {
public function hello() {
return "Hello";
}
}
trait City {
public function city($name) {
return $name;
}
}
class Welcome {
use Hello, City;
}
$var = new Welcome();
echo $var->hello(). ' '. $var->city("Montreal");
echo (new Welcome())->hello(), ' ', (new Welcome())->city("Montreal"); // Hello Montreal
11. Traits OR Horizontal Reuse OR Multiple
Inheritance
trait Hello {
public function hello() {
return "Hello"; }
}
trait City {
public function city($name) {
return $name; }
}
trait Greeting {
use Hello, City;
public function greeting($name) {
echo $this->hello(), ' ', $this->city($name); }
}
class Welcome { use Greeting; }
echo (new Welcome())->greeting("Montreal"); // Hello Montreal
12. Traits. Encapsulation
trait Hello {
private function hello($city) {
echo "Hello " , $city;
}
}
class Welcome {
use Hello {
hello as public;
}
}
(new Welcome())->hello("Montreal"); // "Hello Montreal"
13. Traits. Encapsulation
trait Hello {
private function hello($city) {
echo "Hello " , $city;
}
}
class Welcome {
use Hello {
hello as public;
}
}
(new Welcome())->hello("Montreal"); // Fatal error: Call to private method Welcome::hello()…
14. Traits
trait Who {
public function msg($name) { return $name; }
}
trait Hello {
private function msg() { return "Hello"; }
}
class Welcome {
use Who, Hello {
hello::msg as public hi;
Who::msg insteadof Hello;
}
}
$w = new Welcome();
echo $w->hi(), ' ', $w->msg("Montreal"); // "Hello Montreal"
15. Traits. Identifying traits
trait Hello {
public function hi() { return 'Hello'; }
}
class Welcome {
use Hello { hello::hi as public hello; }
}
$rc = new ReflectionClass('Welcome');
if (!$rc->isTrait()) {
echo $rc->getTraitNames()[0]; // prints "Hello"
echo $rc->getTraitAliases()['hello']; // prints "hello::hi"
foreach ($rc->getTraits() as $v) {
echo $v->getMethods()[0]->class, ' ',
$v->getMethods()[0]->name; // prints "hello hi"
}
}
16. Upload progress
був в HTML 5 File API
і в nginx-upload-progress-module
Тепер в сесії користувача в ключі upload_progress_formname