{"id":16,"date":"2023-06-05T12:36:11","date_gmt":"2023-06-05T04:36:11","guid":{"rendered":"http:\/\/pro369.com\/php\/?p=16"},"modified":"2019-07-01T03:16:00","modified_gmt":"2019-07-01T03:16:00","slug":"%e5%be%9e-php-4-%e7%a7%bb%e6%a4%8d%e5%88%b0-php-5%e9%9c%80%e8%a6%81%e6%b3%a8%e6%84%8f%e7%9a%84%e4%ba%8b%e9%a0%85","status":"publish","type":"post","link":"https:\/\/por.tw\/php\/%e5%be%9e-php-4-%e7%a7%bb%e6%a4%8d%e5%88%b0-php-5%e9%9c%80%e8%a6%81%e6%b3%a8%e6%84%8f%e7%9a%84%e4%ba%8b%e9%a0%85\/","title":{"rendered":"\u5f9e PHP 4 \u79fb\u690d\u5230 PHP 5\u9700\u8981\u6ce8\u610f\u7684\u4e8b\u9805"},"content":{"rendered":"<p><strong style=\"background-color: #ffff00\">\u5f9e PHP 4 \u79fb\u690d\u5230 PHP 5\u9700\u8981\u6ce8\u610f\u7684\u4e8b\u9805<\/strong><\/p>\n<p> <font color=\"#008000\"><strong>\u5411\u5f8c\u4e0d\u76f8\u5bb9\u7684\u6539\u8b8a<\/strong><\/font><\/p>\n<p> <font color=\"#800080\"><strong>\u5118\u7ba1\u5927\u90e8\u5206 PHP 4 \u7684\u4ee3\u78bc\u61c9\u8a72\u4e0d\u7528\u4fee\u6539\u5c31\u80fd\u904b\u884c\uff0c\u9084\u662f\u61c9\u8a72\u7559\u610f\u4ee5\u4e0b\u5411\u5f8c\u4e0d\u76f8\u5bb9\u7684\u6539\u8b8a\uff1a<\/strong><\/font><\/p>\n<p> &nbsp;&nbsp;&nbsp; *<\/p>\n<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u6709\u4e86\u4e00\u4e9b\u65b0\u95dc\u9375\u5b57\u3002<br \/> &nbsp;&nbsp;&nbsp; *<\/p>\n<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strrpos() \u548c strripos() \u5982\u4eca\u4f7f\u7528\u6574\u500b\u5b57\u4e32\u4f5c\u70ba needle\u3002<br \/> &nbsp;&nbsp;&nbsp; *<\/p>\n<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u975e\u6cd5\u4f7f\u7528\u5b57\u4e32\u504f\u79fb\u91cf\u6703\u5c0e\u81f4 E_ERROR \u800c\u4e0d\u662f E_WARNING\u3002\u4e00\u500b\u975e\u6cd5\u4f7f\u7528\u7684\u4f8b\u5b50\uff1a$str = &#39;abc&#39;; unset($str[0]);.<br \/> &nbsp;&nbsp;&nbsp; *<\/p>\n<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; array_merge() \u88ab\u6539\u6210\u53ea\u63a5\u53d7\u9663\u5217\u3002\u82e5\u679c\u50b3\u905e\u5165\u975e\u9663\u5217\u8b8a\u91cf\uff0c\u5c0d\u6bcf\u500b\u6b64\u985e\u53c3\u6578\u90fd\u6703\u767c\u51fa\u4e00\u689d E_WARNING \u8a0a\u606f\u3002\u8981\u5c0f\u5fc3\u56e0\u70ba\u4f60\u7684\u4ee3\u78bc\u6709\u53ef\u80fd\u760b\u72c2\u767c\u51fa E_WARNING\u3002<br \/> &nbsp;&nbsp;&nbsp; *<\/p>\n<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PATH_TRANSLATED \u4f3a\u670d\u5668\u8b8a\u91cf\u5728 Apache2 SAPI \u4e2d\u4e0d\u518d\u6697\u4e2d\u8a2d\u5b9a\uff0c\u9019\u548c PHP 4 \u4e2d\u7684\u60c5\u5f62\u76f8\u53cd\uff0c\u82e5\u679c Apache \u6c92\u7522\u751f\u6b64\u503c\u5247\u5176\u88ab\u8a2d\u70ba\u548c SCRIPT_FILENAME \u4f3a\u670d\u5668\u8b8a\u91cf\u4e00\u6a23\u7684\u503c\u3002\u6b64\u4fee\u6539\u662f\u70ba\u4e86\u9075\u5b88 CGI \u898f\u7bc4\u3002\u66f4\u591a\u8a0a\u606f\u898b bug #23610\uff0c\u4e26\u53c3\u8003\u624b\u518a\u4e2d $_SERVER[&#39;PATH_TRANSLATED&#39;] \u7684\u8aaa\u660e\u3002\u6b64\u554f\u984c\u4e5f\u5f71\u97ff\u5230 PHP &gt;= 4.3.2 \u7684\u7248\u672c\u3002<br \/> &nbsp;&nbsp;&nbsp; *<\/p>\n<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tokenizer \u589e\u52a0\u4e0d\u518d\u5b9a\u7fa9 T_ML_COMMENT \u5e38\u91cf\u3002\u82e5\u679c\u628a error_reporting \u8a2d\u70ba E_ALL\uff0cPHP \u5c07\u7522\u751f\u4e00\u689d\u8a0a\u606f\u3002\u5118\u7ba1 T_ML_COMMENT \u5f9e\u4f86\u90fd\u6c92\u7528\u5230\u904e\uff0c\u9084\u662f\u5728 PHP 4 \u4e2d\u5b9a\u7fa9\u4e86\u3002\u5728 PHP 4 \u548c PHP 5 \u4e2d \/\/ \u548c \/* *\/ \u90fd\u88ab\u89e3\u6790\u70ba T_COMMENT \u5e38\u91cf\u3002\u4f46\u662f PHPDoc \u98a8\u683c\u7684\u6ce8\u89e3 \/** *\/\uff0c\u81ea PHP 5 \u958b\u59cb\u88ab PHP \u89e3\u6790\uff0c\u88ab\u8b58\u5225\u70ba T_DOC_COMMENT\u3002<br \/> &nbsp;&nbsp;&nbsp; *<\/p>\n<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u82e5\u679c variables_order \u5167\u542b\u300cS\u300d\uff0c$_SERVER \u61c9\u8a72\u5e36\u6709 argc \u548c argv \u88ab\u7522\u751f\u3002\u82e5\u679c\u6703\u54e1\u7279\u5225\u914d\u88fd\u7cfb\u7d71\u4e0d\u5efa\u7acb $_SERVER\uff0c\u90a3\u6b64\u8b8a\u91cf\u7576\u7136\u5c31\u4e0d\u5b58\u5728\u4e86\u3002\u6539\u8b8a\u7684\u5730\u65b9\u662f\u4e0d\u7ba1 variables_order \u600e\u9ebc\u8a2d\u5b9a\uff0c\u5728 CLI \u7248\u672c\u4e2d argc \u548c argv \u7e3d\u662f\u53ef\u7528\u7684\u3002\u672c\u4f86 CLI \u7248\u4e0d\u662f\u7e3d\u6703\u7522\u751f\u5168\u5c40\u8b8a\u91cf $argc \u548c $argv \u7684\u3002<br \/> &nbsp;&nbsp;&nbsp; *<\/p>\n<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u6c92\u6709\u5c6c\u6027\u7684\u5c0d\u8c61\u4e0d\u518d\u88ab\u7576\u6210\u300cempty\u300d\u3002<br \/> &nbsp;&nbsp;&nbsp; *<\/p>\n<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u6709\u4e9b\u60c5\u6cc1\u4e0b\u985e\u5fc5\u9808\u5728\u4f7f\u7528\u524d\u88ab\u5b9a\u7fa9\u3002\u9019\u50c5\u5728\u4f7f\u7528\u4e86\u4e00\u4e9b PHP 5 \u7684\u65b0\u7279\u6027\u7684\u6642\u5019\u767c\u751f\u3002\u5176\u5b83\u60c5\u6cc1\u4e0b\u884c\u70ba\u90fd\u6c92\u8b8a\u3002<br \/> &nbsp;&nbsp;&nbsp; *<\/p>\n<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get_class()\uff0cget_parent_class() \u548c get_class_methods() \u5982\u4eca\u8fd4\u56de\u7684\u985e\uff0f\u65b9\u6cd5\u540d\u548c\u5b9a\u7fa9\u6642\u7684\u540d\u5b57\u4e00\u81f4\uff08\u5340\u5206\u5927\u5c0f\u5beb\uff09\uff0c\u5c0d\u65bc\u4f9d\u8cf4\u4ee5\u524d\u884c\u70ba\uff08\u985e\uff0f\u65b9\u6cd5\u540d\u7e3d\u662f\u8fd4\u56de\u5c0f\u5beb\u7684\uff09\u7684\u8001\u8173\u672c\u53ef\u80fd\u7522\u751f\u554f\u984c\u3002\u4e00\u500b\u53ef\u80fd\u7684\u89e3\u6c7a\u65b9\u6cd5\u662f\u5728\u8173\u672c\u4e2d\u641c\u5c0b\u6240\u6709\u9019\u4e9b\u51fd\u6578\u4e26\u4f7f\u7528 strtolower()\u3002<\/p>\n<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u5340\u5206\u5927\u5c0f\u5beb\u7684\u6539\u8b8a\u4e5f\u9069\u7528\u65bc\u9b54\u8853\u5e38\u91cf __CLASS__\uff0c__METHOD__ \u548c __FUNCTION__\u3002\u5176\u503c\u90fd\u6703\u56b4\u683c\u6309\u7167\u5b9a\u7fa9\u6642\u7684\u540d\u5b57\u8fd4\u56de\uff08\u5340\u5206\u5927\u5c0f\u5beb\uff09\u3002<br \/> &nbsp;&nbsp;&nbsp; *<\/p>\n<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ip2long() \u5728\u50b3\u905e\u5165\u4e00\u500b\u975e\u6cd5 IP \u4f5c\u70ba\u53c3\u6578\u6642\u8fd4\u56de FALSE\uff0c\u4e0d\u518d\u662f -1\u3002<br \/> &nbsp;&nbsp;&nbsp; *<\/p>\n<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u82e5\u679c\u5728\u5305\u62ec\u6a94\u6848\u4e2d\u5b9a\u7fa9\u6709\u51fd\u6578\uff0c\u5247\u4e0d\u7ba1\u5728 return() \u4e4b\u524d\u9084\u662f\u4e4b\u5f8c\u90fd\u53ef\u4ee5\u5728\u4e3b\u6a94\u6848\u4e2d\u547c\u53eb\u3002\u82e5\u679c\u6a94\u6848\u88ab\u5305\u62ec\u5169\u6b21\uff0cPHP 5 \u6703\u767c\u51fa\u81f4\u547d\u932f\u8aa4\uff0c\u56e0\u70ba\u51fd\u6578\u5df2\u7d93\u88ab\u5b9a\u7fa9\uff0c\u800c PHP 4 \u4e0d\u7ba1\u9019\u500b\u3002\u56e0\u6b64\u63a8\u85a6\u4f7f\u7528 include_once() \u800c\u4e0d\u8981\u53bb\u6aa2\u67e5\u6a94\u6848\u662f\u5426\u5df2\u88ab\u5305\u62ec\u4ee5\u53ca\u5728\u5305\u62ec\u6a94\u6848\u4e2d\u6709\u689d\u4ef6\u8fd4\u56de\u3002<br \/> &nbsp;&nbsp;&nbsp; *<\/p>\n<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; include_once() \u548c require_once() \u5728 Windows \u4e0b\u5148\u5c07\u8def\u5f91\u898f\u683c\u5316\uff0c\u56e0\u6b64\u5305\u62ec A.php \u548c a.php \u53ea\u6703\u628a\u6a94\u6848\u5305\u62ec\u4e00\u6b21\u3002<\/p>\n<p> \u4f8b\u5b50 B-1. strrpos() \u548c strripos() \u5982\u4eca\u7528\u6574\u500b\u5b57\u4e32\u4f5c\u70ba needle<br \/> &lt;?php<br \/> var_dump(strrpos(&#39;ABCDEF&#39;,&#39;DEF&#39;)); \/\/int(3)<\/p>\n<p> var_dump(strrpos(&#39;ABCDEF&#39;,&#39;DAF&#39;)); \/\/bool(false)<br \/> ?&gt;<\/p>\n<p> \u4f8b\u5b50 B-2. \u6c92\u6709\u5c6c\u6027\u7684\u5c0d\u8c61\u4e0d\u518d\u88ab\u7576\u6210\u300cempty\u300d<br \/> &lt;?php<br \/> class test { }<br \/> $t = new test();<\/p>\n<p> var_dump(empty($t)); \/\/ echo bool(false)<\/p>\n<p> if ($t) {<br \/> &nbsp;&nbsp;&nbsp; \/\/ Will be executed<br \/> }<br \/> ?&gt;<\/p>\n<p> \u4f8b\u5b50 B-3. \u6709\u4e9b\u60c5\u6cc1\u4e0b\u985e\u5fc5\u9808\u5728\u4f7f\u7528\u4e4b\u524d\u5b9a\u7fa9<br \/> &lt;?php<\/p>\n<p> \/\/works with no errors:<br \/> $a = new a();<br \/> class a {<br \/> }<\/p>\n<p> \/\/throws an error:<br \/> $a = new b();<\/p>\n<p> interface c{<br \/> }<br \/> class b implements c {<br \/> }<\/p>\n<p> ?&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f9e PHP 4 \u79fb\u690d\u5230 PHP 5\u9700\u8981\u6ce8\u610f\u7684\u4e8b\u9805 \u5411\u5f8c\u4e0d\u76f8\u5bb9\u7684\u6539\u8b8a \u5118\u7ba1\u5927\u90e8\u5206 PHP 4 \u7684\u4ee3\u78bc\u61c9\u8a72\u4e0d\u7528\u4fee\u6539 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":385,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-16","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/posts\/16"}],"collection":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/comments?post=16"}],"version-history":[{"count":0,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/posts\/16\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/media\/385"}],"wp:attachment":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/media?parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/categories?post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/tags?post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}