Testing the "Array Index"

Define a class ("user"), initialize an instance using the "new" operator. Note that PHP code is invisible using view source except for HTML tags output in a print statement, in this case <br />
Core PHP Programming page 64.

Begin PHP output

Sunday Jun 24 2018 01:0 PM
Leon


END PHP output

<?

/* Define class for tracking users */
class user
{
  /*
  ** Properties
  */
  var $name;
  var $password;
  var $last_login;
  
  /*
  ** Methods
  */
  // Sets all the properties
  function init($inputName, $inputPassword)
  {
    $this->name = $inputName;
    $this->password = $inputPassword;
    $this->last_login = time();
  }
  // Get the date of the last login
  function getLastLogin()
  {
    return(Date("M d Y", $this->last_login));
  }
  /*
  ** Create an instance and then initialize
  */
  
  $currentUser = new user;
  $currentUser->init("Leon", "adf123");
  
    /*
  ** Get the last login date
  */
  
  print($currentUser->getLastLogin());
  print("
\n"); /* ** Print the users name */ print($currentUser->name); print("
\n"); ?>

Back to Bill's PHP