10-classes - PHP Workshop 1 PHP Classes and Object...

Info iconThis preview shows pages 1–14. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: PHP Workshop 1 PHP Classes and Object Orientation PHP Workshop 2 Reminder a function Reusable piece of code. Has its own local scope. function my_func($arg1,$arg2) { << function statements >> } PHP Workshop 3 Conceptually, what does a function represent? give the function something (arguments), it does something with them, and then returns a result Action or Method PHP Workshop 4 What is a class ? Conceptually, a class represents an object , with associated methods and variables PHP Workshop 5 Class Definition <?php class dog { public $name; public function bark() { echo Woof! ; } } ?> An example class definition for a dog. The dog object has a single attribute, the name, and can perform the action of barking. PHP Workshop 6 Class Definition <?php class dog { public $name; public function bark() { echo Woof! ; } } ?> class dog { Define the name of the class. PHP Workshop 7 Class Definition <?php class dog { var $name public function bark() { echo Woof! ; } } ?> public $name; Define an object attribute (variable), the dogs name. PHP Workshop 8 Class Definition <?php class dog { public $name; function bark() { echo Woof! ; } } ?> public function bark() { echo Woof! ; } Define an object action (function), the dogs bark. PHP Workshop 9 Class Definition <?php class dog { public $name; public function bark() { echo Woof! ; } } ?> } End the class definition PHP Workshop 10 Class Defintion Similar to defining a function.. The definition does not do anything by itself . It is a blueprint, or description, of an object. To do something, you need to use the class PHP Workshop 11 Class Usage <?php require ( dog.class.php ); $puppy = new dog(); $puppy->name = Rover ; echo {$puppy->name} says ; $puppy->bark(); ?> PHP Workshop 12 Class Usage <?php require ( dog.class.php ); $puppy = new dog(); $puppy->name = Rover; echo {$puppy->name} says ; $puppy->bark(); ?> require ( dog.class.php ); Include the class definition PHP Workshop 13 Class Usage <?php require ( dog.class.php ); $puppy = new dog(); $puppy->name = Rover; echo {$puppy->name} says ; $puppy->bark(); ?> $puppy = new dog(); Create a new instance of the class. PHP Workshop...
View Full Document

This note was uploaded on 10/23/2011 for the course ENCS ENCS5 taught by Professor Abdelsalam during the Spring '10 term at Birzeit University.

Page1 / 38

10-classes - PHP Workshop 1 PHP Classes and Object...

This preview shows document pages 1 - 14. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online