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

    - Control Flow Constructs
    - More Time Manipulation with PHP
    - Validating and Manipulating Dates with PHP
    - Using the Date Constructor in PHP
    - Calendar Construction with PHP
    - PHP`s Calendar Package
    - Getting Modified Versions and Correct Dates ...
    - Combining Date Functions in PHP
    - Using PHP for Date and Time in Programming
    - More Exception Handling with PHP
    - Exception Handling in PHP
    - Error Logging and Handling Exceptions
    - Configuration Directives for Error and Excep...
    - Error and Exception Handling
    - Python Modules for Games


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