NOT FOUND ERROR - PHP

Asked

Viewed 302 times

0

ERROR:

Fatal error: Uncaught Error: Class 'Alunomasculino Aluno' not found in C: xampp htdocs Fullstrack PHP OO Exercicios Projeto-Escola Alunomasculino.php:7 Stack trace: #0 C: xampp htdocs Fullstrack PHP OO Exercicios Projeto-Escola Universidade.php(2): require_once() #1 {main} thrown in C: xampp htdocs Fullstrack PHP OO Exercicios Projeto-Escola Alunomasculino.php on line 7

<?php 

namespace Aluno;

 class Aluno{
    public $codigo;
    public $nome;
    public $cpf;

    function __construct(){

    }
    public function getSexo()
    {
        return $this->sexo;
    }

    public function isApto($apto){
        return true;
    }

    public function setSexo($sexo)
    {
        $this->sexo = $sexo;
    }


}



?>
<?php
namespace AlunoMasculino;
include 'Aluno.php';



class AlunoMasculino extends Aluno{
    public $numeroCarteiraMilitar;



    public function setNumeroCarteiraMilitar($numeroCarteiraMilitar){
        $this->numeroCarteiraMilitar = $numeroCarteiraMilitar;
    }

    public function isApto($apto){


        return true;
    }


    public function getSexo($sexo)
    {
        return $this->sexo;
    }


}



?>
<?php
require_once 'AlunoMasculino.php';
require_once 'Aluno.php';

//Namespace
//use AlunoMasculino\AlunoMasculino ;

$AlunoMasculino = new AlunoMasculino();

//codigo uid
$token = md5(uniqid(""));

//Aluno, codigo e cpf
$AlunoMasculino->nome = "Aluno";
$AlunoMasculino->codigo = $token;
$AlunoMasculino->cpf = "000.000.000.00";
$AlunoMasculino->setSexo("Masculino");
$AlunoMasculino->getSexo();




 ?>

THIS LAST IS THE UNIVERSITY ARCHIVE, I AM UNABLE TO CALL THE MALE STUDENT INFORMING HE HAS NOT FOUND THE STUDENT CLASS

  • 1

    You know how the namespace? You set the class Aluno within the namespace Aluno, but is trying to use it inside the namespace AlunoMasculino. Basically you implemented it Aluno\Aluno and called AlunoMasculino\Aluno, that doesn’t exist.

  • I’m studying it right now, it’s an exercise, so doubt, get it ? ie in case I wanted to use it in another class, because the namespace practically only is used qd classes have the same name, right ?

  • 1
  • Okay, thanks, I don’t know if I delete that question or mark as seen

No answers

Browser other questions tagged

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