title: PDO class use chain method
body: <p>This is my "wrapper" class, over PDO (it is larger, this is the important part right now)</p>
  
  <pre><code>class DB
      {
          protected $pdo;
          protected $dsn;
          protected $username;
          protected $password;
          protected $driverOptions;
          protected $query;
  
          public function __construct($dsn, $username = '', $password = '', array $driverOptions = [])
          {
              $this-&gt;dsn = $dsn;
              $this-&gt;username = $username;
              $this-&gt;password = $password;
              $this-&gt;driver_options = $driverOptions;
          }
  
          public function connect()
          {
              $this-&gt;pdo = new PDO($this-&gt;dsn, $this-&gt;username, $this-&gt;password, (array)$this-&gt;driver_options);
              $this-&gt;pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
              return $this-&gt;pdo;
          }
  
          public function myQuery($sql)
          {
              $this-&gt;query = $this-&gt;pdo-&gt;prepare($sql);
              $this-&gt;query-&gt;execute();
              return $this-&gt;query;
          }
  
          public function all()
          {
              $all = $this-&gt;query-&gt;fetchAll();
              $this-&gt;query-&gt;closeCursor();
              return $all;
          }
      }
  </code></pre>
  
  <p>This works perfectly(if a little change, in particular by adding type hinting), as such:</p>
  
  <pre><code>$class = new myPDO('mysql:host=localhost;dbname=***', 'login', 'pass');
  $prepare = $class-&gt;connect()-&gt;prepare('SELECT * FROM test');
  $prepare-&gt;execute();
  $result = $prepare-&gt;fetch();
  </code></pre>
  
  <p>BUT I want to use it this way:</p>
  
  <pre><code>$pdo = new DB('mysql:host=localhost;dbname=***', 'login', 'pass');
  $result = $pdo-&gt;connect()-&gt;myQuery('SELECT * FROM test')-&gt;all();
  </code></pre>
  
  <p>There was this error in my IDE:</p>
  
  <blockquote>
    <p>Method 'myQuery' not found in class PDO</p>
  </blockquote>