IT Community - Software Programming, Web Development and Technical Support

Static members

This is a discussion on Static members within the PHP Programming forums, part of the Web Development category; Classes definitions can now include static members (properties), accessible via the class. Common usage of static members is in the ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 12-05-2007, 10:08 AM
ragavraj ragavraj is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 92
ragavraj is on a distinguished road
Default Static members

Classes definitions can now include static members (properties), accessible via the class. Common usage of static members is in the Singleton pattern.
PHP Code:
class Singleton {
    static private 
$instance NULL;

    private function 
__construct() {
    }

    static public function 
getInstance() {
        if (
self::$instance == NULL) {
            
self::$instance = new Singleton();
        }
        return 
self::$instance;
    }

Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-06-2007, 06:33 AM
Kamalakannan Kamalakannan is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 299
Kamalakannan is on a distinguished road
Default Re: Static members

Hi rajan,

Can u explain me what mean by Singleton pattern?

Regards,
R.Kamalakannan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-06-2007, 08:17 PM
ragavraj ragavraj is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 92
ragavraj is on a distinguished road
Default Re: Static members

The Singleton is one of the simplest Patterns to understand. It's common usage is to ensure that only one instance of a class is ever instantiated. The reason for wanting such behaviour varies but typically it is because only one object instantiated from the source class is required and you want the resulting object to be available throughout an application, i.e. globally available.

An example might be a class for storing Settings. A Settings class is a good candidate for a Singleton because its data is immutable (the only way to change settings data is to edit the settings file) and it is likely required in many areas of an application. Furthermore creating a new Settings object wherever it is needed is wasteful of resources - each is identical to all others.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hello To all the members of this forum satyaraghavendra Introductions 1 08-25-2007 01:51 AM
Static Global Variable and Static Local Variable vigneshgets C and C++ Programming 1 05-30-2007 11:50 AM
difference between a static and a non-static inner class vigneshgets Java Programming 1 05-23-2007 11:02 PM
Java Static swoosh Java Programming 3 05-08-2007 04:36 AM
Which forum has a biggest members? montyauto The Lounge 1 03-12-2007 06:28 AM


All times are GMT -7. The time now is 03:46 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0