I’m running Eclipse Indigo with PDT and Xdebugger (all latest versions) and a LAMP server on Ubuntu 11.04.
While debugging, an object function (see code below) won’t execute; the debugger just defaults – the variables window goes completely blank and it just freezes up. The page won’t load either, it just stays in a loading state.
Everything is fine up to the point where I start calling functions on the object.
Suggestions?
Here’s the code:
<?php
require_once 'user.php';
require_once 'fetcher.php';
require_once 'inscriber.php';
$uname=$_POST['regname'];
$upass=$_POST['regpass'];
$ufirst=$_POST['regfirst'];
$ulast=$_POST['reglast'];
$uemail=$_POST['regemail'];
$uphone=$_POST['regphone'];
$user = new User();
$user->setUsername($uname); // THIS IS WHERE IT FREEZES UP
$user->setPassword($upass);
$user->setFirstname($ufirst);
$user->setLastname($ulast);
$user->setEmail($uemail);
$user->setPhone($uphone);
$inscriber = Inscriber::getInscriberInstance();
$success = $inscriber->inscribeUser($user);
?>
<?php
class User{
private $username;
private $password;
private $userID;
private $firstname;
private $lastname;
private $phone;
private $email;
public function getUsername(){
return $username;
}
public function setUsername($var){
$this->$username = $var;
}
///
public function getPassword(){
return $password;
}
public function setPassword($var){
$this->$password = $var;
}
///
public function getUserID(){
return $userID;
}
public function setUserID($var){
$this->$userID = $var;
}
///
public function getFirstname(){
return $firstname;
}
public function setFirstname($var){
$this->$firstname = $var;
}
///
public function getLastname(){
return $lastname;
}
public function setLastname($var){
$this->$lastname = $var;
}
///
public function getPhone(){
return $phone;
}
public function setPhone($var){
$this->$phone = $var;
}
///
public function getEmail(){
return $email;
}
public function setEmail($var){
$this->$email = $var;
}
}
This is a “dynamic property”. PHP tries to replace
$usernamewith the content of the variable. The variable doesn’t exists, so the resulting$this-> = $varjust fails(non-static) properties are always called without the
$.Additional in the getters you are using local variables
Don’t know, why you (at least try to) use properties in setters, but use local variables in getters
Sidenote: “objects functions” are called “methods”