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];
}
}
}