{"id":1183,"date":"2015-07-13T09:31:26","date_gmt":"2015-07-13T01:31:26","guid":{"rendered":"http:\/\/www.awaysoft.com\/taor\/?p=1183"},"modified":"2015-07-13T09:47:06","modified_gmt":"2015-07-13T01:47:06","slug":"php-%e8%87%aa-5-2-%e5%88%b0-5-6-%e4%b8%ad%e6%96%b0%e5%a2%9e%e7%9a%84%e5%8a%9f%e8%83%bd%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/actom.me\/blog\/php-%e8%87%aa-5-2-%e5%88%b0-5-6-%e4%b8%ad%e6%96%b0%e5%a2%9e%e7%9a%84%e5%8a%9f%e8%83%bd%e8%af%a6%e8%a7%a3.html","title":{"rendered":"[\u8f6c]PHP \u81ea 5.2 \u5230 5.6 \u4e2d\u65b0\u589e\u7684\u529f\u80fd\u8be6\u89e3"},"content":{"rendered":"<div class=\"article fmt\">\n<p>\u622a\u81f3\u76ee\u524d(2014.2), PHP \u7684\u6700\u65b0\u7a33\u5b9a\u7248\u672c\u662f PHP5.5, \u4f46\u6709\u5dee\u4e0d\u591a\u4e00\u534a\u7684\u7528\u6237\u4ecd\u5728\u4f7f\u7528\u5df2\u7ecf\u4e0d\u5728\u7ef4\u62a4 [\u6ce8] \u7684 PHP5.2, \u5176\u4f59\u7684\u4e00\u534a\u7528\u6237\u5728\u4f7f\u7528 PHP5.3 [\u6ce8].<br \/>\n\u56e0\u4e3a PHP \u90a3\u201c\u96c6\u767e\u5bb6\u4e4b\u957f\u201d\u7684\u86cb\u75bc\u8bed\u6cd5\uff0c\u52a0\u4e0a\u793e\u533a\u6c1b\u56f4\u4e0d\u597d\uff0c\u5f88\u591a\u4eba\u5bf9\u65b0\u7248\u672c\uff0c\u65b0\u7279\u5f81\u5e76\u65e0\u5174\u8da3\u3002<br \/>\n\u672c\u6587\u5c06\u4f1a\u4ecb\u7ecd\u81ea PHP5.2 \u8d77\uff0c\u76f4\u81f3 PHP5.6 \u4e2d\u589e\u52a0\u7684\u65b0\u7279\u5f81\u3002<\/p>\n<ul>\n<li>PHP5.2 \u4ee5\u524d\uff1aautoload, PDO \u548c MySQLi, \u7c7b\u578b\u7ea6\u675f<\/li>\n<li>PHP5.2\uff1aJSON \u652f\u6301<\/li>\n<li>PHP5.3\uff1a\u5f03\u7528\u7684\u529f\u80fd\uff0c\u533f\u540d\u51fd\u6570\uff0c\u65b0\u589e\u9b54\u672f\u65b9\u6cd5\uff0c\u547d\u540d\u7a7a\u95f4\uff0c\u540e\u671f\u9759\u6001\u7ed1\u5b9a\uff0cHeredoc \u548c Nowdoc, const, \u4e09\u5143\u8fd0\u7b97\u7b26\uff0cPhar<\/li>\n<li>PHP5.4\uff1aShort Open Tag, \u6570\u7ec4\u7b80\u5199\u5f62\u5f0f\uff0cTraits, \u5185\u7f6e Web \u670d\u52a1\u5668\uff0c\u7ec6\u8282\u4fee\u6539<\/li>\n<li>PHP5.5\uff1ayield, list() \u7528\u4e8e foreach, \u7ec6\u8282\u4fee\u6539<\/li>\n<li>PHP5.6: \u5e38\u91cf\u589e\u5f3a\uff0c\u53ef\u53d8\u51fd\u6570\u53c2\u6570\uff0c\u547d\u540d\u7a7a\u95f4\u589e\u5f3a<\/li>\n<\/ul>\n<p>\u6ce8\uff1a\u5df2\u4e8e2011\u5e741\u6708\u505c\u6b62\u652f\u6301\uff1a <a href=\"http:\/\/www.php.net\/eol.php\" target=\"_blank\" rel=\"nofollow\">http:\/\/www.php.net\/eol.php<\/a><br \/>\n\u6ce8\uff1a<a href=\"http:\/\/w3techs.com\/technologies\/details\/pl-php\/5\/all\" target=\"_blank\" rel=\"nofollow\">http:\/\/w3techs.com\/technologies\/details\/pl-php\/5\/all<\/a><\/p>\n<h2 id=\"articleHeader0\">PHP5.2\u4ee5\u524d<\/h2>\n<p>(2006\u524d)<br \/>\n\u987a\u4fbf\u4ecb\u7ecd\u4e00\u4e0b PHP5.2 \u5df2\u7ecf\u51fa\u73b0\u4f46\u503c\u5f97\u4ecb\u7ecd\u7684\u7279\u5f81\u3002<\/p>\n<h2 id=\"articleHeader1\">autoload<\/h2>\n<p>\u5927\u5bb6\u53ef\u80fd\u90fd\u77e5\u9053 __autoload() \u51fd\u6570\uff0c\u5982\u679c\u5b9a\u4e49\u4e86\u8be5\u51fd\u6570\uff0c\u90a3\u4e48\u5f53\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528\u4e00\u4e2a\u672a\u5b9a\u4e49\u7684\u7c7b\u7684\u65f6\u5019\uff0c\u8be5\u51fd\u6570\u5c31\u4f1a\u88ab\u8c03\u7528\uff0c\u4f60\u53ef\u4ee5\u5728\u8be5\u51fd\u6570\u4e2d\u52a0\u8f7d\u76f8\u5e94\u7684\u7c7b\u5b9e\u73b0\u6587\u4ef6\uff0c\u5982\uff1a<\/p>\n<pre class=\"hljs php\"><code>function __autoload($classname)\r\n{\r\n    require_once( \"{$classname}.php\")\r\n}\r\n<\/code><\/pre>\n<p>\u4f46\u8be5\u51fd\u6570\u5df2\u7ecf\u4e0d\u88ab\u5efa\u8bae\u4f7f\u7528\uff0c\u539f\u56e0\u662f\u4e00\u4e2a\u9879\u76ee\u4e2d\u4ec5\u80fd\u6709\u4e00\u4e2a\u8fd9\u6837\u7684 __autoload() \u51fd\u6570\uff0c\u56e0\u4e3a PHP \u4e0d\u5141\u8bb8\u51fd\u6570\u91cd\u540d\u3002\u4f46\u5f53\u4f60\u4f7f\u7528\u4e00\u4e9b\u7c7b\u5e93\u7684\u65f6\u5019\uff0c\u96be\u514d\u4f1a\u51fa\u73b0\u591a\u4e2a autoload \u51fd\u6570\u7684\u9700\u8981\uff0c\u4e8e\u662f spl_autoload_register() \u53d6\u800c\u4ee3\u4e4b\uff1a<\/p>\n<pre class=\"hljs php\"><code>spl_autoload_register(function($classname)\r\n{\r\n    require_once(\"{$classname}.php\")\r\n});\r\n<\/code><\/pre>\n<p>spl_autoload_register() \u4f1a\u5c06\u4e00\u4e2a\u51fd\u6570\u6ce8\u518c\u5230 autoload \u51fd\u6570\u5217\u8868\u4e2d\uff0c\u5f53\u51fa\u73b0\u672a\u5b9a\u4e49\u7684\u7c7b\u7684\u65f6\u5019\uff0cSPL [\u6ce8] \u4f1a\u6309\u7167\u6ce8\u518c\u7684\u5012\u5e8f\u9010\u4e2a\u8c03\u7528\u88ab\u6ce8\u518c\u7684 autoload \u51fd\u6570\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u53ef\u4ee5\u4f7f\u7528 spl_autoload_register() \u6ce8\u518c\u591a\u4e2a autoload \u51fd\u6570.<\/p>\n<p>\u6ce8\uff1aSPL: Standard PHP Library, \u6807\u51c6 PHP \u5e93, \u88ab\u8bbe\u8ba1\u7528\u6765\u89e3\u51b3\u4e00\u4e9b\u7ecf\u5178\u95ee\u9898(\u5982\u6570\u636e\u7ed3\u6784).<\/p>\n<h2 id=\"articleHeader2\">PDO \u548c MySQLi<\/h2>\n<p>\u5373 PHP Data Object, PHP \u6570\u636e\u5bf9\u8c61\uff0c\u8fd9\u662f PHP \u7684\u65b0\u5f0f\u6570\u636e\u5e93\u8bbf\u95ee\u63a5\u53e3\u3002<\/p>\n<p>\u6309\u7167\u4f20\u7edf\u7684\u98ce\u683c\uff0c\u8bbf\u95ee MySQL \u6570\u636e\u5e93\u5e94\u8be5\u662f\u8fd9\u6837\u5b50\uff1a<\/p>\n<pre class=\"hljs php\"><code>\/\/ \u8fde\u63a5\u5230\u670d\u52a1\u5668\uff0c\u9009\u62e9\u6570\u636e\u5e93\r\n$conn = mysql_connect( \"localhost\",  \"user\",  \"password\");\r\nmysql_select_db( \"database\");\r\n\r\n\/\/ \u6267\u884c SQL \u67e5\u8be2\r\n$type = $_POST[ 'type'];\r\n$sql =  \"SELECT * FROM `table` WHERE `type` = {$type}\";\r\n$result = mysql_query($sql);\r\n\r\n\/\/ \u6253\u5370\u7ed3\u679c\r\nwhile($row = mysql_fetch_array($result, MYSQL_ASSOC))\r\n{\r\n    foreach($rowas$k=&gt; $v)\r\n        print \"{$k}: {$v}\\n\";\r\n}\r\n\r\n\/\/ \u91ca\u653e\u7ed3\u679c\u96c6\uff0c\u5173\u95ed\u8fde\u63a5\r\nmysql_free_result($result);\r\nmysql_close($conn);\r\n<\/code><\/pre>\n<p>\u4e3a\u4e86\u80fd\u591f\u8ba9\u4ee3\u7801\u5b9e\u73b0\u6570\u636e\u5e93\u65e0\u5173\uff0c\u5373\u4e00\u6bb5\u4ee3\u7801\u540c\u65f6\u9002\u7528\u4e8e\u591a\u79cd\u6570\u636e\u5e93(\u4f8b\u5982\u4ee5\u4e0a\u4ee3\u7801\u4ec5\u4ec5\u9002\u7528\u4e8eMySQL)\uff0cPHP \u5b98\u65b9\u8bbe\u8ba1\u4e86 PDO.<br \/>\n\u9664\u6b64\u4e4b\u5916\uff0cPDO \u8fd8\u63d0\u4f9b\u4e86\u66f4\u591a\u529f\u80fd\uff0c\u6bd4\u5982\uff1a<\/p>\n<ul>\n<li>\u9762\u5411\u5bf9\u8c61\u98ce\u683c\u7684\u63a5\u53e3<\/li>\n<li>SQL\u9884\u7f16\u8bd1(prepare), \u5360\u4f4d\u7b26\u8bed\u6cd5<\/li>\n<li>\u66f4\u9ad8\u7684\u6267\u884c\u6548\u7387\uff0c\u4f5c\u4e3a\u5b98\u65b9\u63a8\u8350\uff0c\u6709\u7279\u522b\u7684\u6027\u80fd\u4f18\u5316<\/li>\n<li>\u652f\u6301\u5927\u90e8\u5206SQL\u6570\u636e\u5e93\uff0c\u66f4\u6362\u6570\u636e\u5e93\u65e0\u9700\u6539\u52a8\u4ee3\u7801<\/li>\n<\/ul>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u7528 PDO \u5b9e\u73b0\u5c06\u4f1a\u662f\u8fd9\u6837\uff1a<\/p>\n<pre class=\"hljs php\"><code>\/\/ \u8fde\u63a5\u5230\u6570\u636e\u5e93\r\n$conn= newPDO( \"mysql:host=localhost;dbname=database\",  \"user\",  \"password\");\r\n\r\n\/\/ \u9884\u7f16\u8bd1SQL, \u7ed1\u5b9a\u53c2\u6570\r\n$query= $conn-&gt;prepare( \"SELECT * FROM `table` WHERE `type` = :type\");\r\n$query-&gt;bindParam( \"type\", $_POST[ 'type']);\r\n\r\n\/\/ \u6267\u884c\u67e5\u8be2\u5e76\u6253\u5370\u7ed3\u679c\r\nforeach($query-&gt;execute() as $row)\r\n{\r\n    foreach($rowas$k=&gt; $v)\r\n        print \"{$k}: {$v}\\n\";\r\n}\r\n<\/code><\/pre>\n<p>PDO \u662f\u5b98\u65b9\u63a8\u8350\u7684\uff0c\u66f4\u4e3a\u901a\u7528\u7684\u6570\u636e\u5e93\u8bbf\u95ee\u65b9\u5f0f\uff0c\u5982\u679c\u4f60\u6ca1\u6709\u7279\u6b8a\u9700\u6c42\uff0c\u90a3\u4e48\u4f60\u6700\u597d\u5b66\u4e60\u548c\u4f7f\u7528 PDO.<br \/>\n\u4f46\u5982\u679c\u4f60\u9700\u8981\u4f7f\u7528 MySQL \u6240\u7279\u6709\u7684\u9ad8\u7ea7\u529f\u80fd\uff0c\u90a3\u4e48\u4f60\u53ef\u80fd\u9700\u8981\u5c1d\u8bd5\u4e00\u4e0b MySQLi, \u56e0\u4e3a PDO \u4e3a\u4e86\u80fd\u591f\u540c\u65f6\u5728\u591a\u79cd\u6570\u636e\u5e93\u4e0a\u4f7f\u7528\uff0c\u4e0d\u4f1a\u5305\u542b\u90a3\u4e9b MySQL \u72ec\u6709\u7684\u529f\u80fd\u3002<\/p>\n<p>MySQLi \u662f MySQL \u7684\u589e\u5f3a\u63a5\u53e3\uff0c\u540c\u65f6\u63d0\u4f9b\u9762\u5411\u8fc7\u7a0b\u548c\u9762\u5411\u5bf9\u8c61\u63a5\u53e3\uff0c\u4e5f\u662f\u76ee\u524d\u63a8\u8350\u7684 MySQL \u9a71\u52a8\uff0c\u65e7\u7684C\u98ce\u683c MySQL \u63a5\u53e3\u5c06\u4f1a\u5728\u4eca\u540e\u88ab\u9ed8\u8ba4\u5173\u95ed\u3002<br \/>\nMySQLi \u7684\u7528\u6cd5\u548c\u4ee5\u4e0a\u4e24\u6bb5\u4ee3\u7801\u76f8\u6bd4\uff0c\u6ca1\u6709\u592a\u591a\u65b0\u6982\u5ff5\uff0c\u5728\u6b64\u4e0d\u518d\u7ed9\u51fa\u793a\u4f8b\uff0c\u53ef\u4ee5\u53c2\u89c1 PHP \u5b98\u7f51\u6587\u6863 [\u6ce8]\u3002<\/p>\n<p>\u6ce8\uff1a<a href=\"http:\/\/www.php.net\/manual\/en\/mysqli.quickstart.php\" target=\"_blank\" rel=\"nofollow\">http:\/\/www.php.net\/manual\/en\/mysqli.quickstart.php<\/a><\/p>\n<h3 id=\"articleHeader3\">\u7c7b\u578b\u7ea6\u675f<\/h3>\n<p>\u901a\u8fc7\u7c7b\u578b\u7ea6\u675f\u53ef\u4ee5\u9650\u5236\u53c2\u6570\u7684\u7c7b\u578b\uff0c\u4e0d\u8fc7\u8fd9\u4e00\u673a\u5236\u5e76\u4e0d\u5b8c\u5584\uff0c\u76ee\u524d\u4ec5\u9002\u7528\u4e8e\u7c7b\u548c callable(\u53ef\u6267\u884c\u7c7b\u578b) \u4ee5\u53ca array(\u6570\u7ec4), \u4e0d\u9002\u7528\u4e8e string \u548c int.<\/p>\n<pre class=\"hljs php\"><code>\/\/ \u9650\u5236\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a MyClass, \u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a\u53ef\u6267\u884c\u7c7b\u578b\uff0c\u7b2c\u4e09\u4e2a\u53c2\u6570\u4e3a\u6570\u7ec4\r\nfunction MyFunction(MyClass $a, callable $b, array $c)\r\n{\r\n    \/\/ ...\r\n}\r\n<\/code><\/pre>\n<h2 id=\"articleHeader4\">PHP5.2<\/h2>\n<p>(2006-2011)<\/p>\n<h3 id=\"articleHeader5\">JSON \u652f\u6301<\/h3>\n<p>\u5305\u62ec json_encode(), json_decode() \u7b49\u51fd\u6570\uff0cJSON \u7b97\u662f\u5728 Web \u9886\u57df\u975e\u5e38\u5e38\u7528\u7684\u6570\u636e\u4ea4\u6362\u683c\u5f0f\uff0c\u53ef\u4ee5\u88ab JS \u76f4\u63a5\u652f\u6301\uff0cJSON \u5b9e\u9645\u4e0a\u662f JS \u8bed\u6cd5\u7684\u4e00\u90e8\u5206\u3002<br \/>\nJSON \u7cfb\u5217\u51fd\u6570\uff0c\u53ef\u4ee5\u5c06 PHP \u4e2d\u7684\u6570\u7ec4\u7ed3\u6784\u4e0e JSON \u5b57\u7b26\u4e32\u8fdb\u884c\u8f6c\u6362\uff1a<\/p>\n<pre class=\"hljs bash\"><code>$array= [ \"key\"=&gt;  \"value\",  \"array\"=&gt; [1, 2, 3, 4]];\r\n$json= json_encode($array);\r\necho \"{$json}\\n\";\r\n\r\n$object= json_decode($json);\r\nprint_r($object);\r\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre class=\"hljs php\"><code>{ \"key\": \"value\", \"array\":[1,2,3,4]}\r\nstdClass Object\r\n(\r\n    [key] =&gt; value\r\n    [array] =&gt; Array\r\n        (\r\n            [0] =&gt; 1\r\n            [1] =&gt; 2\r\n            [2] =&gt; 3\r\n            [3] =&gt; 4\r\n        )\r\n)\r\n<\/code><\/pre>\n<p>\u503c\u5f97\u6ce8\u610f\u7684\u662f json_decode() \u9ed8\u8ba4\u4f1a\u8fd4\u56de\u4e00\u4e2a\u5bf9\u8c61\u800c\u975e\u6570\u7ec4\uff0c\u5982\u679c\u9700\u8981\u8fd4\u56de\u6570\u7ec4\u9700\u8981\u5c06\u7b2c\u4e8c\u4e2a\u53c2\u6570\u8bbe\u7f6e\u4e3a true.<\/p>\n<h2 id=\"articleHeader6\">PHP5.3<\/h2>\n<p>(2009-2012)<\/p>\n<p>PHP5.3 \u7b97\u662f\u4e00\u4e2a\u975e\u5e38\u5927\u7684\u66f4\u65b0\uff0c\u65b0\u589e\u4e86\u5927\u91cf\u65b0\u7279\u5f81\uff0c\u540c\u65f6\u4e5f\u505a\u4e86\u4e00\u4e9b\u4e0d\u5411\u4e0b\u517c\u5bb9\u7684\u4fee\u6539\u3002<\/p>\n<h3 id=\"articleHeader7\">\u5f03\u7528\u7684\u529f\u80fd<\/h3>\n<p>\u4ee5\u4e0b\u51e0\u4e2a\u529f\u80fd\u88ab\u5f03\u7528\uff0c\u82e5\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u542f\u7528\uff0c\u5219 PHP \u4f1a\u5728\u8fd0\u884c\u65f6\u53d1\u51fa\u8b66\u544a\u3002<\/p>\n<h4>Register Globals<\/h4>\n<p>\u8fd9\u662f php.ini \u4e2d\u7684\u4e00\u4e2a\u9009\u9879(register_globals), \u5f00\u542f\u540e\u4f1a\u5c06\u6240\u6709\u8868\u5355\u53d8\u91cf($_GET\u548c$_POST)\u6ce8\u518c\u4e3a\u5168\u5c40\u53d8\u91cf.<br \/>\n\u770b\u4e0b\u9762\u7684\u4f8b\u5b50\uff1a<\/p>\n<pre class=\"hljs ruby\"><code>if(isAuth())\r\n    $authorized= true;\r\nif($authorized)\r\n    include( \"page.php\");\r\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5728\u901a\u8fc7\u9a8c\u8bc1\u65f6\uff0c\u5c06 $authorized \u8bbe\u7f6e\u4e3a true. \u7136\u540e\u6839\u636e $authorized \u7684\u503c\u6765\u51b3\u5b9a\u662f\u5426\u663e\u793a\u9875\u9762.<\/p>\n<p>\u4f46\u7531\u4e8e\u5e76\u6ca1\u6709\u4e8b\u5148\u628a $authorized \u521d\u59cb\u5316\u4e3a false, \u5f53 register_globals \u6253\u5f00\u65f6\uff0c\u53ef\u80fd\u8bbf\u95ee \/auth.php?authorized=1 \u6765\u5b9a\u4e49\u8be5\u53d8\u91cf\u503c\uff0c\u7ed5\u8fc7\u8eab\u4efd\u9a8c\u8bc1\u3002<\/p>\n<p>\u8be5\u7279\u5f81\u5c5e\u4e8e\u5386\u53f2\u9057\u7559\u95ee\u9898\uff0c\u5728 PHP4.2 \u4e2d\u88ab\u9ed8\u8ba4\u5173\u95ed\uff0c\u5728 PHP5.4 \u4e2d\u88ab\u79fb\u9664\u3002<\/p>\n<h4>Magic Quotes<\/h4>\n<p>\u5bf9\u5e94 php.ini \u4e2d\u7684\u9009\u9879 magic_quotes_gpc, \u8fd9\u4e2a\u7279\u5f81\u540c\u6837\u5c5e\u4e8e\u5386\u53f2\u9057\u7559\u95ee\u9898\uff0c\u5df2\u7ecf\u5728 PHP5.4 \u4e2d\u79fb\u9664\u3002<\/p>\n<p>\u8be5\u7279\u5f81\u4f1a\u5c06\u6240\u6709\u7528\u6237\u8f93\u5165\u8fdb\u884c\u8f6c\u4e49\uff0c\u8fd9\u770b\u4e0a\u53bb\u4e0d\u9519\uff0c\u5728\u7b2c\u4e00\u7ae0\u6211\u4eec\u63d0\u5230\u8fc7\u8981\u5bf9\u7528\u6237\u8f93\u5165\u8fdb\u884c\u8f6c\u4e49\u3002<br \/>\n\u4f46\u662f PHP \u5e76\u4e0d\u77e5\u9053\u54ea\u4e9b\u8f93\u5165\u4f1a\u8fdb\u5165 SQL , \u54ea\u4e9b\u8f93\u5165\u4f1a\u8fdb\u5165 Shell, \u54ea\u4e9b\u8f93\u5165\u4f1a\u88ab\u663e\u793a\u4e3a HTML, \u6240\u4ee5\u5f88\u591a\u65f6\u5019\u8fd9\u79cd\u8f6c\u4e49\u4f1a\u5f15\u8d77\u6df7\u4e71\u3002<\/p>\n<h4>Safe Mode<\/h4>\n<p>\u5f88\u591a\u865a\u62df\u4e3b\u673a\u63d0\u4f9b\u5546\u4f7f\u7528 Safe Mode \u6765\u9694\u79bb\u591a\u4e2a\u7528\u6237\uff0c\u4f46 Safe Mode \u5b58\u5728\u8bf8\u591a\u95ee\u9898\uff0c\u4f8b\u5982\u67d0\u4e9b\u6269\u5c55\u5e76\u4e0d\u6309\u7167 Safe Mode \u6765\u8fdb\u884c\u6743\u9650\u63a7\u5236\u3002<br \/>\nPHP\u5b98\u65b9\u63a8\u8350\u4f7f\u7528\u64cd\u4f5c\u7cfb\u7edf\u7684\u673a\u5236\u6765\u8fdb\u884c\u6743\u9650\u9694\u79bb\uff0c\u8ba9Web\u670d\u52a1\u5668\u4ee5\u4e0d\u540c\u7684\u7528\u6237\u6743\u9650\u6765\u8fd0\u884cPHP\u89e3\u91ca\u5668\uff0c\u8bf7\u53c2\u89c1\u7b2c\u4e00\u7ae0\u4e2d\u7684<code>\u6700\u5c0f\u6743\u9650\u539f\u5219<\/code>.<\/p>\n<h3 id=\"articleHeader8\">\u533f\u540d\u51fd\u6570<\/h3>\n<p>\u4e5f\u53eb\u95ed\u5305(Closures), \u7ecf\u5e38\u88ab\u7528\u6765\u4e34\u65f6\u6027\u5730\u521b\u5efa\u4e00\u4e2a\u65e0\u540d\u51fd\u6570\uff0c\u7528\u4e8e\u56de\u8c03\u51fd\u6570\u7b49\u7528\u9014\u3002<\/p>\n<pre class=\"hljs php\"><code>$func = function($arg)\r\n{\r\n    print $arg;\r\n};\r\n\r\n$func( \"Hello World\");\r\n<\/code><\/pre>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u5b9a\u4e49\u4e86\u4e00\u4e2a\u533f\u540d\u51fd\u6570\uff0c\u5e76\u8d4b\u503c\u7ed9\u4e86 $func.<br \/>\n\u53ef\u4ee5\u770b\u5230\u5b9a\u4e49\u533f\u540d\u51fd\u6570\u4f9d\u65e7\u4f7f\u7528 function \u5173\u952e\u5b57\uff0c\u53ea\u4e0d\u8fc7\u7701\u7565\u4e86\u51fd\u6570\u540d\uff0c\u76f4\u63a5\u662f\u53c2\u6570\u5217\u8868\u3002<\/p>\n<p>\u7136\u540e\u6211\u4eec\u53c8\u8c03\u7528\u4e86 $func \u6240\u50a8\u5b58\u7684\u533f\u540d\u51fd\u6570\u3002<\/p>\n<p>\u533f\u540d\u51fd\u6570\u8fd8\u53ef\u4ee5\u7528 use \u5173\u952e\u5b57\u6765\u6355\u6349\u5916\u90e8\u53d8\u91cf\uff1a<\/p>\n<pre class=\"hljs php\"><code>function arrayPlus ($array, $num)\r\n{\r\n    array_walk($array, function (&amp;$v)use ($num){\r\n        $v+= $num;\r\n    });\r\n}\r\n<\/code><\/pre>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u5b9a\u4e49\u4e86\u4e00\u4e2a arrayPlus() \u51fd\u6570(\u8fd9\u4e0d\u662f\u533f\u540d\u51fd\u6570), \u5b83\u4f1a\u5c06\u4e00\u4e2a\u6570\u7ec4($array)\u4e2d\u7684\u6bcf\u4e00\u9879\uff0c\u52a0\u4e0a\u4e00\u4e2a\u6307\u5b9a\u7684\u6570\u5b57($num).<\/p>\n<p>\u5728 arrayPlus() \u7684\u5b9e\u73b0\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86 array_walk() \u51fd\u6570\uff0c\u5b83\u4f1a\u4e3a\u4e00\u4e2a\u6570\u7ec4\u7684\u6bcf\u4e00\u9879\u6267\u884c\u4e00\u4e2a\u56de\u8c03\u51fd\u6570\uff0c\u5373\u6211\u4eec\u5b9a\u4e49\u7684\u533f\u540d\u51fd\u6570\u3002<br \/>\n\u5728\u533f\u540d\u51fd\u6570\u7684\u53c2\u6570\u5217\u8868\u540e\uff0c\u6211\u4eec\u7528 use \u5173\u952e\u5b57\u5c06\u533f\u540d\u51fd\u6570\u5916\u7684 $num \u6355\u6349\u5230\u4e86\u51fd\u6570\u5185\uff0c\u4ee5\u4fbf\u77e5\u9053\u5230\u5e95\u5e94\u8be5\u52a0\u4e0a\u591a\u5c11\u3002<\/p>\n<h3 id=\"articleHeader9\">\u9b54\u672f\u65b9\u6cd5\uff1a__invoke(), __callStatic()<\/h3>\n<p>PHP \u7684\u9762\u5411\u5bf9\u8c61\u4f53\u7cfb\u4e2d\uff0c\u63d0\u4f9b\u4e86\u82e5\u5e72\u201c\u9b54\u672f\u65b9\u6cd5\u201d\uff0c\u7528\u4e8e\u5b9e\u73b0\u7c7b\u4f3c\u5176\u4ed6\u8bed\u8a00\u4e2d\u7684\u201c\u91cd\u8f7d\u201d\uff0c\u5982\u5728\u8bbf\u95ee\u4e0d\u5b58\u5728\u7684\u5c5e\u6027\u3001\u65b9\u6cd5\u65f6\u89e6\u53d1\u67d0\u4e2a\u9b54\u672f\u65b9\u6cd5\u3002<\/p>\n<p>\u968f\u7740\u533f\u540d\u51fd\u6570\u7684\u52a0\u5165\uff0cPHP \u5f15\u5165\u4e86\u4e00\u4e2a\u65b0\u7684\u9b54\u672f\u65b9\u6cd5 __invoke().<br \/>\n\u8be5\u9b54\u672f\u65b9\u6cd5\u4f1a\u5728\u5c06\u4e00\u4e2a\u5bf9\u8c61\u4f5c\u4e3a\u51fd\u6570\u8c03\u7528\u65f6\u88ab\u8c03\u7528\uff1a<\/p>\n<pre class=\"hljs php\"><code>classA\r\n{\r\n    public function__invoke ($str)\r\n    {\r\n        print \"A::__invoke(): {$str}\";\r\n    }\r\n}\r\n\r\n$a= newA;\r\n$a( \"Hello World\");\r\n<\/code><\/pre>\n<p>\u8f93\u51fa\u6beb\u65e0\u7591\u95ee\u662f\uff1a<\/p>\n<pre class=\"hljs http\"><code>A::__invoke():  Hello World\r\n<\/code><\/pre>\n<p>__callStatic() \u5219\u4f1a\u5728\u8c03\u7528\u4e00\u4e2a\u4e0d\u5b58\u5728\u7684\u9759\u6001\u65b9\u6cd5\u65f6\u88ab\u8c03\u7528\u3002<\/p>\n<h3 id=\"articleHeader10\">\u547d\u540d\u7a7a\u95f4<\/h3>\n<p>PHP\u7684\u547d\u540d\u7a7a\u95f4\u6709\u7740\u524d\u65e0\u53e4\u4eba\u540e\u65e0\u6765\u8005\u7684\u65e0\u6bd4\u86cb\u75bc\u7684\u8bed\u6cd5\uff1a<\/p>\n<pre class=\"lang:php\"><code>&lt;?php\r\n\/\/ \u547d\u540d\u7a7a\u95f4\u7684\u5206\u9694\u7b26\u662f\u53cd\u659c\u6760\uff0c\u8be5\u58f0\u660e\u8bed\u53e5\u5fc5\u987b\u5728\u6587\u4ef6\u7b2c\u4e00\u884c\u3002\r\n\/\/ \u547d\u540d\u7a7a\u95f4\u4e2d\u53ef\u4ee5\u5305\u542b\u4efb\u610f\u4ee3\u7801\uff0c\u4f46\u53ea\u6709 **\u7c7b, \u51fd\u6570, \u5e38\u91cf** \u53d7\u547d\u540d\u7a7a\u95f4\u5f71\u54cd\u3002\r\nnamespace XXOO\\Test;\r\n\r\n\/\/ \u8be5\u7c7b\u7684\u5b8c\u6574\u9650\u5b9a\u540d\u662f \\XXOO\\Test\\A , \u5176\u4e2d\u7b2c\u4e00\u4e2a\u53cd\u659c\u6760\u8868\u793a\u5168\u5c40\u547d\u540d\u7a7a\u95f4\u3002\r\nclass A{}\r\n\r\n\/\/ \u4f60\u8fd8\u53ef\u4ee5\u5728\u5df2\u7ecf\u6587\u4ef6\u4e2d\u5b9a\u4e49\u7b2c\u4e8c\u4e2a\u547d\u540d\u7a7a\u95f4\uff0c\u63a5\u4e0b\u6765\u7684\u4ee3\u7801\u5c06\u90fd\u4f4d\u4e8e \\Other\\Test2 .\r\nnamespaceOther\\Test2;\r\n\r\n\/\/ \u5b9e\u4f8b\u5316\u6765\u81ea\u5176\u4ed6\u547d\u540d\u7a7a\u95f4\u7684\u5bf9\u8c61\uff1a\r\n$a= new\\XXOO\\Test\\A;\r\nclass B{}\r\n\r\n\/\/ \u4f60\u8fd8\u53ef\u4ee5\u7528\u82b1\u62ec\u53f7\u5b9a\u4e49\u7b2c\u4e09\u4e2a\u547d\u540d\u7a7a\u95f4\r\nnamespace Other{\r\n    \/\/ \u5b9e\u4f8b\u5316\u6765\u81ea\u5b50\u547d\u540d\u7a7a\u95f4\u7684\u5bf9\u8c61\uff1a\r\n    $b= newTest2\\B;\r\n\r\n    \/\/ \u5bfc\u5165\u6765\u81ea\u5176\u4ed6\u547d\u540d\u7a7a\u95f4\u7684\u540d\u79f0\uff0c\u5e76\u91cd\u547d\u540d\uff0c\r\n    \/\/ \u6ce8\u610f\u53ea\u80fd\u5bfc\u5165\u7c7b\uff0c\u4e0d\u80fd\u7528\u4e8e\u51fd\u6570\u548c\u5e38\u91cf\u3002\r\n    use\\XXOO\\Test\\AasClassA\r\n}\r\n<\/code><\/pre>\n<p>\u66f4\u591a\u6709\u5173\u547d\u540d\u7a7a\u95f4\u7684\u8bed\u6cd5\u4ecb\u7ecd\u8bf7\u53c2\u89c1\u5b98\u7f51 [\u6ce8].<\/p>\n<p>\u547d\u540d\u7a7a\u95f4\u65f6\u5e38\u548c autoload \u4e00\u540c\u4f7f\u7528\uff0c\u7528\u4e8e\u81ea\u52a8\u52a0\u8f7d\u7c7b\u5b9e\u73b0\u6587\u4ef6\uff1a<\/p>\n<pre class=\"hljs coffeescript\"><code>spl_autoload_register(\r\n    function($class) {\r\n        spl_autoload(str_replace( \"\\\\\",  \"\/\", $class));\r\n    }\r\n);\r\n<\/code><\/pre>\n<p>\u5f53\u4f60\u5b9e\u4f8b\u5316\u4e00\u4e2a\u7c7b \\XXOO\\Test\\A \u7684\u65f6\u5019\uff0c\u8fd9\u4e2a\u7c7b\u7684\u5b8c\u6574\u9650\u5b9a\u540d\u4f1a\u88ab\u4f20\u9012\u7ed9 autoload \u51fd\u6570\uff0cautoload \u51fd\u6570\u5c06\u7c7b\u540d\u4e2d\u7684\u547d\u540d\u7a7a\u95f4\u5206\u9694\u7b26(\u53cd\u659c\u6760)\u66ff\u6362\u4e3a\u659c\u6760\uff0c\u5e76\u5305\u542b\u5bf9\u5e94\u6587\u4ef6\u3002<br \/>\n\u8fd9\u6837\u53ef\u4ee5\u5b9e\u73b0\u7c7b\u5b9a\u4e49\u6587\u4ef6\u5206\u7ea7\u50a8\u5b58\uff0c\u6309\u9700\u81ea\u52a8\u52a0\u8f7d\u3002<\/p>\n<p>\u6ce8\uff1a<a href=\"http:\/\/www.php.net\/manual\/zh\/language.namespaces.php\" target=\"_blank\" rel=\"nofollow\">http:\/\/www.php.net\/manual\/zh\/language.namespaces.php<\/a><\/p>\n<h3 id=\"articleHeader11\">\u540e\u671f\u9759\u6001\u7ed1\u5b9a<\/h3>\n<p>PHP \u7684 OPP \u673a\u5236\uff0c\u5177\u6709\u7ee7\u627f\u548c\u7c7b\u4f3c\u865a\u51fd\u6570\u7684\u529f\u80fd\uff0c\u4f8b\u5982\u5982\u4e0b\u7684\u4ee3\u7801\uff1a<\/p>\n<pre class=\"hljs php\"><code>class A\r\n{\r\n    public function callFuncXXOO ()\r\n    {\r\n        print$this-&gt;funcXXOO();\r\n    }\r\n\r\n    public function funcXXOO ()\r\n    {\r\n        return \"A::funcXXOO()\";\r\n    }\r\n}\r\n\r\nclass B extends A\r\n{\r\n    public function funcXXOO ()\r\n    {\r\n        return \"B::funcXXOO\";\r\n    }\r\n}\r\n\r\n$b= newB;\r\n$b-&gt;callFuncXXOO();\r\n<\/code><\/pre>\n<p>\u8f93\u51fa\u662f\uff1a<\/p>\n<pre class=\"hljs cpp\"><code>B::funcXXOO\r\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5f53\u5728 A \u4e2d\u4f7f\u7528 <code>$this-&gt;funcXXOO()<\/code> \u65f6\uff0c\u4f53\u73b0\u4e86\u201c\u865a\u51fd\u6570\u201d\u7684\u673a\u5236\uff0c\u5b9e\u9645\u8c03\u7528\u7684\u662f <code>B::funcXXOO()<\/code>.<br \/>\n\u7136\u800c\u5982\u679c\u5c06\u6240\u6709\u51fd\u6570\u90fd\u6539\u4e3a\u9759\u6001\u51fd\u6570\uff1a<\/p>\n<pre class=\"hljs php\"><code>class A\r\n{\r\n    static public function callFuncXXOO ()\r\n    {\r\n        print self::funcXXOO();\r\n    }\r\n\r\n    static public functionfuncXXOO ()\r\n    {\r\n        return \"A::funcXXOO()\";\r\n    }\r\n}\r\n\r\nclass B extends A\r\n{\r\n    static public function funcXXOO ()\r\n    {\r\n        return \"B::funcXXOO\";\r\n    }\r\n}\r\n\r\n$b= newB;\r\n$b-&gt;callFuncXXOO();\r\n<\/code><\/pre>\n<p>\u60c5\u51b5\u5c31\u6ca1\u8fd9\u4e48\u4e50\u89c2\u4e86\uff0c\u8f93\u51fa\u662f\uff1a<\/p>\n<pre class=\"hljs cpp\"><code>A::funcXXOO()\r\n<\/code><\/pre>\n<p>\u8fd9\u662f\u56e0\u4e3a self \u7684\u8bed\u4e49\u672c\u6765\u5c31\u662f\u201c\u5f53\u524d\u7c7b\u201d\uff0c\u6240\u4ee5 PHP5.3 \u7ed9 static \u5173\u952e\u5b57\u8d4b\u4e88\u4e86\u4e00\u4e2a\u65b0\u529f\u80fd\uff1a\u540e\u671f\u9759\u6001\u7ed1\u5b9a\uff1a<\/p>\n<pre class=\"hljs php\"><code>classA\r\n{\r\n    static public function callFuncXXOO ()\r\n    {\r\n        print static::funcXXOO();\r\n    }\r\n\r\n    \/\/ ...\r\n}\r\n\r\n\/\/ ...\r\n<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u4f1a\u50cf\u9884\u671f\u4e00\u6837\u8f93\u51fa\u4e86\uff1a<\/p>\n<pre class=\"hljs cpp\"><code>B::funcXXOO\r\n<\/code><\/pre>\n<h3 id=\"articleHeader12\">Heredoc \u548c Nowdoc<\/h3>\n<p>PHP5.3 \u5bf9 Heredoc \u4ee5\u53ca Nowdoc \u8fdb\u884c\u4e86\u4e00\u4e9b\u6539\u8fdb\uff0c\u5b83\u4eec\u90fd\u7528\u4e8e\u5728 PHP \u4ee3\u7801\u4e2d\u5d4c\u5165\u5927\u6bb5\u5b57\u7b26\u4e32\u3002<\/p>\n<p>Heredoc \u7684\u884c\u4e3a\u7c7b\u4f3c\u4e8e\u4e00\u4e2a\u53cc\u5f15\u53f7\u5b57\u7b26\u4e32\uff1a<\/p>\n<pre class=\"hljs bash\"><code>$name=  \"MyName\";\r\necho&lt;&lt;&lt; TEXT\r\nMy name is  \"{$name}\".\r\nTEXT;\r\n<\/code><\/pre>\n<p>Heredoc \u4ee5\u4e09\u4e2a\u5de6\u5c16\u62ec\u53f7\u5f00\u59cb\uff0c\u540e\u9762\u8ddf\u4e00\u4e2a\u6807\u8bc6\u7b26(TEXT), \u76f4\u5230\u4e00\u4e2a\u540c\u6837\u7684\u9876\u683c\u7684\u6807\u8bc6\u7b26(\u4e0d\u80fd\u7f29\u8fdb)\u7ed3\u675f\u3002<br \/>\n\u5c31\u50cf\u53cc\u5f15\u53f7\u5b57\u7b26\u4e32\u4e00\u6837\uff0c\u5176\u4e2d\u53ef\u4ee5\u5d4c\u5165\u53d8\u91cf\u3002<\/p>\n<p>Heredoc \u8fd8\u53ef\u4ee5\u7528\u4e8e\u51fd\u6570\u53c2\u6570\uff0c\u4ee5\u53ca\u7c7b\u6210\u5458\u521d\u59cb\u5316\uff1a<\/p>\n<pre class=\"hljs cs\"><code>var_dump(&lt;&lt;&lt;EOD\r\nHello World\r\nEOD\r\n);\r\n\r\nclassA\r\n{\r\n    constxx = &lt;&lt;&lt; EOD\r\nHello World\r\nEOD;\r\n\r\n    public$oo = &lt;&lt;&lt; EOD\r\nHello World\r\nEOD;\r\n}\r\n<\/code><\/pre>\n<p>Nowdoc \u7684\u884c\u4e3a\u50cf\u4e00\u4e2a\u5355\u5f15\u53f7\u5b57\u7b26\u4e32\uff0c\u4e0d\u80fd\u5728\u5176\u4e2d\u5d4c\u5165\u53d8\u91cf\uff0c\u548c Heredoc \u552f\u4e00\u7684\u533a\u522b\u5c31\u662f\uff0c\u4e09\u4e2a\u5de6\u5c16\u62ec\u53f7\u540e\u7684\u6807\u8bc6\u7b26\u8981\u4ee5\u5355\u5f15\u53f7\u62ec\u8d77\u6765\uff1a<\/p>\n<pre class=\"hljs bash\"><code>$name=  \"MyName\";\r\necho&lt;&lt;&lt;  'TEXT'\r\nMy name is  \"{$name}\".\r\nTEXT;\r\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre class=\"hljs nginx\"><code>Myname is  \"{$name}\".\r\n<\/code><\/pre>\n<h3 id=\"articleHeader13\">\u7528 const \u5b9a\u4e49\u5e38\u91cf<\/h3>\n<p>PHP5.3 \u8d77\u540c\u65f6\u652f\u6301\u5728\u5168\u5c40\u547d\u540d\u7a7a\u95f4\u548c\u7c7b\u4e2d\u4f7f\u7528 const \u5b9a\u4e49\u5e38\u91cf\u3002<\/p>\n<p>\u65e7\u5f0f\u98ce\u683c\uff1a<\/p>\n<pre class=\"hljs coffeescript\"><code>define( \"XOOO\",  \"Value\");\r\n<\/code><\/pre>\n<p>\u65b0\u5f0f\u98ce\u683c\uff1a<\/p>\n<pre class=\"hljs coffeescript\"><code>const XXOO =  \"Value\";\r\n<\/code><\/pre>\n<p>const \u5f62\u5f0f\u4ec5\u9002\u7528\u4e8e\u5e38\u91cf\uff0c\u4e0d\u9002\u7528\u4e8e\u8fd0\u884c\u65f6\u624d\u80fd\u6c42\u503c\u7684\u8868\u8fbe\u5f0f\uff1a<\/p>\n<pre class=\"hljs cs\"><code>\/\/ \u6b63\u786e\r\nconst XXOO = 1234;\r\n\/\/ \u9519\u8bef\r\nconst XXOO = 2* 617;\r\n<\/code><\/pre>\n<h3 id=\"articleHeader14\">\u4e09\u5143\u8fd0\u7b97\u7b26\u7b80\u5199\u5f62\u5f0f<\/h3>\n<p>\u65e7\u5f0f\u98ce\u683c\uff1a<\/p>\n<pre class=\"hljs nginx\"><code>echo $a? $a:  \"No Value\";\r\n<\/code><\/pre>\n<p>\u53ef\u7b80\u5199\u6210\uff1a<\/p>\n<pre class=\"hljs nginx\"><code>echo $a?:\"No Value\";\r\n<\/code><\/pre>\n<p>\u5373\u5982\u679c\u7701\u7565\u4e09\u5143\u8fd0\u7b97\u7b26\u7684\u7b2c\u4e8c\u4e2a\u90e8\u5206\uff0c\u4f1a\u9ed8\u8ba4\u7528\u7b2c\u4e00\u4e2a\u90e8\u5206\u4ee3\u66ff\u3002<\/p>\n<h3 id=\"articleHeader15\">Phar<\/h3>\n<p>Phar\u5373PHP Archive, \u8d77\u521d\u53ea\u662fPear\u4e2d\u7684\u4e00\u4e2a\u5e93\u800c\u5df2\uff0c\u540e\u6765\u5728PHP5.3\u88ab\u91cd\u65b0\u7f16\u5199\u6210C\u6269\u5c55\u5e76\u5185\u7f6e\u5230 PHP \u4e2d\u3002<br \/>\nPhar\u7528\u6765\u5c06\u591a\u4e2a .php \u811a\u672c\u6253\u5305(\u4e5f\u53ef\u4ee5\u6253\u5305\u5176\u4ed6\u6587\u4ef6)\u6210\u4e00\u4e2a .phar \u7684\u538b\u7f29\u6587\u4ef6(\u901a\u5e38\u662fZIP\u683c\u5f0f)\u3002<br \/>\n\u76ee\u7684\u5728\u4e8e\u6a21\u4eff Java \u7684 .jar, \u4e0d\u5bf9\uff0c\u76ee\u7684\u662f\u4e3a\u4e86\u8ba9\u53d1\u5e03PHP\u5e94\u7528\u7a0b\u5e8f\u66f4\u52a0\u65b9\u4fbf\u3002\u540c\u65f6\u8fd8\u63d0\u4f9b\u4e86\u6570\u5b57\u7b7e\u540d\u9a8c\u8bc1\u7b49\u529f\u80fd\u3002<\/p>\n<p>.phar \u6587\u4ef6\u53ef\u4ee5\u50cf .php \u6587\u4ef6\u4e00\u6837\uff0c\u88abPHP\u5f15\u64ce\u89e3\u91ca\u6267\u884c\uff0c\u540c\u65f6\u4f60\u8fd8\u53ef\u4ee5\u5199\u51fa\u8fd9\u6837\u7684\u4ee3\u7801\u6765\u5305\u542b(require) .phar \u4e2d\u7684\u4ee3\u7801\uff1a<\/p>\n<pre class=\"hljs coffeescript\"><code>require( \"xxoo.phar\");\r\nrequire( \"phar:\/\/xxoo.phar\/xo\/ox.php\");\r\n<\/code><\/pre>\n<p>\u66f4\u591a\u4fe1\u606f\u8bf7\u53c2\u89c1\u5b98\u7f51 [\u6ce8].<\/p>\n<p>\u6ce8\uff1a<a href=\"http:\/\/www.php.net\/manual\/zh\/phar.using.intro.php\" target=\"_blank\" rel=\"nofollow\">http:\/\/www.php.net\/manual\/zh\/phar.using.intro.php<\/a><\/p>\n<h2 id=\"articleHeader16\">PHP5.4<\/h2>\n<p>(2012-2013)<\/p>\n<h2 id=\"articleHeader17\">Short Open Tag<\/h2>\n<p>Short Open Tag \u81ea PHP5.4 \u8d77\u603b\u662f\u53ef\u7528\u3002<br \/>\n\u5728\u8fd9\u91cc\u96c6\u4e2d\u8bb2\u4e00\u4e0b\u6709\u5173 PHP \u8d77\u6b62\u6807\u7b7e\u7684\u95ee\u9898\u3002\u5373\uff1a<\/p>\n<pre class=\"lang:php\"><code>&lt;?php\r\n\/\/ Code...\r\n?&gt;\r\n<\/code><\/pre>\n<p>\u901a\u5e38\u5c31\u662f\u4e0a\u9762\u7684\u5f62\u5f0f\uff0c\u9664\u6b64\u4e4b\u5916\u8fd8\u6709\u4e00\u79cd\u7b80\u5199\u5f62\u5f0f\uff1a<\/p>\n<pre class=\"lang:php\"><code>&lt;?\/* Code... *\/?&gt;\r\n<\/code><\/pre>\n<p>\u8fd8\u53ef\u4ee5\u628a<\/p>\n<pre class=\"lang:php\"><code>&lt;?phpecho$xxoo;?&gt;\r\n<\/code><\/pre>\n<p>\u7b80\u5199\u6210\uff1a<\/p>\n<pre class=\"lang:php\"><code>&lt;?= $xxoo;?&gt;\r\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u7b80\u5199\u5f62\u5f0f\u88ab\u79f0\u4e3a Short Open Tag, \u5728 PHP5.3 \u8d77\u88ab\u9ed8\u8ba4\u5f00\u542f\uff0c\u5728 PHP5.4 \u8d77\u603b\u662f\u53ef\u7528\u3002<br \/>\n\u4f7f\u7528\u8fd9\u79cd\u7b80\u5199\u5f62\u5f0f\u5728 HTML \u4e2d\u5d4c\u5165 PHP \u53d8\u91cf\u5c06\u4f1a\u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n<p>\u5bf9\u4e8e\u7eaf PHP \u6587\u4ef6(\u5982\u7c7b\u5b9e\u73b0\u6587\u4ef6), PHP \u5b98\u65b9\u5efa\u8bae\u9876\u683c\u5199\u8d77\u59cb\u6807\u8bb0\uff0c\u540c\u65f6 <strong>\u7701\u7565<\/strong> \u7ed3\u675f\u6807\u8bb0\u3002<br \/>\n\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u6574\u4e2a PHP \u6587\u4ef6\u90fd\u662f PHP \u4ee3\u7801\uff0c\u6ca1\u6709\u4efb\u4f55\u8f93\u51fa\uff0c\u5426\u5219\u5f53\u4f60\u5305\u542b\u8be5\u6587\u4ef6\u540e\uff0c\u8bbe\u7f6e Header \u548c Cookie \u65f6\u4f1a\u9047\u5230\u4e00\u4e9b\u9ebb\u70e6 [\u6ce8].<\/p>\n<p>\u6ce8\uff1aHeader \u548c Cookie \u5fc5\u987b\u5728\u8f93\u51fa\u4efb\u4f55\u5185\u5bb9\u4e4b\u524d\u88ab\u53d1\u9001\u3002<\/p>\n<h3 id=\"articleHeader18\">\u6570\u7ec4\u7b80\u5199\u5f62\u5f0f<\/h3>\n<p>\u8fd9\u662f\u975e\u5e38\u65b9\u4fbf\u7684\u4e00\u9879\u7279\u5f81\uff01<\/p>\n<pre class=\"hljs php\"><code>\/\/ \u539f\u6765\u7684\u6570\u7ec4\u5199\u6cd5\r\n$arr= array( \"key\"=&gt;  \"value\",  \"key2\"=&gt;  \"value2\");\r\n\/\/ \u7b80\u5199\u5f62\u5f0f\r\n$arr= [ \"key\"=&gt;  \"value\",  \"key2\"=&gt;  \"value2\"];\r\n<\/code><\/pre>\n<h3 id=\"articleHeader19\">Traits<\/h3>\n<p>\u6240\u8c13Traits\u5c31\u662f\u201c\u6784\u4ef6\u201d\uff0c\u662f\u7528\u6765\u66ff\u4ee3\u7ee7\u627f\u7684\u4e00\u79cd\u673a\u5236\u3002PHP\u4e2d\u65e0\u6cd5\u8fdb\u884c\u591a\u91cd\u7ee7\u627f\uff0c\u4f46\u4e00\u4e2a\u7c7b\u53ef\u4ee5\u5305\u542b\u591a\u4e2aTraits.<\/p>\n<pre class=\"hljs php\"><code>\/\/ Traits\u4e0d\u80fd\u88ab\u5355\u72ec\u5b9e\u4f8b\u5316\uff0c\u53ea\u80fd\u88ab\u7c7b\u6240\u5305\u542b\r\ntrait SayWorld\r\n{\r\n    public function sayHello ()\r\n    {\r\n        echo 'World!';\r\n    }\r\n}\r\n\r\nclass MyHelloWorld\r\n{\r\n    \/\/ \u5c06SayWorld\u4e2d\u7684\u6210\u5458\u5305\u542b\u8fdb\u6765\r\n    use SayWorld;\r\n}\r\n\r\n$xxoo= new MyHelloWorld();\r\n\/\/ sayHello() \u51fd\u6570\u662f\u6765\u81ea SayWorld \u6784\u4ef6\u7684\r\n$xxoo-&gt;sayHello();\r\n<\/code><\/pre>\n<p>Traits\u8fd8\u6709\u5f88\u591a\u795e\u5947\u7684\u529f\u80fd\uff0c\u6bd4\u5982\u5305\u542b\u591a\u4e2aTraits, \u89e3\u51b3\u51b2\u7a81\uff0c\u4fee\u6539\u8bbf\u95ee\u6743\u9650\uff0c\u4e3a\u51fd\u6570\u8bbe\u7f6e\u522b\u540d\u7b49\u7b49\u3002<br \/>\nTraits\u4e2d\u4e5f\u540c\u6837\u53ef\u4ee5\u5305\u542bTraits. \u7bc7\u5e45\u6709\u9650\u4e0d\u80fd\u9010\u4e2a\u4e3e\u4f8b\uff0c\u8be6\u60c5\u53c2\u89c1\u5b98\u7f51 [\u6ce8].<\/p>\n<p>\u6ce8\uff1a<a href=\"http:\/\/www.php.net\/manual\/zh\/language.oop5.traits.php\" target=\"_blank\" rel=\"nofollow\">http:\/\/www.php.net\/manual\/zh\/language.oop5.traits.php<\/a><\/p>\n<h3 id=\"articleHeader20\">\u5185\u7f6e Web \u670d\u52a1\u5668<\/h3>\n<p>PHP\u4ece5.4\u5f00\u59cb\u5185\u7f6e\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684Web\u670d\u52a1\u5668\uff0c\u4e0d\u652f\u6301\u5e76\u53d1\uff0c\u5b9a\u4f4d\u662f\u7528\u4e8e\u5f00\u53d1\u548c\u8c03\u8bd5\u73af\u5883\u3002<\/p>\n<p>\u5728\u5f00\u53d1\u73af\u5883\u4f7f\u7528\u5b83\u7684\u786e\u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n<pre class=\"hljs nginx\"><code>php -S localhost:8000\r\n<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u5728\u5f53\u524d\u76ee\u5f55\u5efa\u7acb\u8d77\u4e86\u4e00\u4e2aWeb\u670d\u52a1\u5668\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7 <a href=\"http:\/\/localhost:8000\/\" target=\"_blank\" rel=\"nofollow\">http:\/\/localhost:8000\/<\/a> \u6765\u8bbf\u95ee\u3002<br \/>\n\u5176\u4e2dlocalhost\u662f\u76d1\u542c\u7684ip\uff0c8000\u662f\u76d1\u542c\u7684\u7aef\u53e3\uff0c\u53ef\u4ee5\u81ea\u884c\u4fee\u6539\u3002<\/p>\n<p>\u5f88\u591a\u5e94\u7528\u4e2d\uff0c\u90fd\u4f1a\u8fdb\u884cURL\u91cd\u5199\uff0c\u6240\u4ee5PHP\u63d0\u4f9b\u4e86\u4e00\u4e2a\u8bbe\u7f6e\u8def\u7531\u811a\u672c\u7684\u529f\u80fd:<\/p>\n<pre class=\"hljs nginx\"><code>php -S localhost:8000index.php\r\n<\/code><\/pre>\n<p>\u8fd9\u6837\u4e00\u6765\uff0c\u6240\u6709\u7684\u8bf7\u6c42\u90fd\u4f1a\u7531index.php\u6765\u5904\u7406\u3002<\/p>\n<p>\u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528 XDebug \u6765\u8fdb\u884c\u65ad\u70b9\u8c03\u8bd5\u3002<\/p>\n<h3 id=\"articleHeader21\">\u7ec6\u8282\u4fee\u6539<\/h3>\n<p>PHP5.4 \u65b0\u589e\u4e86\u52a8\u6001\u8bbf\u95ee\u9759\u6001\u65b9\u6cd5\u7684\u65b9\u5f0f\uff1a<\/p>\n<pre class=\"hljs bash\"><code>$func=  \"funcXXOO\";\r\nA::{$func}();\r\n<\/code><\/pre>\n<p>\u65b0\u589e\u5728\u5b9e\u4f8b\u5316\u65f6\u8bbf\u95ee\u7c7b\u6210\u5458\u7684\u7279\u5f81\uff1a<\/p>\n<pre class=\"hljs php\"><code>(newMyClass)-&gt;xxoo();\r\n<\/code><\/pre>\n<p>\u65b0\u589e\u652f\u6301\u5bf9\u51fd\u6570\u8fd4\u56de\u6570\u7ec4\u7684\u6210\u5458\u8bbf\u95ee\u89e3\u6790(\u8fd9\u79cd\u5199\u6cd5\u5728\u4e4b\u524d\u7248\u672c\u662f\u4f1a\u62a5\u9519\u7684)\uff1a<\/p>\n<pre class=\"hljs coffeescript\"><code>printfunc()[0];\r\n<\/code><\/pre>\n<h2 id=\"articleHeader22\">PHP5.5<\/h2>\n<p>(2013\u8d77)<\/p>\n<h3 id=\"articleHeader23\">yield<\/h3>\n<p>yield\u5173\u952e\u5b57\u7528\u4e8e\u5f53\u51fd\u6570\u9700\u8981\u8fd4\u56de\u4e00\u4e2a\u8fed\u4ee3\u5668\u7684\u65f6\u5019, \u9010\u4e2a\u8fd4\u56de\u503c\u3002<\/p>\n<pre class=\"hljs php\"><code> function number10 ()\r\n{\r\n    for($i= 1; $i&lt;= 10; $i+= 1)\r\n        yield $i;\r\n}\r\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u7684\u8fd4\u56de\u503c\u662f\u4e00\u4e2a\u6570\u7ec4\uff1a<\/p>\n<pre class=\"hljs json\"><code>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\r\n<\/code><\/pre>\n<h3 id=\"articleHeader24\">list() \u7528\u4e8e foreach<\/h3>\n<p>\u53ef\u4ee5\u7528 list() \u5728 foreach \u4e2d\u89e3\u6790\u5d4c\u5957\u7684\u6570\u7ec4\uff1a<\/p>\n<pre class=\"hljs bash\"><code>$array= [\r\n    [1, 2, 3],\r\n    [4, 5, 6],\r\n];\r\n\r\nforeach ($arrayas list($a, $b, $c))\r\n    echo \"{$a} {$b} {$c}\\n\";\r\n<\/code><\/pre>\n<p>\u7ed3\u679c\uff1a<\/p>\n<pre class=\"hljs\"><code>1 2 3\r\n4 5 6\r\n<\/code><\/pre>\n<h3 id=\"articleHeader25\">\u7ec6\u8282\u4fee\u6539<\/h3>\n<p>\u4e0d\u63a8\u8350\u4f7f\u7528 mysql \u51fd\u6570\uff0c\u63a8\u8350\u4f7f\u7528 PDO \u6216 MySQLi, \u53c2\u89c1\u524d\u6587\u3002<br \/>\n\u4e0d\u518d\u652f\u6301Windows XP.<\/p>\n<p>\u53ef\u7528 <code>MyClass::class<\/code> \u53d6\u5230\u4e00\u4e2a\u7c7b\u7684\u5b8c\u6574\u9650\u5b9a\u540d(\u5305\u62ec\u547d\u540d\u7a7a\u95f4)\u3002<\/p>\n<p>empty() \u652f\u6301\u8868\u8fbe\u5f0f\u4f5c\u4e3a\u53c2\u6570\u3002<\/p>\n<p>try-catch \u7ed3\u6784\u65b0\u589e finally \u5757\u3002<\/p>\n<h2 id=\"articleHeader26\">PHP5.6<\/h2>\n<h3 id=\"articleHeader27\">\u66f4\u597d\u7684\u5e38\u91cf<\/h3>\n<p>\u5b9a\u4e49\u5e38\u91cf\u65f6\u5141\u8bb8\u4f7f\u7528\u4e4b\u524d\u5b9a\u4e49\u7684\u5e38\u91cf\u8fdb\u884c\u8ba1\u7b97\uff1a<\/p>\n<pre class=\"hljs php\"><code>const A = 2;\r\nconst B = A + 1;\r\n\r\nclass C\r\n{\r\n    const STR =  \"hello\";\r\n    const STR2 = self::STR +  \", world\";\r\n}\r\n<\/code><\/pre>\n<p>\u5141\u8bb8\u5e38\u91cf\u4f5c\u4e3a\u51fd\u6570\u53c2\u6570\u9ed8\u8ba4\u503c\uff1a<\/p>\n<pre class=\"hljs php\"><code>function func ($arg= C::STR2)\r\n<\/code><\/pre>\n<h3 id=\"articleHeader28\">\u66f4\u597d\u7684\u53ef\u53d8\u51fd\u6570\u53c2\u6570<\/h3>\n<p>\u7528\u4e8e\u4ee3\u66ff <code>func_get_args()<\/code><\/p>\n<pre class=\"hljs php\"><code>function add (...$args)\r\n{\r\n    $result= 0;\r\n    foreach($argsas$arg)\r\n        $result+= $arg;\r\n    return $result;\r\n}\r\n<\/code><\/pre>\n<p>\u540c\u65f6\u53ef\u4ee5\u5728\u8c03\u7528\u51fd\u6570\u65f6\uff0c\u628a\u6570\u7ec4\u5c55\u5f00\u4e3a\u51fd\u6570\u53c2\u6570\uff1a<\/p>\n<pre class=\"hljs ruby\"><code>$arr= [2, 3];\r\nadd(1, ...$arr);\r\n\/\/\u7ed3\u679c\u4e3a 6\r\n<\/code><\/pre>\n<h3 id=\"articleHeader29\">\u547d\u540d\u7a7a\u95f4<\/h3>\n<p>\u547d\u540d\u7a7a\u95f4\u652f\u6301\u5e38\u91cf\u548c\u51fd\u6570\uff1a<\/p>\n<pre class=\"hljs php\"><code>namespace Name\\Space{\r\n    const FOO= 42;\r\n     function f (){ echo__FUNCTION__. \"\\n\"; }\r\n}\r\n\r\nnamespace{\r\n    use const Name\\Space\\FOO;\r\n    use function Name\\Space\\f;\r\n\r\n    echo FOO. \"\\n\";\r\n    f();\r\n}\r\n<\/code><\/pre>\n<\/div>\n<p>\u672c\u6587\u8f6c\u8f7d\u81ea\uff1ahttp:\/\/segmentfault.com\/a\/1190000000403307<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u622a\u81f3\u76ee\u524d(2014.2), PHP \u7684\u6700\u65b0\u7a33\u5b9a\u7248\u672c\u662f PHP5.5, \u4f46\u6709\u5dee\u4e0d\u591a &#8230; <a class=\"more-link\" href=\"https:\/\/actom.me\/blog\/php-%e8%87%aa-5-2-%e5%88%b0-5-6-%e4%b8%ad%e6%96%b0%e5%a2%9e%e7%9a%84%e5%8a%9f%e8%83%bd%e8%af%a6%e8%a7%a3.html\">Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"_links":{"self":[{"href":"https:\/\/actom.me\/blog\/wp-json\/wp\/v2\/posts\/1183"}],"collection":[{"href":"https:\/\/actom.me\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actom.me\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actom.me\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actom.me\/blog\/wp-json\/wp\/v2\/comments?post=1183"}],"version-history":[{"count":4,"href":"https:\/\/actom.me\/blog\/wp-json\/wp\/v2\/posts\/1183\/revisions"}],"predecessor-version":[{"id":1188,"href":"https:\/\/actom.me\/blog\/wp-json\/wp\/v2\/posts\/1183\/revisions\/1188"}],"wp:attachment":[{"href":"https:\/\/actom.me\/blog\/wp-json\/wp\/v2\/media?parent=1183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actom.me\/blog\/wp-json\/wp\/v2\/categories?post=1183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actom.me\/blog\/wp-json\/wp\/v2\/tags?post=1183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}