Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    911
    Thanks
    302
    Thanked 2 Times in 2 Posts

    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

  • #2
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    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'
    );
    ?>
    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;
    }
    ?>

  • Users who have thanked TFlan for this post:

    phantom007 (01-04-2013)

  • #3
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    911
    Thanks
    302
    Thanked 2 Times in 2 Posts
    Thanks so much for the explanation TFlan, so

    1) indices means index, right?

    2) what does "base indices" here mean?

  • #4
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    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.

  • Users who have thanked TFlan for this post:

    phantom007 (01-04-2013)

  • #5
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    911
    Thanks
    302
    Thanked 2 Times in 2 Posts
    Thanks for the further clarification.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •