PHP
  Home arrow PHP arrow Page 4 - Back To Class
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
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? 
PHP

Back To Class
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2000-10-05

    Table of Contents:
  • Back To Class
  • Who Needs Class, Anyway?
  • If Wishes Were Prancing Horses...
  • New Cars For Old
  • Ford's Law
  • Turning The Tables
  • Under Construction
  • Extending Yourself
  • Be My Guest

  • 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


    Back To Class - New Cars For Old


    (Page 4 of 9 )

    Now that you've got the concepts straight, let's take a look at the nitty-gritty of a class definition.

    <? class Automobile { // this is where the properties are defined var $colour; var $shape; ... // this is where the functions are defined function start() ( // code goes here ) ... } ?>
    Every class definition begins with the keyword "class", followed by a class name. You can give your class any name that strikes your fancy, so long as it doesn't collide with a reserved PHP word. A pair of curly braces encloses all class variables and functions, which are written as you would normally code them.

    In order to create a new instance of a class, you need to use the "new" keyword, and assign the newly-created object to a PHP variable.

    <? $his = new Automobile; ?>
    In English, the above would mean "create a new object of class Automobile and assign it to the variable $his".

    You can now access all the methods and properties of the class via this variable.

    <? // accessing properties $his->make = "Ferrari"; $his->colour = "Black"; // accessing methods $his->start(); $his->accelerate(180); ?>
    Again, in English,

    $his->make = "Ferrari";
    would mean

    "assign the value Ferrari to the variable $make of this specific instance of the class Automobile", while

    $his->accelerate(180);
    would mean

    "execute the function accelerate() with parameter 180 of this specific instance of the class Automobile".

    Note the -> symbol, and the fact that the $ symbol is omitted when accessing variables of a specific class instance.

    More PHP Articles
    More By icarus, (c) Melonfire


     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT