|
What is Class !: (PHP year 2006 )
|
 Let us summarize how to define a class, properties, methods, scope as
public or private.
- Private : Public : private variables/functions can be used within the class;
- A public
function can relay the variable outside the class.
- The line
//print("$members->pwd<br>\n"); would throw an
error.
(<-click this link)
|
<html>
<head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Class explained</title> </head>
<body text="#FFFF00" bgcolor="#000080"> Please enter a name and password in the box <br> <form id="exception_form" method="POST" action="what_is_class.php5"> <p><input type="text" name="T1" size="20"><br> <input type="text" name="T2" size="20"><br> <input type="submit" value="Submit" name="B1" > <input type="reset" value="Reset" name="B2"></p> </form>
<?php //define class for tracking members $y=$_POST['T1']; $p=$_POST['T2']; if ($y=="" or $p=="") { exit;}
class members { //properties public $name; private $pwd, $prev_Login;
//methods public function __construct($name, $pwd) { $this->name = $name; $this->pd = $pwd; $this->prev_Login = time(); $this->accesses++; }
// get the date of the prev_ login function getprev_Login() { return(date("M d Y", $this->prev_Login)); } function get_pwd() { return($this->pd); }
}
//create an instance the class members $members = new members($y, $p); //get the prev_ login date print($members->getprev_Login() ."<br>\n"); //print the members name print("welcome : $members->name<br>\n"); //get the prev_ login date print("your pwd: "); print($members->get_pwd() ."<br>\n"); //print("$members->pd<br>\n");
?> </body>
</html>
|
 |
| error 
|
| |