PHP classes, parse syntax errors when using 'var' to declare variables
Posted
by jon
on Stack Overflow
See other posts from Stack Overflow
or by jon
Published on 2010-05-29T13:06:40Z
Indexed on
2010/05/29
13:12 UTC
Read the original article
Hit count: 172
I am a C# guy trying to translate some of my OOP understanding over to php. I'm trying to make my first class object, and are hitting a few hitches.
Here is the beginning of the class:
<?php
require("Database/UserDB.php");
class User {
private var $uid;
private var $username;
private var $password;
private var $realname;
private var $email;
private var $address;
private var $phone;
private var $projectArray;
public function _construct($username) {
$userArray = UserDB::GetUserArray($username);
$uid = $userArray['uid'];
$username = $userArray['username'];
$realname = $userArray['realname'];
$email = $userArray['email'];
$phone = $userArray['phone'];
$i = 1;
$projectArray = UserDB::GetUserProjects($this->GetID());
while($projectArray[$i] != null) {
$projectArray[$i] = new Project($projectArray[$i]);
}
UserDB.php is where I have all my static functions interacting with the Database for this User Class. I am getting errors using when I use var, and I'm getting confused. I know I don't HAVE to use var, or declare the variables at all, but I feel it is a better practice to do so.
the error is "unexpected T_VAR, expecting T_VARIABLE"
When I simply remove var from the declarations it works. Why is this?
© Stack Overflow or respective owner