Posted By

iroybot on 01/29/09


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

umang_nine
iroybot


Singleton Pattern


 / Published in: PHP
 

  1. public static function getInstance() {
  2. if(!is_a($_SESSION["MTVUsers"], "MTVUsers") || HTTPCache::shouldBeNoCache()) $_SESSION["MTVUsers"] = new MTVUsers($_SERVER['DOCUMENT_ROOT']."/capital_invest_de/Login/Users/Users.csv", "Username", "Password");
  3. return $_SESSION["MTVUsers"];
  4. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: adix on January 29, 2009

You seem to miss the way a singleton pattern is to be implemented friend. Also, objects should not be stored in the session.

Posted By: iroybot on September 30, 2009

@adix I do this for performance reasons. This has several benefits for form validation, etc. pp

even though you would end up with the same instance on every pageload, saving the object in a session lets you access the exact same instance throughout the whole website.

What are the downsides?

Posted By: iroybot on September 30, 2009

@adix I do this for performance reasons. This has several benefits for form validation, etc. pp

even though you would end up with the same instance on every pageload, saving the object in a session lets you access the exact same instance throughout the whole website.

What are the downsides?

You need to login to post a comment.