How to resolve "Fatal error: Uncaught Error: Class 'User' not found"

Asked

Viewed 1,994 times

3

I created this class (starting now with POO) in the file Funcionarios.php, there it works:

class Funcionario{
    public $departamento;
    public $salario;
    public $dataEntrada;
    public $cpf;

    public function recebeAumento(){
        $this->salario += $this->salario*0.1;
    }

    public function calculaGanhoAnual(){
        return "$".$this->salario*13 .".00";
    }

    function __construct($departamento, $salario, $dataEntrada, $cpf){
    # para fazer qualquer acao com o funcionaro e necessario que o seu
    # cadastro esteja completo, entao faz sentido colocar isso num construct
        $this->departamento = $departamento;
        $this->salario = $salario;
        $this->dataEntrada = $dataEntrada;
        $this->cpf = $cpf;
    }
}

and tried to use it on teste_funcionario.php:

<?php
require "../model/Funcionario.php";

# para se criar um funcionario e necessario passar em ordem as 
seguintes informacoes:
# departamento, salario, data de entrada e cpf

$funcionarioPiloto = new Usuario("caixa",1500,"15/02/2018", 
"000.000.008-00");

$funcionarioPilotoDois = new 
Usuario("estoque",1400,"14/07/2018","000.000.009-00"); 

And every time she makes that mistake:

Fatal error: Uncaught Error: Class 'Usuario' not found in /opt/lampp/htdocs/work123programodoseujaguara/controller/teste_funcionario.php:9 Stack trace: #0 {main} thrown in /opt/lampp/htdocs/work123programmeodoseujaguara/controller/test_funcionario.php on line 9

1 answer

4


The name of your class is Funcionario, so you have to instantiate the class Funcionario and not the class Usuario (that doesn’t even exist).

The right thing would be:

$funcionarioPiloto = new Funcionario("caixa", 1500, "15/02/2018", "000.000.008-00");

$funcionarioPilotoDois = new Funcionario("estoque", 1400, "14/07/2018", "000.000.009-00"); 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.