Programming Basics

  Home arrow Programming Basics arrow Page 4 - Beginning Object Oriented Programming ...
PROGRAMMING BASICS

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

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

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Beginning Object Oriented Programming in PHP - Methods


    (Page 4 of 6 )

    To ask the box what it contains, the special get_whats_inside function was used. Functions defined in the class are known as methods; they act as a method for communicating with and manipulating the data within the box.

    The nice thing about methods is that they allow us to separate all the class coding from our actual script.

    We could save all of the class code in a separate file and then use include to import it into our script. Our scripts become more streamlined and, because we used descriptive names for our methods, anyone else reading our code can easily see our train-of-thought.

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

    $mybox = new Box("Jack");
    echo 
    $mybox-&gt;get_whats_inside();

    ?&
    gt;
    ?>

    Another benefit of methods is that it provides our box or whatever other objects we may build with a standard interface that anyone can use. We can share our classes with other programmers or even import them into our other scripts when the functionality they provide is needed.

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

    $mybox = new Box("Suggestion");
    echo 
    $mybox-&gt;get_whats_inside();
    ?>

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

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

    More Programming Basics Articles
    More By bluephoenix

    blog comments powered by Disqus

    PROGRAMMING BASICS ARTICLES

    - The Transliteration Operator in Perl
    - Perl String Processing Functions
    - Perl String Processing
    - Control Flow Constructs: Loops Conclusion
    - Loop Control Constructs
    - Control Flow Constructs: the For and Foreach...
    - Loops and Control Flow Constructs
    - Expression Modifiers for Perl Control Flow C...
    - Logical Operators and Control Flow Constructs
    - Comparing Strings with Control Flow Construc...
    - Perl Operators and Control Flow Constructs
    - Control Flow Constructs
    - More Time Manipulation with PHP
    - Validating and Manipulating Dates with PHP
    - Using the Date Constructor in PHP

    Developer Shed Affiliates

     



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