I am just learning PHP so I know very little about it...
I am trying to compile the following code from a PHP 5 book:
<?php
//define class for tracking users
class User {
//properties
public $uname;
private $pword, $lastLogin;
//methods
public function __construct($aname, $apword) {
$this->uname = $aname;
$this->pword = $apword;
$this->lastLogin = time();
$this->accesses++;
}
//get the date of hte last login
function getLastLogin() {
return(date("M d Y", $this->lastLogin));
}
}
//Create an instance of User
$user = new User("Leon", "sdf123");
//get the last login date
print($user->getLastLogin() . "<br>\n");
//print the user's name
print("$user->uname<br>\n");
?>
I copied the code word for word (with the exception of renaming some variables) but am getting the following error:
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in c:\program files\apache group\apache\htdocs\usingclasses.php on line 7
The book I am using is for PHP 5 however I have PHP 4.3.3.
What do I need to do to run this without errors?