You cannot echo an object unless you implement the __toString() function (which you will learn about furthur down the road).
In php4, the constructor is the name of the class, which is called when the class is initialized.
Constructors cannot return anything. What you want to do is create another method to retrieve the data.
Secondly, you access the class properties using $this. I.e., $this->loginTime;
Thirdly, when declaring variables you cannot call a function, i.e. var $loginTime = time(); is not valid
Fourthly, any parameters to methods you do not give a default value to are considered required. In your login::login() method you have 2 parameters, but you are only pass one. I think you only wanted to pass the first parameter.
To make your example work,
Code: Select all
class master {
function getTime() {
return time();
}
}
class login extends master {
var $result;
function login($loginUsername) {
$loginText = "result: ".$loginUsername." time: ". $this->getTime();
$this->result = $loginText
}
function getResult() {
return $this->result;
}
}
$echo = new login($_POST['username']);
echo $echo->getResult();
(is that a security risk using it as a class variable before checking it ?)
Generally you should not access class variables from outside the class scope. Meaning, you should be using setters and getters to change the class properties from outside the object.
Side note, I would recommend you pick up php5 for OOP