Last active
November 6, 2017 17:16
-
-
Save yvan-sraka/fb82f5bc72231a84b9aea4bb1c3d7e59 to your computer and use it in GitHub Desktop.
Pokemon class example in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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