valdeir2000

$this and Self

Apr 11th, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. <?php
  2.  
  3. // Dúvida referente ao post http://forum.tableless.com.br/t/ajuda-com-o-this-e-self/1095
  4.  
  5. //$u = new User();
  6. //$u->find();
  7.  
  8. echo "<pre>";
  9. var_dump(User::forge()->find());
  10.  
  11. class BaseModel
  12. {
  13.   private $_table = null;
  14.  
  15.   public function __construct($table)
  16.   {
  17.     $this->_table = $table;
  18.   }
  19.  
  20.   public function find(array $params = [])
  21.   {
  22.     die($this->table);
  23.   }
  24. }
  25.  
  26. class User extends BaseModel
  27. {
  28.   protected $table = "users";
  29.  
  30.   public function __construct()
  31.   {
  32.     $this->_table = $this->table;
  33.   }
  34.  
  35.   public static function forge()
  36.   {
  37.     return new self;
  38.   }
  39.  
  40.   public function find(array $params = [])
  41.   {
  42.     parent::find($params);
  43.   }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment