Update:Archive/2.0/Developers/Best Practices: Difference between revisions

m
(added $_REQUEST)
 
(12 intermediate revisions by 8 users not shown)
Line 1: Line 1:
[[Update:Home_Page|Update: Home Page]] » [[Update:Development|Development]] »
{{AmoArchive}}


== Introduction ==
== Introduction ==
Line 29: Line 29:
* Use <?php ?> to designate code blocks
* Use <?php ?> to designate code blocks
* Use CSS for all styles.
* Use CSS for all styles.
* Write in XHTML ?
* Create validated markup according to html 4.01 Strict.
* Create validated markup according to html 4.01 Strict.
* Use $_REQUEST if input could come from GET or POST
* Use $_REQUEST if input could come from GET or POST
* Check data to make sure it is the right type.  If you're expecting an int, make sure it's an int.


=== Don't ===
=== Don't ===
Line 37: Line 39:
* Use variable or function names that are ambiguous (like $var or validate()).
* Use variable or function names that are ambiguous (like $var or validate()).
* Create unnecessary functions.
* Create unnecessary functions.
* Use <? ?> to designate a PHP block.
* Use &lt;? ?&gt; to designate a PHP block.
* Use $array[foo] or $array["foo"] unless it is appropriate (constant or a variable catted with a string).
* Use $array[foo] or $array["foo"] unless it is appropriate (constant or a variable catted with a string).
* Loop MySQL queries.
* Loop MySQL queries.
* Use variables from outside PHP (GET, POST, COOKIE...) in MySQL queries without cleaning them.
* Use variables from outside PHP (GET, POST, COOKIE...) in MySQL queries without cleaning them.
* "Clean" above variables in place: '''$_GET['foo']=db_escape($_GET['foo'])''' is ''bad''. '''$foo_dbescaped=db_escape($_GET['foo'])''' is OK.
* "Clean" above variables in place: '''$_GET['foo']=db_escape($_GET['foo'])''' is ''bad''. '''$foo_dbescaped=db_escape($_GET['foo'])''' is OK.
* Pass SID via GET.
* Build URLs including Session ID (''SID should be "automagically" added by PHP if we're using a no-cookie configuration'').
* Use inline styles.  Ever.
* Use inline styles.  Ever.
* Use &lt;table&gt; for design
* Duplicate DOM IDs.
* Duplicate DOM IDs.
* Use $_GET and $_POST with extra checks if the input could come from either GET or POST
* Use $_GET and $_POST with extra checks if the input could come from either GET or POST
Line 52: Line 55:
* We prefix all the functions in a module (include) that are not meant to be called from an including file (private utility functions) with '''_mozupd_'''? example '''_mozupd_dbTest()'''
* We prefix all the functions in a module (include) that are not meant to be called from an including file (private utility functions) with '''_mozupd_'''? example '''_mozupd_dbTest()'''


:Personally, if you want to avoid namesoace conflicts, then you should be writing things as classes; so <tt>mozupd_addRating()</tt> becomes <tt>$rating = new Rating(); $rating->addRating();</tt>. I would tend to agree on "internal" methods being called <tt>_methodName</tt> but I think prefixing everything with mozupd_ etc. is going to get extremelt annoying very quickly. --[[User:Csogilvie|Csogilvie]] 10:55, 22 Jan 2005 (PST)
:Personally, if you want to avoid namespace conflicts, then you should be writing things as classes; so <tt>mozupd_addRating()</tt> becomes <tt>$rating = new Rating(); $rating->addRating();</tt>. I would tend to agree on "internal" methods being called <tt>_methodName</tt> but I think prefixing everything with mozupd_ etc. is going to get extremely annoying very quickly. --[[User:Csogilvie|Csogilvie]] 10:55, 22 Jan 2005 (PST)
 
Why not use "umo_" instead? It's much more intuitive to use.
--[[User:Topal|Topal]] 15:13, 16 Apr 2005 (PDT)
 
If we use classes then there's no need to worry about that. In the cases that there is a chance, simply do something like mozupdate_sendMail()
--[[User:Artooro|artooro]] 17:42, 22 Apr 2005 (EDT)
 
== Database Calls ==
: Please edit this as needed.
Database calls should be in the file /foo/bar.php
To execute the query and get the results, you should use a wrapper of the form:
db_Something(arg1,arg2,arg3)
canmove, Confirmed users, Bureaucrats and Sysops emeriti
1,043

edits