WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : using the singleton pattern with globals to save typing
Categories : PHP, PHP Classes Click here to Update Your Picture
Joseph Crawford
Date : Sep 26th 2004
Grade : 2 of 5 (graded 3 times)
Viewed : 3729
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Joseph Crawford
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
Like this code?
Show the author your appreciation.
 

The Post object using the singleton pattern because you will NEVER need more than one object.

in this file all i did was create a class that uses the singleton pattern, it also overrides the magic __get method so that you dont have to specify a get method to return the value, all you will need to do is $p->variable;

I hope everyone likes this idea, remember i implemented this for the $_POST auto global but using the same methods you can implement this for any pre-defined global such as $_GET, $_REQUEST, $_SESSION, $_ENV, $_SERVER, etc..


<?php
final class Post {
  static private
$instance;
  private
$_vars;

  private function
__construct() {
   
$this->_vars = $_POST;
  }

  static function
getInstance() {
    if (!
Post::$instance) {
     
Post::$instnace = new Post();
    }
    return
Post::$instnace;
  }

  public function
__get($var) {
    if (isset(
$this->_vars[$var]) {
      return
$this->_vars[$var];
    }
  }
}

$p = Post::getInstance();
$p->firstname;
?>



Three Cool Classes and One Trick
Categories : PHP, PHP Classes, Graphics, Email
Class TStringList include some metods from class TStringList implemented in INPRISE/BORLAND-DELPHI
Categories : PHP Classes, PHP, Strings
PHP Class to calculate Degrees Minutes Seconds to Decimal Degrees
Categories : PHP, PHP Classes, Geo Related, Beginner Guides
Reflection Examples - Their main goal is show how to use PHP's reflection classes re-implementing some php standard functions using reflection.
Categories : PHP, PHP Classes, Classes and Objects
logger class (PHP5 +)
Categories : PHP, PHP Classes, Log Files, XML
Class that allows the PHP developer to establish connections with a POP3 mail server amd be able to list, retrieve and delete mail messages from a given mail box.
Categories : Network, Email, PHP, PHP Classes
Search and Replace Text : Searches Files for Specified Text and Replaces It by a Given Text
Categories : PHP, PHP Classes, Search, Filesystem
A damaged image generator (class) for validating text. CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart
Categories : PHP, PHP Classes, Security, GD image library, Security
A Timing Class
Categories : PHP, PHP Classes, Date Time
Mssql database Manager
Categories : PHP, Databases, MS SQL Server, Classes and Objects, PHP Classes
Easy upload class
Categories : PHP Classes, Filesystem, HTTP, PHP
ECHO-PHP Class Real Time Transaction Processor v1.4.4 for Credit Cards and Checks / ACH
Categories : PHP Classes, Cybercash, Classes and Objects, Ecommerce, PHP
Returns Yahoo! Address Book and Messenger List as an Array
Categories : PHP, PHP Classes, CURL
PHP Image Class
Categories : PHP, PHP Classes, Multimedia, GD image library
Open and Close your website in fixed times .
Categories : PHP, PHP Classes, Cron, Date Time
 Joseph Crawford wrote : 1198
if you grade my comments and grade them low, i would appreciate it if you would post some comments and tell me why :)
 
 Joseph Crawford wrote :1199
in the last post s/comments/examples