PHP5.3的新特性介绍,转自:http://www.quou.cn/
来源:互联网 发布:淘宝买仓鼠靠谱吗 编辑:程序博客网 时间:2024/06/16 06:59
1、引入 __DIR__ magic常量 定位脚本的目录
<?
echo __DIR__."|".dirname(__FILE__);
?>
2、允许从2个值的or/and表达式快速的获取一个非空的值
<?
echo (1 ?: 0) ."|". ("" ?: 0)."|". var_export(array() ?: array(1), true);
?>
3、类添加__callStatic方法,等价于 __call(),但它是为调用静态方法准备的。下面来看示例:
<?
class xxx{
function __call($func, $args){
echo "function name:".$func;
echo "</br />";
echo "args:".var_export($args, true);
}
static function __callStatic($func, $args){
echo "static function name:".$func;
echo "</br />";
echo "static args:".var_export($args, true);
}
}
$x = new xxx();
$x->testfunc("oo");
echo "</br />";
xxx::teststatic("xx");
?>
4、动态的调用静态的方法
<?
class xx{
static function test(){
echo __METHOD__;
}
}
$c = "xx";
$m = "test";
$c::$m();
?>
5、延迟静态绑定(静态处理从编译时延迟到执行时)
<?
class A{
static function whoami(){
echo __CLASS__;
}
static function say1(){
self::whoami();
}
static function say2(){
static::whoami();
}
}
class B extends A{
static function whoami(){
echo __CLASS__;
}
}
class C extends A{
static function whoami(){
echo __CLASS__;
}
}
B::say1();
C::say2();
?>
6、MySQLInd (高速的专门为PHP设计的MySQL调用库接口)
7、INI Magic
8、扩展的 OpenSSL 函数
9、SPL(Standard PHP Library) 优化
10、时间处理进行扩展了和添加
<?
$date = strtotime("11-05-17 00:00:00");
echo date("Y-m-d", $date)."|";
$date = date_create_from_format("y-m-d", "11-05-17");
echo $date->format("Y-m-d");
?>
11、垃圾回收器(为复杂和长时间运行脚本的执行结束周期释放内存的清理)
<?
gc_enable(); // 允许垃圾回收
var_dump(gc_enabled()); // true
var_dump(gc_collect_cycles()); // 某个元素的清理
gc_disable(); // 禁止垃圾回收
?>
12、NOWDOC(不对HEREDOC进行转译)
<?
$fubar = "xxx";
$xbar = <<<ONE
this is HEREDOC $fubar
ONE;
$abar = <<<'TWO'
this is NOWDOC $fubar
TWO;
echo $xbar."|".$abar;
?>
13、匿名函数体验
<?
$ofun = create_function('$a, $b', 'return $a*$b;'); //不要忘了分号,传统方法
echo $ofun(2, 5);
$nfun = function ($a, $b){
return $a*$b;
};//不要忘了分号,现代方法
echo $nfun(3, 5);
?>
14、闭包体验
<?
$arr = array(1, 2, 3, 5, 6, 7);
$res = array_filter($arr, function($v) { return $v >4; });
var_dump($res);
function countnum(){
$num = 0;
$testt = function() use(&$num){
++$num;
echo $num;
};
return $testt;
}
$t = countnum();
$t();
$t();
?>
15、命名空间
<?
namespace xxx; //第一个namespace需要在所有输出之前
function t(){
return __NAMESPACE__;
}
namespace xxx;
function t(){
return __NAMESPACE__;
}
echo \xx\t()."|";
echo \xxx\t();
- PHP5.3的新特性介绍,转自:http://www.quou.cn/
- PHP5.3新特性介绍
- [转] php5.3 PHP5.4 PHP5.5 新特性/使用PHP5.5要注意的
- PHP5.6新特性介绍
- PHP5.6新特性介绍
- PHP5.6新特性介绍
- ORACLE SEQUENCE的简单介绍(转自:http://www.dbonline.cn/source/oracle/20031224/PLSQL_oracle%20sequence%20brief%20intro.html)
- PHP5.3新特性
- PHP5.3新特性
- php5.3 新特性
- php5.3新特性
- PHP5.3之后的新特性
- PHP5.3的新特性解析
- php5.3以后新的特性
- c# 4.0新特性一览(转自:http://www.cnblogs.com/palo/archive/2009/03/01/1400949.html)
- php5.3 PHP5.4 PHP5.5 新特性/使用PHP5.5要注意的
- PHP5.3、PHP5.4、PHP5.5、PHP5.6的新特性
- php5.3 PHP5.4 PHP5.5 php5.6 新特性/使用PHP5.5/PHP5.6要注意的
- Connection reset by peer: socket write error错误分析及解决
- 一切将从这里开始
- vmware7.1汉化中文版序列号+注册机下载
- POJ 3630
- 两张图帮你快速入门Mercurial
- PHP5.3的新特性介绍,转自:http://www.quou.cn/
- java设置环境变量,、打包war,配置日志
- LRU页面调度算法
- JS取屏幕尺寸
- 02-struts 业务分离
- axis2 soap整合hibernate遇到的classloader问题(转)
- 学术资料账号密码全集汇总
- Android NDK C++开发注意事项总结
- 弹出输入框后,将listview内容遮住,解决方案