Home arrow PHP arrow Page 7 - Back To Class

Under Construction - PHP

Classes and objects are powerful OOP concepts - and PHP4 supportsthem too. This article explains some basic OO entities (including classes,constructors and extensibility) with examples of a table builder and aguestbook.

TABLE OF CONTENTS:
  1. Back To Class
  2. Who Needs Class, Anyway?
  3. If Wishes Were Prancing Horses...
  4. New Cars For Old
  5. Ford's Law
  6. Turning The Tables
  7. Under Construction
  8. Extending Yourself
  9. Be My Guest
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 9
October 05, 2000

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
It's also possible to automatically execute a function when the class is called to create a new object. This is referred to in geek lingo as a "constructor" and, in order to use it, your class definition must contain a function with the same name as the class.

For example, if you'd like your car to start automatically when you create it, add the function Automobile() to your definition, as show below.

<? class Automobile { // constructor function Automobile { $this->start(); } function start() ( // code goes here ) } ?>
Or, in the table example you just saw, you could define a default grid and colours for your table when the object is created.

<? class Table { // constructor function Table() { $this->rows = 4; $this->columns = 5; $this->bcolor = "black"; $this->fcolor = "white"; $this->font = "Times New Roman"; } // other functions ?>
And now, when you create a new Table object like this, without defining any parameters,

<? // first table $alpha = new Table; $alpha->drawTable(); ?>
you'll get a default 4x4 black and white grid. Try it and see for yourself!

 
 
>>> More PHP Articles          >>> More By icarus, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: