Programming Basics
  Home arrow Programming Basics arrow Page 5 - Beginning Object Oriented Programming ...
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PROGRAMMING BASICS

Beginning Object Oriented Programming in PHP
By: bluephoenix
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 132
    2003-11-11

    Table of Contents:
  • Beginning Object Oriented Programming in PHP
  • Objects - The Magic Box
  • Classes
  • Methods
  • Extends
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Beginning Object Oriented Programming in PHP - Extends


    (Page 5 of 6 )

    So far our example is only capable of telling us what its content is. We could add more methods to our class, but what if we were building extensions to someone else's class? We don't have to create an entirely new class to add new functionality... we can build a small extension class based on the original.

    <?php
    ;
    include(
    "class.Box.php");

    class 
    ShoeBox extends Box
    {
      
    varr $size;

      function 
    ShoeBox($contents$size) {
        
    $this-&gt;contents $contents;
        
    $this-&gt;size $size;
      }

      function 
    get_shoe_size() {
        return 
    $this-&gt;size;
      }
    }

    $mybox = new ShoeBox("Shoes"10);
    echo 
    $mybox-&gt;get_whats_inside();
    echo 
    $mybox-&gt;get_shoe_size();
    ?>

    With the extends keyword, our script now has access to a ShoeBox class which is based on our original Box class. ShoeBox has all of the same functionality as Box class but also has extra functions specific to a special kind of box.

    The ability to write such modular additions to your code gives great flexibility in testing out new methods and saves time by reusing the same core code.

    <?php
    include("class.Box.php");
    include(
    "extentions.Shoe.php");
    include(
    "extentions.Suggestion.php");
    include(
    "extentions.Cardboard.php");

    $mybox = new ShoeBox("Shoes"10);
    $mySuggestion = new SuggestionBox("Complaints");
    $myCardboard = new CardboardBox(''"corrugated""18in""12in""10in");
    ?>

    More Programming Basics Articles
    More By bluephoenix


       · the tutorial is very clear &gt;&gt;really excellent
       · I liked the article.Does PHP4 support private/protected/public variables and...
       · I just got a good handle on how functions work and with this it just elevates to...
       · one of best explains i'v seen about objects..sorry for the english ...i speak...
       · DEAR SIR,I WANT TO KNOW ABOUT FUNCTIONS AND OOPS CONCEPTS IN PHP PLEAS REPLY TO MY...
       · thanx for the tutorial.. now I know how to use Class.....
       · Thanks for writing such a clear and concise introduction to OOP.I now feel...
       · This is a great article.I have never read such a great article on OOP in my life.The...
       · Nice article to understatnd OOPS. The English used to explain OOPS is very simple to...
       · I couldn't make it work until I made some changes, then I ended up doing some...
       · Fantastic tutorial! Well spoken!
       · your website displays displays greater than signs ( > ) as > and ampersands as...
       · I would like to thank you for writing such an excellent, concise and clear PHP OOP...
       · Very good tutorial very easy to understand and the analogies were excellent
       · In the code examples where text is rendered literally there is no need for the...
       · So, now I understand OOP a little better, can you explain the action of -> using...
       · I'm guessing you are a windows fan. I'd like to pass on to your many, many...
       · I have read lots of them and this is the first I have ever commented on. It was easy...
       · This was a very basic explanation and potentially helpful to anyone who knows the...
       · this is very very very wst knlwdg of OOPS where is orgi basics of OOPS
       · Excellent turtorial on PHP OOP concepts for a beginning PHP procedural...
       · n i must say...ur mind blowing!!!u made my some chunk of time ..quite...
       · Google adds covered the text of the tutorial on one page and covered part of the...
     

    PROGRAMMING BASICS ARTICLES

    - PHP: Hypertext Preprocessor: What is it?
    - Loops and PHP Decision Making
    - Operators, Conditionals, and PHP Decision-Ma...
    - PHP Decision-Making
    - Coding
    - Server Statistics
    - Looping in PHP
    - Cookies in PHP
    - Working with text files
    - Beginning Object Oriented Programming in PHP
    - A Tour of Decision Making Structures in PHP
    - PHP Strings Primer
    - PHP Control Structures
    - Intro to Vim
    - Reading Directorys with PHP





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT