Vinicius Dias
Notice: Undefined property: Alura\Banco\Modelo\Conta\Conta::$cpf in C:\Users\alefr\Desktop\Aula dev front end\php\Projeto\src\Modelo\Conta\Conta.php on line 70
PHP Notice: Undefined property: Alura\Banco\Modelo\Conta\Conta::$cpf in C:\Users\alefr\Desktop\Aula dev front end\php\Projeto\src\Modelo\Conta\Conta.php on line 70
PHP Fatal error: Uncaught Error: Call to a member function recuperaCpf() on null in C:\Users\alefr\Desktop\Aula dev front end\php\Projeto\src\Modelo\Conta\Conta.php:70
Stack trace:
#0 C:\Users\alefr\Desktop\Aula dev front end\php\Projeto\bancoA.php(26): Alura\Banco\Modelo\Conta\Conta->recuperaCpfTitular()
#1 {main}
thrown in C:\Users\alefr\Desktop\Aula dev front end\php\Projeto\src\Modelo\Conta\Conta.php on line 70
Fatal error: Uncaught Error: Call to a member function recuperaCpf() on null in C:\Users\alefr\Desktop\Aula dev front end\php\Projeto\src\Modelo\Conta\Conta.php:70
Stack trace:
#0 C:\Users\alefr\Desktop\Aula dev front end\php\Projeto\bancoA.php(26): Alura\Banco\Modelo\Conta\Conta->recuperaCpfTitular()
#1 {main}
thrown in C:\Users\alefr\Desktop\Aula dev front end\php\Projeto\src\Modelo\Conta\Conta.php on line 70
<?php
namespace Alura\Banco\Modelo\Conta;
class Conta
{
private $titular;
private $saldo;
private static $numeroDeContas = 0;
public function __construct(Titular $titular)
{
$this->titular = $titular;
$this->saldo = 0;
self::$numeroDeContas++;
}
public function __destruct()
{
self::$numeroDeContas--;
}
public function saca(float $valorASacar): void
{
if ($valorASacar > $this->saldo) {
echo "Saldo indisponÃvel";
return;
}
$this->saldo -= $valorASacar;
}
public function deposita(float $valorADepositar): void
{
if ($valorADepositar < 0) {
echo "Valor precisa ser positivo";
return;
}
$this->saldo += $valorADepositar;
}
public function transfere(float $valorATransferir, Conta $contaDestino): void
{
if ($valorATransferir > $this->saldo) {
echo "Saldo indisponÃvel";
return;
}
$this->sacar($valorATransferir);
$contaDestino->depositar($valorATransferir);
}
public function recuperaSaldo(): float
{
return $this->saldo;
}
public function recuperaNomeTitular(): string
{
return $this->titular->recuperaNome();
}
public function recuperaCpfTitular(): string
{
return $this->cpf->recuperaCpf();
}
public static function recuperaNumeroDeContas(): int
{
return self::$numeroDeContas;
}
}
<?php
namespace Alura\Banco\Modelo;
class Pessoa{
protected string $nome;
private string $cpf;
public function __construct(string $nome, CPF $cpf)
{
$this->validaNomeTitular($nome);
$this->nome = $nome;
$this->CPF = $cpf;
}
public function recuperaNome(): string
{
return $this->nome;
}
public function recuperaCpf(): string
{
return $this->cpf->recuperaNumero();
}
public function defineNome()
{
return $this->nome;
}
public function defineCPF()
{
return $this->cpf;
}
protected function validaNomeTitular(string $nomeTitular)
{
if (strlen($nomeTitular) < 5) {
echo "Nome precisa ter pelo menos 5 caracteres";
exit();
}
}
}