SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot silverviper's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Classes vs. procedual functions?

    Hi,

    This post is not meant to flame OOP'ers.

    I'm trying to learn OOP (PHP4), but I'm having a hard time
    getting why OOP is more reusable than my procedual functions.

    For my websites i use a "functions.php" file where I have stashed all my functions,
    connect to db, resize an image... and so on.


    How would i write the following code using OOP, and make it more reusable?

    PHP Code:
    <?

    // TABLEHEADS function
    function tableHead($array_heads){
    $head .= "<table border=\"1\">\n<tr>\n";
        foreach (
    $array_heads as $new_td) {
            
    $head .= "<td>$new_td</td>\n";
        }    
    $head .= "</tr>\n";
    return 
    $head;
    }

    //call the function
    $array_heads = array('col1','col2','col3','col4','col5');
    echo 
    tableHead($array_heads).'</table>';

    ?>
    the code above outputs a html table

    HTML Code:
    <table border="1">
    <tr>
    <td>col1</td>
    <td>col2</td>
    <td>col3</td>
    <td>col4</td>
    <td>col5</td>
    </tr>
    </table>
    does anyone know of a good tutorial for OOP, that shows side by side (oop/procedual) examples?

    thx

    Silverviper

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have a read of http://www.sitepoint.com/forums/show...8&postcount=14

    It has a few examples but mainly it explains the power of OOP.


Bookmarks

Posting Permissions

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