From 1bad4fc00814e2c03ecadaa7faf93c6372f5bd30 Mon Sep 17 00:00:00 2001 From: Kyle Kaminski Date: Sun, 16 Jun 2013 03:25:26 -0500 Subject: initial commit --- class_ex.php | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 class_ex.php (limited to 'class_ex.php') diff --git a/class_ex.php b/class_ex.php new file mode 100644 index 0000000..710a28b --- /dev/null +++ b/class_ex.php @@ -0,0 +1,72 @@ + + + +Hacker's Corner + + + +

Beyond The Basics?

+ +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() . "
\n"; + +$me = clone $person; +$me->lname = "K"; +echo $me->fullname() . "
\n"; + +echo "total ids: " . Person::$id . "
\n"; + +?> + +

+== is like memcmp in C, it compares whole classes and attributes
+=== is like == in C, simply comparing references
+

+ + + + + -- cgit v1.2.3