Newsletter: Buy generic viagra Vicodin es Fioricet phentermine shipping Viagra use in women Effects from side viagra Viagra testimonials Buy xanax without prescription Phentermine canada Liver problems from xanax Diet pills phentermine Snorting xanax Related drugs to phentermine 5 in round white tablets no imprint code Phentermine drug test Cialis in the uk Order phentermine on line Phentermine use Is viagra safe for women 37 effects phentermine side Cheapest viagra in uk Time released xanax Prescription free viagra Meridia diet pill Viagra 100 mg Allowed cialis tag viagra xhtml Cialis price comparison Cortisol 0 buy by popl powered viagra wordpress Information on the drug xanax Anxiety disorder xanax Cheap prices phentermine Online pharmacy and phentermine overnight Phentermine prozac Xanax mexico Tomorrow Ambien overnight Generic ambien Information phentermine Generic viagra soft tabs Purchase viagra on line Lowest drug price for phentermine Xanax prescription online Viagra sex Online consultations and prescriptions phentermine Viagra levivia alternatives Herbal phentermine forum Buy ambien Low cost viagra Phentermine 37 5 Xanax and grapefruit 3mg xanax Identify xanax Hydrocodone pharmacy Ambien rx Xanax lethal dose Constipation phentermine What is xanax used for Fact phentermine diet pill Blue diet phentermine pill Cheapest viagra on line Pfizer xanax information Online phentermine sale Cafergot How does viagra work Fosamax Adipex phentermine xenical Injecting phentermine Cheap prescription viagra Leo phentermine order online Phentermine 37.5 pay by money order Xanax and valium Ultram tramadol hci tablet Fioricet medication Viagra xenical Xanax for anxiety Phentermine and ocular hypertension Cheap viagra canada Buy cheap domain online outdoors com xanax Herbal viagra reviews Phentermine diet Free viagra order online Buy phentermine online without prescription Hydrocodone ap ap Natural viagra alternatives Soma cube Phentermine hcl Phentermine for less Meridia vs. Phentermine Mail order viagra Xenical hgh phentermine quit smoking Prescription xanax Phentermine free shipping Viagra in woman Online pharmacy phentermine xenical meridia Colace Cialis overnight Phentermine $70 no prescription Phentermine tablets Generic viagra overnight delivery Buy hydrocodone overnight Xanax online no prescription Female viagra cream Discount priced viagra Adipex phentermine prescription Phentermine and carbs Blue diet phentermine pill Phentermine sites that ship cash on delivery Tramadol use Loss phentermine story weight On line prescription viagra Tramadol sale Paris cheep phentermine Phentermine 37.5mg cheap Flagyl Viagra versus levivia Vicodin and alcohol Xanax weight gain Buy tramadol without prescription Tramadol hci Oxycontin xanax bars perclesept and lortab wha Hydrocodone cough syrup Cheapest cialis Natural over counter just like viagra stores Viagra cialis levitra dose comparison Order xanax Hydrocodone overnight No prescription xanax Xanax suicide Amaryl Ambien online Viagra prices Buy viagra without a prescription Free viagra online Phentermine hci Levlen Phentermine weight loss pill Viagra sales online Female viagra Phentermine chemical enhancement Xanax with same day delivery Phentermine hcl side effects Cialis overnight shipping Viagra info Viagra 6 free sample Bosch power tools zio lowest viagra Review of herbal phentermine Buy domain onlinebigsitecitycom phentermine Effects long side term xanax Tramadol hcl 50mg Viagra prescription online Phentermine results Diet ingredient phentermine pill Bentyl 50mg viagra Purchase tramadol without a prescription Uk cheapest viagra Dog xanax Prescription phentermine with cod payment Levitra cialis info Xanax depression Viagra discount sale Cheap perscription phentermine Phentermine 30 mg Xanax and alcohol How long does xanax stay in system Cialis compared to viagra Ambien Viagra and pulmonary hypertension Viagra alternates Cheap perscription phentermine Drug vicodin Best viagra prices online Overnight phentermine no prescription Order viagra visit your doctor online Phentermine in the uk Phenytoin Cheap phentermine no shipping Cheapest phentermine pills Effects of viagra on woman Oxycontin xanax bars perclesept and lortab 92 accepted cod phentermine Pill price viagra Buy cheap fioricet Tramadol hydrochloride overdose Imuran Cheapest phentermine online Ambien side effects Hydrocodone mexican pharmacy what is tramadol Cialis samples Phentermine alternative Phentermine depression Diet phentermine Phentermine accepts cod Valium vs xanax Viagra knock offs Chinese viagra dragon power Phentermine shipped to tn Phentermine addiction help Buy cod pay phentermine What is xanax used for Hydrocodone drug Order tramadol cod Vicodin addiction Clindamycin Viagra lowest price Discount phentermine to florida Generic lowest price viagra Hydroxyzine How does viagra work Effects of viagra on woman Buy viagra online Hydrocodone drug test Cheap phentermine 37.5 mg diet pills Buy online securely viagra Natural viagra substitutes Tramadol narcotic Cialis tablets Cheap overnight phentermine Discount online phentermine Long term effects of xanax Substitute viagra Cheapest place to buy phentermine Canada xanax Ativan xanax Viagra pharmacy Lexapro and xanax What does xanax do Free phentermine Online cialis Tramadol dogs Buy cheap phentermine online Buy cialis without prescription Pfizer xanax information Uk online pharmacy phentermine Drug test tramadol Medical information on tramadol hc Viagra price online Vicodin hp Overnight phentermine Order phentermine phentermine online Generic cialis prices Xanax dosing Estraderm Vicodin for sale Santa claus viagra jokes Paris cheep phentermine Side effects of tramadol hydrochloride I need to find cheap phentermine delivered to fl Women viagra Tramadol hydrochloride Buying viagra Cialis story Vicodin info Safety of phentermine Discount phentermine free shipping Buy tramadol cheap Viagra alternates Xanax photos Natural suppliments work like viagra Phentermine and topiramate for weightloss Pictures of xanax pills Soma restaurant Phentermine meridia xenical review Buy in online uk viagra Mixing viagra and cialis Discount viagra europe Meridia online Epivir Phentermine 37 5mg and mastercard Stopping xanax Viagra buy in uk online Cheap diet phentermine pill Viagra tablets Phentermine overnight Pulmonary hypertension and viagra Compare prices on phentermine Hydrocodone overdose 5 mg diet pill On line doctor phentermine Methylphenidate Acquisto cialis Best price for generic viagra Tramadol without perscription Vicodin and pregnancy Vicodin addiction Viagra online uk Hydrocodone withdrawal symptom Phentermine and fast shipping Phentermine pharmacys online Viagra for woman information Generic viagra pill Buy phentermine by cod Vicodin health Leo phentermine order online 5 online Diet ky phentermine pill ship that Xanax prescription online Compare viagra cialis levivia Dangers of viagra Bush inauguration speech draft viagra bastard of Viagra online sales Xanax and drug testing Cod xanax Prescription for viagra Vicodin prescription Levivia vs viagra Phentermine shipped to ky Xanax 2mg generic alprazolam 180 pills Caverta veega generic viagra Cialis levitra viagra compare Allegra Xanax long term effects Phentermine price Cialis comparison viagra Mail order viagra online Meridia order Vicodin effects Phentermine saturday delivery Viagra discussion Online phentermine Phentermine by cod Ways to inject xanax pills Online pharmacy prescription viagra Lowest priced viagra in the uk Viagra suppliers Diet online phentermine pill Tramadol long term use Buy viagra line Generic viagra online Viagra experience Bosch power tools zio lowest viagra Cialis generic india Best buy phentermine Cialis experience Phentermine money order Generic viagra cheap Buy phentermine online cash on delivery Phentermine pharmacy online consultation Picture viagra Buy cialis viagra Viagra alternative and woman Cod xanax But phentermine Generic xanax online Free online phentermine shipping Generic viagra soft tab Phentermine cheapest Luvox and xanax Lowest viagra price Herbal viagra Viagra advertisements Cialis info Order generic viagra Cheap tramadol 180 Pilljar phentermine Cialis doseage Valium and xanax Viagra advertisement

Implementing Singleton Pattern in PHP4

October 3rd, 2006 by algis

Everyone knows how important this pattern is. Unfortunately, PHP4 lacks static class variables so the classic natural way to implement Singleton is not working here. In my applications it do this in the following way:

  1. In a global include file (you have one for sure) define a singleton helper function:
    function &mySingletonFunction( $class ) {
    	// Declare a static variable to hold the object instance
    	static $instances;
    
    	// If the instance is not there, create one
    	if( ! isset($instances[$class]) ){
    		$instances[$class] = new $class;
    		}
    	return $instances[$class];
    	}
    
  2. For every class that you would like to make Singleton, create a method:

    function &getInstance(){
    	return mySingletonFunction( 'myClassName' );
    	}
    
  3. In your main code, where you want to get a single instance of a class, you call it like this:

    $myObject =& myClassName::getInstance();
    

    So we get a fully functional Singleton pattern in PHP4 just with a couple of lines.

Posted in PHP Application Development | No Comments »