Skip to content

Instantly share code, notes, and snippets.

@fajarwz
Created July 5, 2021 13:54
Show Gist options
  • Save fajarwz/d8d12448e6f5e3d1b6a326fe6aa736e3 to your computer and use it in GitHub Desktop.
Save fajarwz/d8d12448e6f5e3d1b6a326fe6aa736e3 to your computer and use it in GitHub Desktop.
PHP OOP example. Create class, object, get-set attribute
<?php
class animal {
public $name;
public $foot;
function setName($name) {
$this->name = $name;
}
function getName() {
return $this->name;
}
function setFoot($foot) {
$this->foot = $foot;
}
function getFoot() {
return $this->foot;
}
}
$animal1 = new animal();
$animal1->setName('Cat');
$animal1->setFoot(4);
echo "First animal is ". $animal1->getName() ."\n";
echo "It has ".$animal1->getFoot()." feet";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment