title: PHP singleton pattern
body: <p>Hello there i want to learn a singleton pattern in php,
  i have a class:</p>
  
  <pre><code>class Database
  {
      private static $instance;
  
      private function __construct() 
      { 
      }
  
      public static function getInstance()
      {
          if (!self::$instance)
          {
              self::$instance= new Database();
          }
  
          return self::$instance;
      }
  
      public function query($table)
      {
           $this-&gt;query = 'select * from $table';
      }
  
      public function result()
      {
          echo $this-&gt;query;
  
      }
  
  }
  
  
  $db = Database::getInstance();
  </code></pre>
  
  <p>and now , is it posible to call the result() method and print the value set by the query() which is "select * from $table" using a singleton?</p>
  
  <p>i want my code in  something like:</p>
  
  <pre><code>$db-&gt;query('user_tb')-&gt;result();
  
  //output
  select * from user_tb;
  </code></pre>