PEAR Articles

  Home arrow PEAR Articles arrow Page 4 - 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 - Functions


    (Page 4 of 4 )


    When making function calls, there should be no space between the name of the function and the opening parenthesis prior to its argument list. If there are no arguments to be passed, a blank list should be used by opening and then immediately closing parentheses. Take a look at this example:

    <?php

    function myfunction($num1,$num2){

    //function adds two numbers

    ..statements here..

    }


    function nopars(){

    //function does nothing in particular

    ..statements here..

    }



    $res = myFunction(5,10);

    //function with no parameters

    $answer =nopars();

    ?>

    When declaring your own functions, the rules for braces in control structures are changed slightly. The starting brace for the block should begin on a new line, immediately after the function name and argument list definition. Take a look at the example function definition below:

    function generatepassword()

    {

    //This function generates a 7 letter password

    $chars = "1234567890abcdefGHIJKLMNOPQRSTUVWxyz
    ABCDEFghijklmnopqrstuvwXYZ1234567890";

    $thepass = '';

    for($i=0;$i<7;$i++)

    {

    $thepass .= $chars{rand() % 39};

    }

    return $thepass;

    }

    A function should always return a result whether it is successful or not. Finally, PEAR does not, it seems, have any opinion on naming conventions. But generally(this is a personal observation) it looks like the name of the variable alludes to the contents of the variable itself. For example:

    $mystrvar - holds a string variable.

    $myintvar -- holds a number (integer).

    In the next article we will look at how to install and use a PEAR package.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.
    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 5 - Follow our Sitemap