-2
I’m creating a class with methods parameterized.
The dice sane fictitious:
<?php
require_once '../../../erros.php';
class ClientesModelos {
private $idClientes, $data, $nome, $sobreNome, $nascimento, $documento, $telefone, $celular, $email, $senha, $bloqueio;
public function __construct (
date $_data,
string $_nome,
string $_sobreNome,
date $_nacimento,
int $_documento,
int $_telefone,
bool $_celular,
string $_email,
string $_senha,
bool $_bloqueio = false
) {
$this->data = $_data;
$this->nome = $_nome;
$this->sobreNome = $_sobreNome;
$this->nascimento = $_nacimento;
$this->documento = $_documento;
$this->telefone = $_telefone;
$this->celular = $_celular;
$this->email = $_email;
$this->senha = $_senha;
$this->bloqueio = $_bloqueio;
}
public function setIdClientes(int $_idClientes) { $this->idClientes = $_idClientes; }
public function getIdClientes() : int { return $this->idClientes; }
public function getData() : string { return $this->data; }
public function getNome() : string { return $this->nome; }
public function getSobreNome() : string { return $this->sobreNome; }
public function getNascimento() : date { return $this->nascimento; }
public function getDocumento() : int { return $this->documento; }
public function getTelefone() : int { return $this->telefone; }
public function getCelular() : ?bool { return $this->celular ? $this->email : NULL; }
public function getEmail() : string { return $this->email; }
public function getSenha() : string { return $this->senha; }
public function getBloqueio() : string { return $this->bloqueio; }
}
$clientesModelos = new ClientesModelos(
date('Y-m-d'),
'Carlos',
'Alberto',
date('1970-12-20'),
77777777777,
12345678,
87654321,
'[email protected]',
'aaaa',
false
);
print_r ($clientesModelos);
I’m getting the following error:
Fatal error: Uncaught TypeError: Argument 1 passed to ClientesModelos::__construct() must be an instance of date, string given, called in
D:\Trabalhos\host\htdocs\mvc_crud_pdo\classes\mvc\modelos\ClientesModelos.php on line 71 and defined in
D:\Trabalhos\host\htdocs\mvc_crud_pdo\classes\mvc\modelos\ClientesModelos.php:10 Stack trace: #0
D:\Trabalhos\host\htdocs\mvc_crud_pdo\classes\mvc\modelos\ClientesModelos.php(71):
ClientesModelos->__construct('2019-05-02', 'Carlos', 'Alberto', '1970-12-20', 77777777777, 12345678, 87654321, '[email protected]....', 'aaaa', false) #1 {main} thrown in D:\Trabalhos\host\htdocs\mvc_crud_pdo\classes\mvc\modelos\ClientesModelos.php on line 10
But I’m going through date correctly.
And what should be the guy
date
? You’re passing a string.– Woss
I don’t think so: date("Y-m-d") and date ("1970-12-20"). Where is my error in reasoning?
– Carlos Rocha
https://www.php.net/manual/en/function.date.php#refsect1-Function.date-returnvalues
– Woss
Um, would it be the case then for me to switch to string? Or would I have to change the past parameter?]
– Carlos Rocha
The mistake is that
date
is not a type and what you are passing as parameter is the return of the function, which is a string.– Woss
The correct would then be to switch to string and treat in the body of the function?
– Carlos Rocha