Skip to content

Instantly share code, notes, and snippets.

@yvan-sraka
Last active November 6, 2017 17:16
Show Gist options
  • Save yvan-sraka/fb82f5bc72231a84b9aea4bb1c3d7e59 to your computer and use it in GitHub Desktop.
Save yvan-sraka/fb82f5bc72231a84b9aea4bb1c3d7e59 to your computer and use it in GitHub Desktop.
Pokemon class example in PHP
<?php
// version 1 of class Pokemon
class Pokemon {
public $name;
public $level;
public $pv;
public function attack($name) {
echo $this->name." launch attack ".$name;
}
}
// Create an object
$pikachu = new Pokemon;
// Set attributes of the object
$pikachu->name = "Pickachu";
$pikachu->level = 0;
$pikachu->pv = 60;
// Launch the attack "Thunderbolt"
$pikachu->attack("Thunderbolt");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment