Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-03-2013, 01:05 PM   PM User | #1
cancer10
Regular Coder

 
Join Date: Jun 2006
Location: India
Posts: 799
Thanks: 211
Thanked 2 Times in 2 Posts
cancer10 can only hope to improve
Question Zend Framework Coding Standards

Hello

I was going through the Zend Framework Coding Standards and was unable to understand the meaning of the following lines, please if someone can explain them to me with example if possible.


  1. An indexed array may start with any non-negative number, however all base indices besides 0 are discouraged.
  2. The construct default should never be omitted from a switch statement





Many thanks
cancer10 is offline   Reply With Quote
Old 01-03-2013, 02:17 PM   PM User | #2
TFlan
New Coder

 
Join Date: Dec 2012
Location: USA
Posts: 82
Thanks: 3
Thanked 17 Times in 17 Posts
TFlan is an unknown quantity at this point
Quote:
An indexed array may start with any non-negative number, however all base indices besides 0 are discouraged.
An array CAN NOT start with any negative number, and any array SHOULD start with an index of 0.

IE:
Do Not Do:
PHP Code:
<?php
$var 
= array(
    [-
4] => 'Hello',
    [-
3] => 'World'
);
?>
Do:
PHP Code:
<?php
$var 
= array(
    [
a] => 'Hello',
    [
b] => 'World'
);
?>
Recommended:
PHP Code:
<?php
$var 
= array(
    [
0] => 'Hello',
    [
1] => 'World'
);
?>
Quote:
The construct default should never be omitted from a switch statement
Do not leave out the default option in any switch.

IE:
Do Not Do:
PHP Code:
<?php
switch($var){
    case 
'a':
        break;
    case 
'b':
        break;
}
?>
Do:
PHP Code:
<?php
switch($var){
    case 
'a':
        break;
    case 
'b':
        break;
    default:
        break;
}
?>
TFlan is offline   Reply With Quote
Users who have thanked TFlan for this post:
cancer10 (01-04-2013)
Old 01-03-2013, 03:32 PM   PM User | #3
cancer10
Regular Coder

 
Join Date: Jun 2006
Location: India
Posts: 799
Thanks: 211
Thanked 2 Times in 2 Posts
cancer10 can only hope to improve
Thanks so much for the explanation TFlan, so

1) indices means index, right?

2) what does "base indices" here mean?
cancer10 is offline   Reply With Quote
Old 01-03-2013, 07:28 PM   PM User | #4
TFlan
New Coder

 
Join Date: Dec 2012
Location: USA
Posts: 82
Thanks: 3
Thanked 17 Times in 17 Posts
TFlan is an unknown quantity at this point
Correct, indices is plural for index.

"Base indices" means just what it says. The base index.

IE:
Not Recommended:
PHP Code:
<?php
$var 
= array(11 => 'a''b''c');
?>
Recommended:
PHP Code:
<?php
$var 
= array(=> 'a''b''c');
?>
The first example would assign the index of 11 to a, 12 to b, 13 to c.
The second example would assign the index of 0 to a, 1 to b, 2 to c.

"Thanks for the further clarification."
You're very welcome

Last edited by TFlan; 01-04-2013 at 09:53 PM..
TFlan is offline   Reply With Quote
Users who have thanked TFlan for this post:
cancer10 (01-04-2013)
Old 01-04-2013, 04:22 AM   PM User | #5
cancer10
Regular Coder

 
Join Date: Jun 2006
Location: India
Posts: 799
Thanks: 211
Thanked 2 Times in 2 Posts
cancer10 can only hope to improve
Thanks for the further clarification.
cancer10 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:46 AM.


Advertisement
Log in to turn off these ads.