@Maxemp

Из за чего ошибка ArgumentCountError?

После переписывания метода signup в классе SignUpForm на следующий код:
public function signup()
    {
        if (!$this->validate()) {
            return null;
        }
        
        $user = new User($this->username, $this->password, $this->email);
        
        return $user->save() ? $user : null;
    }


Написания конструктора в классе User и трейта InstantiateTrait
Конструктор:
public function __construct( string $username, string $password, string $email )
	{
		$this->username = $username;
		$this->email = $email;
		$this->setPassword($password);
		$this->created_at = time();
		$this->status = self::STATUS_ACTIVE;
		$this->generateAuthKey();
		parent::__construct();
	}

Трейт:
trait InstantiateTrait
{
	private static $_instance;
	private static $_prototype;
	public static function instance($refresh = false): self
	{
		if ($refresh || self::$_prototype === null) {
			self::$_instance = self::instantiate([]);
		}
		return self::$_instance;
	}
	public static function instantiate($row): self
	{
		if (self::$_prototype === null) {
			$class = \get_called_class();
			self::$_prototype = unserialize(sprintf('O:%d:"%s":0:{}', \strlen($class), $class));
		}
		$entity = clone self::$_prototype;
		$entity->init();
		return $entity;
	}
}

Во время регистрации и авторризации пользователя выходит ошибка : ArgumentCountError
текст: Too few arguments to function common\entities\User::__construct(), 0 passed in /app/vendor/yiisoft/yii2-debug/models/search/User.php on line 34 and exactly 3 expected
Как решить эту проблему ?
  • Вопрос задан
  • 1671 просмотр
Решения вопроса 1
@BorisKorobkov
Web developer
Too few arguments to function common\entities\User::__construct(), 0 passed in /app/vendor/yiisoft/yii2-debug/models/search/User.php on line 34 and exactly 3 expected

Что именно вам не понятно в этом сообщении? Хотя бы прочитать и перевести пробовали?

Update: в моделях Yii не трогайте конструктор! Весь ваш код из него перенесите в signup() или в новый метод внутри User.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы