-2
people, where’s the problem? instantiating directly the classes validaNome and validaSobrenome they work, now in class msgContato they return NULL, where I’m going wrong?
validationName
class validaNome {
    public $ico_warning, $ico_success;
    public function setNome($nome) {
        if (empty($nome)) :
            return '<b class="ico_msg error"><i class="fas fa-engine-warning"></i> Nome está vazio.</b>';
        elseif (strlen($nome) < 3) :
            return '<b class="ico_msg error"><i class="fas fa-engine-warning"></i> Nome tem que ter mais de 3 caracteres.</b>';
        elseif (strlen($nome) > 25) :
            return '<b class="ico_msg error"><i class="fas fa-engine-warning"></i> Nome no maximo 25 caracteres.</b>';
        else :
            return $nome;
        endif;
    }
}
validationSobrenome
class validaSobrenome {
    public $ico_warning, $ico_success;
    public function setSobrenome($sobrenome) {
        if (empty($sobrenome)) :
            return '<b class="ico_msg error"><i class="fas fa-engine-warning"></i> Sobrenome está vazio.</b>';
        elseif (strlen($sobrenome) < 3) :
            return '<b class="ico_msg error"><i class="fas fa-engine-warning"></i> Sobrenome tem que ter mais de 3 caracteres.</b>';
        elseif (strlen($sobrenome) > 25) :
            return '<b class="ico_msg error"><i class="fas fa-engine-warning"></i> Sobrenome no maximo 25 caracteres.</b>';
        else :
            return $sobrenome;
        endif;
    }
}
msgContact
class msgContato {
    private $v_nome, $p_nome, $v_sobrenome, $p_sobrenome, $v_email, $p_email, $v_assunto, $p_assunto, $v_mensagem, $p_mensagem, $crud;
    public function getContato($nome, $sobrenome) {
        $this->v_nome = new validaNome;
        $this->v_sobrenome = new validaSobrenome;
        $this->v_nome->setNome(''.$nome.'');
        $this->v_sobrenome->setSobrenome(''.$sobrenome.'');
    }
}
$a = new msgContato;
var_dump($a->getContato('aaaaaaaa', 'aaaaaaaaaaaaaa'));
						
Your code is wrong everywhere.
– novic
@Virgilionovic as well?
– goio
Methods do not do what you expect not to have Return etc. What you intend to do?
– novic
@Virgilionovic apologizes for the delay, I ran out of internet, so that would be a simple validation for a contact form
– goio
See the return of @Augusto Vasques, your class is not NULL. Another thing, it’s confusing and very strange the way you structured your classes for a simple validation.You created 2 classes for 2 validations, why not just create one class ? Better, why not put the validations only in the assignment methods of
$v_nomeand$v_sobrenomeif this is really all you want to validate ? There are N ways to do what you want, restructure everything that will be better.– 8biT