0
I made my transition from Java to PHP and recently bumped into something I used to do in Java but am not able to do in php.
The following code creates an object of type "User"
public function validateUser() {
//Check if information entered by user is valid
$user = new User($_POST);
new UserControl($user);
}
I need to do a validation if Cpf is numeric before proceeding with the validation with the formula. In Java I would use something like:
int cpf = this.getUser().getUserCpf();
The php code looks like this:
class UserControl {
private $user;
public function __construct($user) {
$this->setUser($user);
}
public function validateIntegers() {
$cpf = $this->getUser()->getUserCpf();
is_numeric($cpf);
}
But the same logic does not apply. Is there any other way to use this object orientation in PHP? Or is it not possible to do something like this?
What is Chaining of Methods?
– rray
I couldn’t understand exactly where the problem is.
$cpf
comes void?– rray
Exactly. $Cpf is normal after creating the User object, but when I pass $user as a parameter to build the Usercontrol class it is null.
– Joao Pedro
Put the code of
getUser()
– rray
public Function getUser() { Return $this->user; }
– Joao Pedro
I have to cast this as Return (Object) $this->user;?
– Joao Pedro
No need to cast. Need to debug or give a few
var_dump()
to find the problem location, looking at this code seems correct.– rray
I found the error... was like this:
new DbrControl();


require_once "../model/User.php";


require_once "./UserControl.php";
I did this:require_once "../model/User.php";


require_once "./UserControl.php";


new DbrControl();
, and it worked– Joao Pedro