blob: 710a28b41367d54ae74c3e7c84dadb159ab289dd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hacker's Corner</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h2>Beyond The Basics?</h2>
<?php
class Person
{
public $name; /* good convention to put public explicitly */
public $lname; /* but public in front of 'var' errors out yo */
/* should I just avoid var modifier */
/* var public means public public, wrong! */
static $id = 0;
function __construct($name, $lname)
{
$this->name = $name;
$this->lname = $lname;
Person::$id++;
}
function __clone()
{
$this->increment(); /* we're cloning, creating another person, so increase count */
}
function fullname()
{
return $this->name . " " . $this->lname;
}
static function increment()
{
self::$id++; /* another way to mean Person:: */
}
}
class Employee extends Person
{
static function oneup()
{
parent::increment(); /* refer to parent's stuff */
}
};
$person = new Person("Kyle", "Broflovski");
echo $person->fullname() . "<br />\n";
$me = clone $person;
$me->lname = "K";
echo $me->fullname() . "<br />\n";
echo "total ids: " . Person::$id . "<br />\n";
?>
<p>
== is like memcmp in C, it compares whole classes and attributes<br />
=== is like == in C, simply comparing references<br />
</p>
</body>
</html>
|