Introducing-PHP5.4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
$str = 'php,5.4';
$arr = explode(',', $str)[1]; //echo php
function dosomething(){
return [
'hello' => 'hello world'
];
}
/**
* 支持短语法 <?= 'xx'?> 相当于<?php echo 'xxx'?>
*/
dosomething()['hello'];
//echo hello world
/**
* 更加准确的处理时间
*/
//<5.4
$startTime = microtime(1);
//代码块
echo '花费了'.(microtime(1)-$startTime);
//>5.4
echo '花费了'.(microtime(1)-$_SERVER["REQUEST_TIME_FLOAT"]);
/**
* TRAIT 实现继承/重复利用
*/
trait name {
public function name($name){
return $name;
}
}
trait age{
public function age($age){
return $age;
}
}
class people{
use name;
use age;
public function peopleInfo(){
return 'this people name is '.$this->name('hello').'age'.$this->age(19);
}
}
$obj = new people();
var_dump($obj->peopleInfo());