PHP classes, syntax errors when using "var" to declare variables

I am a C # guy trying to translate part of my understanding of OOP into php. I try to create my first class object and click on a few hooks.

Here is the start 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 get errors when using, when I use var, and I am embarrassed. I know that I don’t need to use var or declare variables at all, but I think this is better.

error "unexpected T_VAR awaiting T_VARIABLE"

When I just remove var from declarations, it works. Why is this?

+3
1

. PHP 5

var $uid;

PHP 5

private $uid; // or
protected $uid; // or
public $uid;

:

.. PHP 4, PHP 5 var ( ) public, protected private. var . PHP 5.0 5.1.3 var E_STRICT, PHP 5.1.3 . var public, protected private, PHP 5 , .

+11

Source: https://habr.com/ru/post/1747662/


All Articles