From 66b18be324deca4d392ee51f8b73a6d65b75eacc Mon Sep 17 00:00:00 2001 From: David M Date: Tue, 20 Feb 2007 04:46:07 +0000 Subject: #8148 git-svn-id: file:///svn/phpbb/trunk@7020 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/docs/coding-guidelines.html | 60 +++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'phpBB/docs/coding-guidelines.html') diff --git a/phpBB/docs/coding-guidelines.html b/phpBB/docs/coding-guidelines.html index 63d83a7c20..7e949d2d90 100644 --- a/phpBB/docs/coding-guidelines.html +++ b/phpBB/docs/coding-guidelines.html @@ -598,7 +598,7 @@ if (isset($forum)) ... if (isset($forum) && $forum == 5) -

The empty() function is useful if you want to check if a variable is not set or being empty (an empty string, 0 as an integer or string, NULL, false, an empty array or a variable declared, but without a value in a class). Therefore empty should be used in favor of isset($array) && sizeof($array) > 0 - this can be written in a shorter way as !empty($array).

+

The empty() function is useful if you want to check if a variable is not set or being empty (an empty string, 0 as an integer or string, NULL, false, an empty array or a variable declared, but without a value in a class). Therefore empty should be used in favor of isset($array) && sizeof($array) > 0 - this can be written in a shorter way as !empty($array).

Switch statements:

Switch/case code blocks can get a bit long sometimes. To have some level of notice and being in-line with the opening/closing brace requirement (where they are on the same line for better readability), this also applies to switch/case code blocks and the breaks. An example:

@@ -769,9 +769,9 @@ $sql = 'SELECT *
 $sql_ary = array(
-	'somedata'		=> $my_string,
-	'otherdata'		=> $an_int,
-	'moredata'		=> $another_int
+	'somedata'		=> $my_string,
+	'otherdata'		=> $an_int,
+	'moredata'		=> $another_int
 );
 
 $db->sql_query('INSERT INTO ' . SOME_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
@@ -781,9 +781,9 @@ $db->sql_query('INSERT INTO ' . SOME_TABLE . ' ' . $db->sql_build_array('I
 
 	
 $sql_ary = array(
-	'somedata'		=> $my_string,
-	'otherdata'		=> $an_int,
-	'moredata'		=> $another_int
+	'somedata'		=> $my_string,
+	'otherdata'		=> $an_int,
+	'moredata'		=> $another_int
 );
 
 $sql = 'UPDATE ' . SOME_TABLE . ' 
@@ -850,24 +850,24 @@ SELECT FROM phpbb_forums WHERE forum_id <> 1
 
 	
 $sql_array = array(
-	'SELECT'	=> 'f.*, ft.mark_time',
+	'SELECT'	=> 'f.*, ft.mark_time',
 
-	'FROM'		=> array(
-		FORUMS_WATCH_TABLE	=> 'fw',
-		FORUMS_TABLE		=> 'f'
+	'FROM'		=> array(
+		FORUMS_WATCH_TABLE	=> 'fw',
+		FORUMS_TABLE		=> 'f'
 	),
 
-	'LEFT_JOIN'	=> array(
+	'LEFT_JOIN'	=> array(
 		array(
-			'FROM'	=> array(FORUMS_TRACK_TABLE => 'ft'),
-			'ON'	=> 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
+			'FROM'	=> array(FORUMS_TRACK_TABLE => 'ft'),
+			'ON'	=> 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
 		)
 	),
 
-	'WHERE'		=> 'fw.user_id = ' . $user->data['user_id'] . ' 
+	'WHERE'		=> 'fw.user_id = ' . $user->data['user_id'] . ' 
 		AND f.forum_id = fw.forum_id',
 
-	'ORDER_BY'	=> 'left_id'
+	'ORDER_BY'	=> 'left_id'
 );
 
 $sql = $db->sql_build_query('SELECT', $sql_array);
@@ -877,25 +877,25 @@ $sql = $db->sql_build_query('SELECT', $sql_array);
 
 	
 $sql_array = array(
-	'SELECT'	=> 'f.*',
+	'SELECT'	=> 'f.*',
 
-	'FROM'		=> array(
-		FORUMS_WATCH_TABLE	=> 'fw',
-		FORUMS_TABLE		=> 'f'
+	'FROM'		=> array(
+		FORUMS_WATCH_TABLE	=> 'fw',
+		FORUMS_TABLE		=> 'f'
 	),
 
-	'WHERE'		=> 'fw.user_id = ' . $user->data['user_id'] . ' 
+	'WHERE'		=> 'fw.user_id = ' . $user->data['user_id'] . ' 
 		AND f.forum_id = fw.forum_id',
 
-	'ORDER_BY'	=> 'left_id'
+	'ORDER_BY'	=> 'left_id'
 );
 
 if ($config['load_db_lastread'])
 {
 	$sql_array['LEFT_JOIN'] = array(
 		array(
-			'FROM'	=> array(FORUMS_TRACK_TABLE => 'ft'),
-			'ON'	=> 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
+			'FROM'	=> array(FORUMS_TRACK_TABLE => 'ft'),
+			'ON'	=> 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
 		)
 	);
 
@@ -984,7 +984,7 @@ $mark_array = request_var('mark', array(0));
 
 	

// Getting an array, keys are strings, value defaults to 0

-$action_ary = request_var('action', array('' => 0));
+$action_ary = request_var('action', array('' => 0));
 	

Login checks/redirection:

@@ -999,12 +999,12 @@ $action_ary = request_var('action', array('' => 0));

Sessions should be initiated on each page, as near the top as possible using the following code:

-$user->session_begin();
-$auth->acl($user->data);
-$user->setup();
+$user->session_begin();
+$auth->acl($user->data);
+$user->setup();
 	
-

The $user->setup() call can be used to pass on additional language definition and a custom style (used in viewforum).

+

The $user->setup() call can be used to pass on additional language definition and a custom style (used in viewforum).

Errors and messages:

All messages/errors should be outputed by calling trigger_error() using the appropriate message type and language string. Example:

@@ -1328,7 +1328,7 @@ div

You are even able to check the number of items within a loop by comparing it with values within the IF condition:

-<!-- IF .loop > 2 -->
+<!-- IF .loop > 2 -->
 	<!-- BEGIN loop -->
 		markup
 	<!-- END loop -->
-- 
cgit v1.2.1