{"id":604,"date":"2010-10-14T03:15:05","date_gmt":"2010-10-14T03:15:05","guid":{"rendered":"http:\/\/tw.newtonstudio.com\/?p=604"},"modified":"2010-10-14T03:33:10","modified_gmt":"2010-10-14T03:33:10","slug":"top-10-php-tips-for-developers","status":"publish","type":"post","link":"http:\/\/tw.newtonstudio.com\/?p=604","title":{"rendered":"Top 10 PHP Tips for Developers"},"content":{"rendered":"<p><img decoding=\"async\" class=\"alignleft\" style=\"margin: 10px;\" title=\"programming\" src=\"http:\/\/www.accra.ca\/images\/CustomProgramming.jpg\" alt=\"\" width=\"300\" \/><\/p>\n<h3>1) Go OOP<\/h3>\n<p>\u5118\u91cf\u4ee5\u7269\u4ef6\u5c0e\u5411\u7684\u65b9\u5f0f\u4f86\u5beb\u7a0b\u5f0f. \u7406\u7531\u5f88\u7c21\u55ae: \u5bb9\u6613\u7dad\u8b77+\u64f4\u5145+\u7a0b\u5f0f\u91cd\u8907\u4f7f\u7528!<\/p>\n<h3>2) Stay Away from Anything Ending With _once()<\/h3>\n<p>\u50cfinclude_once, require_once\u7684\u51fd\u6578\u5118\u91cf\u4e0d\u8981\u78b0, \u56e0\u70ba\u5f88\u8017\u7cfb\u7d71\u8cc7\u6e90<\/p>\n<h3>3) Develop With Error Reporting On<\/h3>\n<p>\u958b\u767c\u4e2d\u8a18\u5f97\u5c07\u6240\u6709\u7684ERROR\u90fd\u958b\u555f, error_reporting (E_ALL); \u624d\u80fd\u77e5\u9053\u4f60\u7684\u7a0b\u5f0f\u5728\u4efb\u4f55\u74b0\u5883\u4e0b\u90fd\u662f\u6b63\u5e38\u53ef\u4ee5RUN\u7684<\/p>\n<h3>4) Use A Framework If You Need One<\/h3>\n<p>\u4f7f\u7528\u5225\u4eba\u5beb\u597d\u7684framework\u53ef\u4ee5\u6e1b\u5c11\u4f60\u7684\u958b\u767c\u6642\u7a0b, \u4f46\u76f8\u5c0d\u7684\u4f60\u5c31\u9700\u8981\u82b1\u6bd4\u8f03\u591a\u7684\u6642\u9593\u53bb\u7814\u7a76\u5225\u4eba\u7684\u529f\u80fd\u4ee5\u53ca\u600e\u9ebc\u4f7f\u7528. \u53ef\u80fd\u8981\u8996\u60c5\u6cc1\u4f86\u505a\u6289\u64c7\u4e86.<\/p>\n<h3>5) Use PHP&#8217;s Inbuilt Functions<\/h3>\n<p>\u5118\u91cf\u4f7f\u7528PHP\u5167\u5efa\u7684\u51fd\u6578\u7d55\u5c0d\u6703\u6bd4\u4f60\u81ea\u5df1\u53bb\u7528\u81ea\u5df1\u6f14\u7b97\u6cd5\u4f86\u7684\u5212\u7b97(\u7576\u7136\u524d\u63d0\u662f\u8981\u7b26\u5408\u4f60\u7684\u9700\u6c42)<\/p>\n<h3>6) Protect Your Database<\/h3>\n<p>The best and safest way is to use mysql_real_escape_string() for all database before it is added to the database. \u7b46\u8005\u662f\u5efa\u8b70\u4f7f\u7528\u51fd\u6578mysql_real_escape_string()\u4f86\u9632\u6b62\u60e1\u610f\u7684SQL INJECTION. \u4e5f\u53ef\u4ee5\u7528addslashes() \u4f46\u807d\u8aaa\u9084\u662f\u6709\u6f0f\u6d1e\u5c31\u662f\u4e86. \u53e6\u5916\u5f88\u91cd\u8981\u7684\u662f\u8981\u5be9\u6838\u4efb\u4f55POST\u6216GET, \u4e0d\u8981\u4f7f\u7528REQUEST, \u4ee5\u9632\u6b62\u4e0d\u5fc5\u8981\u7684\u6f0f\u6d1e\u5b58\u5728.<\/p>\n<h3>7) Use POST Not GET<\/h3>\n<p>\u5118\u91cf\u7528POST.\u00a0\u7406\u7531\u5f88\u7c21\u55ae, \u56e0\u70baGET\u7684QUERY STRING\u5728\u7db2\u5740\u5217\u5f88\u5bb9\u6613\u88ab\u770b\u5230, \u589e\u52a0\u591a\u4e00\u9053\u9396, \u8b93\u6709\u5fc3\u4eba\u58eb\u9700\u8981\u82b1\u66f4\u591a\u6642\u9593\u4f86\u7834\u89e3\u4f60\u7684\u7a0b\u5f0f\u662f\u7d55\u5c0d\u5283\u5f97\u4f86\u7684.<\/p>\n<h3>8) Draw Before You Code<\/h3>\n<p>\u5148\u7528\u5f35\u767d\u7d19\u4f86\u756b\u51fa\u4f60\u7684\u61c9\u7528\u7a0b\u5f0f\u69cb\u5716, \u6d41\u7a0b, \u91d0\u6e05\u8166\u6d77\u4e2d\u7684\u69cb\u601d.<\/p>\n<h3>9) Understand Your Project<\/h3>\n<p>\u9019\u662f\u5fc5\u7136\u7684\u5427?<\/p>\n<h3>10) Code Code Code<\/h3>\n<p>\u591a\u5beb\u81ea\u7136\u5c31\u6703\u9032\u6b65\u4e86!<\/p>\n<p><strong>\u53c3\u8003\u8cc7\u6599: <\/strong><br \/>\n\u7d66PHP \u958b\u767c\u8005\u768410\u500b\u8cbc\u5fc3\u5efa\u8b70:\u00a0<a href=\"http:\/\/www.htmlgoodies.com\/beyond\/php\/article.php\/3907521\">http:\/\/www.htmlgoodies.com\/beyond\/php\/article.php\/3907521<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1) Go OOP \u5118\u91cf\u4ee5\u7269\u4ef6\u5c0e\u5411\u7684\u65b9\u5f0f\u4f86\u5beb\u7a0b\u5f0f. \u7406\u7531\u5f88\u7c21\u55ae: \u5bb9\u6613\u7dad\u8b77+\u64f4\u5145+\u7a0b\u5f0f\u91cd\u8907\u4f7f\u7528! 2) Sta [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-604","post","type-post","status-publish","format-standard","hentry","category-php-"],"_links":{"self":[{"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/posts\/604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=604"}],"version-history":[{"count":4,"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/posts\/604\/revisions"}],"predecessor-version":[{"id":606,"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/posts\/604\/revisions\/606"}],"wp:attachment":[{"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=604"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/tw.newtonstudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}