{"id":24412,"date":"2021-04-08T23:10:12","date_gmt":"2021-04-09T03:10:12","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/good-coding-style-in-php-other-languages-root\/"},"modified":"2021-04-08T23:10:12","modified_gmt":"2021-04-09T03:10:12","slug":"good-coding-style-in-php-other-languages-root","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=24412","title":{"rendered":"Good Coding Style in PHP + Other languages #Root"},"content":{"rendered":"<p>Style 1.1: Use proper indenting<\/p>\n<pre>while ($x &lt; $z) \r\n{\r\n\tif ($a == 1) \r\n\t{\r\n\t\techo 'A was equal to 1';\r\n\t} \r\n\telse \r\n\t{\r\n\t\tif ($b == 2) \r\n\t\t{\r\n\t\t\t\/\/do something\r\n\t\t} \r\n\t\telse \r\n\t\t{\r\n\t\t\t\/\/do something else\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<pre>1.2\r\nwhile ($x &lt; $z) {\r\n\tif ($a == 1) {\r\n\t\techo 'A was equal to 1';\r\n\t} else {\r\n\t\tif ($b == 2) {\r\n\t\t\t\/\/do something\r\n\t\t} else {\r\n\t\t\t\/\/do something else\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>Style 2.1: Properly indent conditional statements. Always use braces, it will make later additions of more statements easier.<\/p>\n<pre>while ($x &lt; $z) \r\n{\r\n\tif ($a == 1) \r\n\t{\r\n\t\techo 'A was equal to 1';\r\n\t} \r\n\telse \r\n\t{\r\n\t\tif ($b == 2) \r\n\t\t{\r\n\t\t\t\/\/do something\r\n\t\t} \r\n\t\telse \r\n\t\t{\r\n\t\t\t\/\/do something else\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>Style 2.2<\/p>\n<pre>while ($x &lt; $z) {\r\n\tif ($a == 1) {\r\n\t\techo 'A was equal to 1';\r\n\t} else {\r\n\t\tif ($b == 2) {\r\n\t\t\t\/\/do something\r\n\t\t} else {\r\n\t\t\t\/\/do something else\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>3.1 Function Calls<br \/>\nNo space between function names and parenthesis.<\/p>\n<pre>\t$var = myFunction($x, $y);\r\n<\/pre>\n<p>3.2 Function declarations<\/p>\n<p>Use braces properly, give meaningful names to the parameters, always return values from functions. Avoid printing\/echoing inside functions.<\/p>\n<pre>function myFunction($province, $city = '')\r\n{\r\n\t\/\/indent all code inside here\r\n\treturn $result;\r\n}   \r\n<\/pre>\n<p>4. Use comments before a function. Also, use comments before a block [especially if it uses some difficult to understand logic] use PHPDoc style comments that may work like Javadoc to create documentation from your source files<\/p>\n<pre>\/**\r\n *\tshort description of function\r\n *\r\n *\tOptional more detailed description.\r\n *\r\n *\t@param $paramName - type - brief purpose\r\n *\t@param ...\r\n *\t...\r\n *\t@return type and description\r\n *\/\r\n<\/pre>\n<p>5. Use include_once or require_once instead of include or require to include a file that contains common variables, functions, classes.<br \/>\n6. PHP tags: always use<\/p>\n<pre>  &lt;?php\r\n\r\n  ?&gt;\r\n<\/pre>\n<p>instead of<\/p>\n<pre>  &lt;?\r\n\r\n  ?&gt;\r\n<\/pre>\n<p>7. to enclose strings use single quote &#8216; &#8216; rather than double quotes &#8221; &#8220;. Try to use . to concate string variables. You can use double quote and put variables inside.<\/p>\n<pre>\t$associative_array['name'];\r\n\t$var='My String';\r\n\t$var2='Very... long... string... ' . $var . ' ...more string... ';\r\n\t$sql=\"INSERT INTO mytable (field) VALUES ('$var')\";\r\n<\/pre>\n<p>8. Follow some conventions for variable and function names<\/p>\n<ul>\n<li>Class name start with uppercase letter. Each word should start with uppercase letter<\/li>\n<li>Variable and function name may start with lower case letters. Then each word will start with a capital letter<\/li>\n<li>give meaningful names to variables and functions<\/li>\n<li>Do not make them too lengthy. I prefer less than 12-15 character names<\/li>\n<li>Do not abbreviate words in variable or function names. Use $url or $articleUrl as variable names, not $URL or $articleURL as<\/li>\n<\/ul>\n<p> From: http:\/\/sitestree.com\/?p=3535<br \/> Categories:Root<br \/>Tags:<br \/> Post Data:2016-07-08 16:04:58<\/p>\n<p>\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\">https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\t(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"> http:\/\/Training.SitesTree.com<\/a><br \/>\n\t\tIn Bengali: <a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\">http:\/\/Bangla.SaLearningSchool.com<\/a><br \/>\n\t\t<a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\">http:\/\/SitesTree.com<\/a><br \/>\n\t\t8112223 Canada Inc.\/JustEtc: <a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\">http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) <\/a><br \/>\n\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com'> https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\tMedium: <a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"> https:\/\/medium.com\/@SayedAhmedCanada <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Style 1.1: Use proper indenting while ($x &lt; $z) { if ($a == 1) { echo &#8216;A was equal to 1&#8217;; } else { if ($b == 2) { \/\/do something } else { \/\/do something else } } } &nbsp; 1.2 while ($x &lt; $z) { if ($a == 1) { echo &#8216;A was &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=24412\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-24412","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":70111,"url":"http:\/\/bangla.sitestree.com\/?p=70111","url_meta":{"origin":24412,"position":0},"title":"Good Coding Style in PHP + Other languages #15","author":"Author-Check- Article-or-Video","date":"August 26, 2021","format":false,"excerpt":"Style 1.1: Use proper indentingwhile ($x < $z) { if ($a == 1) { echo 'A was equal to 1'; } else { if ($b == 2) { \/\/do something } else { \/\/do something else } }}1.2while ($x < $z) { if ($a == 1) { echo 'A was\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65714,"url":"http:\/\/bangla.sitestree.com\/?p=65714","url_meta":{"origin":24412,"position":1},"title":"If then else in shell programming. Count the number of files in current directory, and check &#8230; #Linux\/Unix: Shell Programming &#8211; 001","author":"Author-Check- Article-or-Video","date":"July 12, 2021","format":false,"excerpt":"#!\/bin\/sh #count the number of files in current directory, and check if the number is equal to or greater than or less than 26 #NOF represents number of files NOF=`ls -l | wc -l` if [ $NOF -eq 26 ] then echo \"No of files and directories is equal to\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65784,"url":"http:\/\/bangla.sitestree.com\/?p=65784","url_meta":{"origin":24412,"position":2},"title":"Some JavaScript stuff that you need to know #JavaScript","author":"Author-Check- Article-or-Video","date":"July 14, 2021","format":false,"excerpt":"What you really need to learn in Javascript? 1. Where you can place JavaScript codes? Anywhere in the web-pages, ideally in the header section, or in an external file. If you keep javascript codes in an external file, the codes will be re-usable from different web-pages 2. Some basic programming:\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6010,"url":"http:\/\/bangla.sitestree.com\/?p=6010","url_meta":{"origin":24412,"position":3},"title":"\u09aa\u09bf\u098f\u0987\u099a\u09aa\u09bf \u09eb if&#8230;else&#8230;elseif \u09b8\u09cd\u099f\u09cd\u09af\u09be\u099f\u09ae\u09c7\u09a8\u09cd\u099f (PHP 5 if&#8230;else&#8230;elseif Statements)","author":"Author-Check- Article-or-Video","date":"February 7, 2015","format":false,"excerpt":"PHP \u09a4\u09c7 \u0986\u09ae\u09b0\u09be \u0995\u09cb\u09a8 variable \u0998\u09cb\u09b7\u09a3\u09be \u0995\u09b0\u09b2\u09c7 \u09a4\u09be $ \u099a\u09bf\u09b9\u09cd\u09a8 \u09a6\u09bf\u09df\u09c7 \u09aa\u09cd\u09b0\u0995\u09be\u09b6 \u0995\u09b0\u09c7 \u09a5\u09be\u0995\u09bf\u0964 \u0986\u09ae\u09b0\u09be \u09af\u09a6\u09bf if-else statement \u098f\u09b0 \u0995\u09be\u099c \u0995\u09b0\u09a4\u09c7 \u09af\u09be\u0987 \u09a4\u09be\u09b9\u09b2\u09c7 \u0986\u09ae\u09be\u09a6\u09c7\u09b0 \u098f\u0987 \u099a\u09bf\u09b9\u09cd\u09a8 \u09a8\u09bf\u09df\u09c7 \u0995\u09be\u099c \u0995\u09b0\u09a4\u09c7 \u09b9\u09ac\u09c7\u0964 \u0995\u09cb\u09a8 \u0989\u09a6\u09be\u09b9\u09b0\u09a8 \u09a6\u09c7\u0993\u09df\u09be\u09b0 \u0986\u0997\u09c7 \u0986\u09ae\u09b0\u09be \u098f\u0995\u099f\u09c1 if-else \u09ac\u09bf\u09b7\u09df \u099f\u09be \u09ac\u09c1\u099d\u09c7 \u09a8\u09c7\u0987\u0964 \u09aa\u09bf\u098f\u0987\u099a\u09aa\u09bf \u09ab\u09be\u0987\u09b2 \u09b0\u09be\u09a8 \u0995\u09b0\u09be\u09b0 \u0995\u09cd\u09b7\u09c7\u09a4\u09cd\u09b0\u09c7 \u0986\u09ae\u09be\u09a6\u09c7\u09b0 \u0985\u09a8\u09c7\u0995 condition \u09a5\u09be\u0995\u09a4\u09c7\u2026","rel":"","context":"In &quot;\u09aa\u09bf \u098f\u0987\u099a \u09aa\u09bf \u099f\u09bf\u0989\u099f\u09cb\u09b0\u09bf\u09df\u09be\u09b2 \u0964 PHP tutorial&quot;","block_context":{"text":"\u09aa\u09bf \u098f\u0987\u099a \u09aa\u09bf \u099f\u09bf\u0989\u099f\u09cb\u09b0\u09bf\u09df\u09be\u09b2 \u0964 PHP tutorial","link":"http:\/\/bangla.sitestree.com\/?cat=172"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":70121,"url":"http:\/\/bangla.sitestree.com\/?p=70121","url_meta":{"origin":24412,"position":4},"title":"What you really need to learn in Javascript? #13","author":"Author-Check- Article-or-Video","date":"August 26, 2021","format":false,"excerpt":"What you really need to learn in Javascript? 1. Where you can place JavaScript codes? Anywhere in the web-pages, ideally in the header section, or in an external file. If you keep javascript codes in an external file, the codes will be re-usable from different web-pages2. Some basic programming: document.write('Hello\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65720,"url":"http:\/\/bangla.sitestree.com\/?p=65720","url_meta":{"origin":24412,"position":5},"title":"If then else example in Shell Programming #Linux\/Unix: Shell Programming &#8211; 001","author":"Author-Check- Article-or-Video","date":"July 12, 2021","format":false,"excerpt":"#!\/bin\/sh #If then else example #if elif else NOF=5 if [ $NOF -eq 27 ] then echo \"No of files and directories = 27\" elif [ $NOF -gt 27 ] then echo \"No of files are dir are greator than 27\" else echo \"No of files and directories are less\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/24412","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=24412"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/24412\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=24412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=24412"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=24412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}