PEAR Articles

  Home arrow PEAR Articles arrow Page 3 - My PEAR: The Beginning
PEAR ARTICLES

My PEAR: The Beginning
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-09-17

    Table of Contents:
  • My PEAR: The Beginning
  • Installing PEAR
  • PEAR Coding Standards
  • Functions

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    My PEAR: The Beginning - PEAR Coding Standards


    (Page 3 of 4 )

    While there is no commonly agreed way of writing code, the creators of PEAR have created their own way of writing code known as PCS or PEAR Coding Standards. In general you don't have to follow these standards, but if you ever want to submit your work to PEAR,  you will have to follow them. If you visit the PEAR website you will find a lot of information about PEAR Coding Standards so I will not be going into great detail here.

    To start with, all code should be indented correctly according to its context by using a suitable number of spaces. PEAR dictates four spaces. Also, if a parenthesis is optional but its inclusion improves clarity, then its inclusion is required. Comments are encouraged wherever possible. Avoid using # when commenting; instead, use the "//" for single line comments or the "/*" and "*/" for multi-line comments.

    PEAR also dictates that all starting and finishing blocks of code are done like so: starting "<?php" and finishing "?>". This is mostly because some servers may throw an error if you use "<?" for the starting block. This requirement ensures that your code is more platform independent.

    As for control structures, the curly braces should always be used. Control structures may include:

    • for
    • foreach
    • while
    • if

    PEAR dictates that curly braces should be used even if there is only a single line in the block. The PHP interpreter is very lax in this regard. This is mainly for improving clarity.

    Here is an example of PEAR compliant commenting:

    <?php

    //now check if the values in the two variables match

    if ($a==$b) {

    echo "the values match";

    }else{

    echo "The values do not match.";

    }

    /*In this block of code we evaluated the two variables to see if they matched.

    Appropriate messages where printed out to show the outcome

    */


    ?>

    The above example shows how to make single and multi-line comments that are PEAR compliant.

    More PEAR Articles Articles
    More By David Web

    blog comments powered by Disqus

    PEAR ARTICLES ARTICLES

    - Installing PEAR
    - PEAR: an Introduction
    - Managing robots.txt using PHP: Generating Dy...
    - Deleting Authors from a PEAR Content Managem...
    - PEAR CMS: Index and Delete Scripts
    - Listing Articles for a PEAR Content Manageme...
    - Building an Authors Page for a PEAR CMS
    - Building the View Details Page in a PEAR CMS
    - Creating the Main Pages of a PEAR CMS
    - Completing the Login Script for a PEAR CMS
    - User Authentication for a PEAR CMS
    - A PEAR CMS: Examining the Code
    - Building a Content Management System with PE...
    - Installing a PEAR Package
    - My PEAR: The Beginning


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap