Hi, can someone explain me the difference between those 2 classes? Why to use satic calls instead of an new object?
class User
{
protected $users = array();
/**
* Create new user
*
* @param string $name Username
* @return array Users
*/
public function create($name)
{
$this->users[] = $name;
return $this->users;
}
}
$u = new User();
var_dump($u->create('TEST'));
class User
{
protected static $users = array();
/**
* Create new user
*
* @param string $name Username
* @return array Users
*/
public static function create($name)
{
self::$users[] = $name;
return self::$users,
}
}
$u = User::create('TEST');
var_dump($u);