1
How could I print on the screen the cpf
according to my code?
The code:
<?php
class valida {
protected $cpf;
public function cpf($cpf) {
if(is_numeric($cpf) and $cpf > 11) {
$this->cpf = $cpf;
return $cpf;
}
}
}
class manda extends valida {
function foo() {
return $this->cpf;
}
}
$cpf1 = $_GET['cpf'];
$p1 = new valida;
$p1->cpf($cpf1);
$sis = new manda;
echo $sis->foo();
What I’m doing wrong ?
I did it this way: https://ideone.com/wANBeV . It seems that the "Cpf" function is not checking the condition, that is any value/Cpf is being accepted. Could you help me ? Thank you :)
– user113606
I edited the answer.
– Marcelo Shiniti Uchimura
Lacked a
$this->
when calling the methodcpf
insidefoo
in the second code. And I wouldn’t particularly recommend treating CPF as numerical, because zeros on the left will be ignored, and if it is necessary to display it, I would have to undergo treatment to fill in the missing zeros. Easier to keep as string and dostrlen($cpf)
.– Woss
I did it this way and everything went right: https://ideone.com/Ws6Trl . Thank you and hugs.
– user113606