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
You know how the namespace? You set the class
Alunowithin the namespaceAluno, but is trying to use it inside the namespaceAlunoMasculino. Basically you implemented itAluno\Alunoand calledAlunoMasculino\Aluno, that doesn’t exist.– Woss
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 ?
– Vitor
Perhaps you should read How namespaces work in PHP? | Namespaces and Use when to use and for what purpose?
– Woss
Okay, thanks, I don’t know if I delete that question or mark as seen
– Vitor