Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class People {
- public $name;
- public function setName($x) {
- $this->name = $x;
- }
- }
- class Tuna {
- public $fish1 = "stinky";
- private $fish2 = "smellgoody";
- public function sayName() {
- echo $this->fish2;
- }
- }
- class Beef {
- private $cowsName;
- //setter (sets private variable)
- public function setCowsName($x) {
- $this->cowsName = $x;
- }
- //getter (retrieves private variables)
- public function getCowsName(){
- return $this->cowsName;
- }
- }
- ?>
- <html>
- <head>
- <title>PHP Objects</title>
- </head>
- <body>
- <?php
- $person1 = new People();
- $person1->setName('Chris');
- echo $person1->name;
- echo "<br />";
- $fish = new Tuna();
- echo $fish->fish1;
- $fish->sayName();
- echo "<br />";
- $cowObject = new Beef;
- echo $cowObject->setCowsName('Chris');
- echo $cowObject->getCowsName();
- echo $cowObject->setCowsName(' & Missy');
- echo $cowObject->getCowsName();
- ?>
- </body>
- </html>
- <!--
- Class
- Holder for data
- variable == field
- Object
- Way to access info in classes
- -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement