[Switch] PHP5.3 test the essence of features finishing 1. introduce _ DIR _ magic constant to locate the script directory echo _ DIR __. |. dirname (_ FILE _); 2. allow orand expressions with two values to quickly obtain a non-empty value echo (1? : 0). | .(? : 0). |. var_export (array ()? : [Switch] PHP5.3 test the essence of features
1. introduce the _ DIR _ magic constant to locate the script directory.
echo __DIR__."|".dirname(__FILE__);
2. allow the or/and expression with two values to quickly obtain a non-null value.
echo (1 ?: 0) ."|". ("" ?: 0)."|". var_export(array() ?: array(1), true);
3. add the _ callStatic method to the class. it is equivalent to _ call (), but it is prepared to call the static method. The following is an example:
class xxx{ function __call($func, $args){ echo "function name:".$func; echo "
"; echo "args:".var_export($args, true); } static function __callStatic($func, $args){ echo "static function name:".$func; echo "
"; echo "static args:".var_export($args, true); } } $x = new xxx(); $x->testfunc("oo"); echo "
"; xxx::teststatic("xx");
4. Dynamic Call of static methods
class xx{ static function test(){ echo __METHOD__; } } $c = "xx"; $m = "test"; $c::$m();
5. delayed static binding (when static processing delays execution from compilation)
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 (high-speed MySQL call library interface specially designed for PHP)
7. INI Magic
8. extended OpenSSL functions
9. SPL (Standard PHP Library) optimization
10. time processing is extended and added
$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. garbage collector (cleaning of memory released for the execution end cycle of complex and long-running scripts)
Gc_enable (); // permit garbage collection var_dump (gc_enabled (); // true var_dump (gc_collect_cycles (); // clear gc_disable () for an element (); // prohibit garbage collection
12. NOWDOC (do not translate HEREDOC)
$ Fubar = "xxx"; $ xbar = <
13. Anonymous function experience
$ Ofun = create_function ('$ a, $ B', 'return $ a * $ B; '); // do not forget the semicolon. echo $ ofun (2, 5); $ nfun = function ($ a, $ B) {return $ a * $ B;}; // do not forget the semicolon, modern method echo $ nfun (3, 5 );
14. closure experience
$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
Namespace xxx; // before the first namespace is output, function t () {return _ NAMESPACE __;} namespace xxx; function t () {return _ NAMESPACE __;} echo \ xx \ t (). "|"; echo \ xxx \ t ();