Created
November 9, 2016 08:23
-
-
Save gorkamu/970503dd8b0398a5a016d1005501c9b6 to your computer and use it in GitHub Desktop.
Ejemplo de objeto
This file contains hidden or 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 | |
| class Numero | |
| { | |
| private $valor; | |
| public function __construct($valor) { | |
| $this->valor = $valor; | |
| } | |
| public function cualEsSuValor() { | |
| return $this->valor; | |
| } | |
| public function sumarUnidad() { | |
| $this->valor++; | |
| } | |
| public function restarUnidad() { | |
| $this->valor--; | |
| } | |
| } | |
| $numero = new Numero(5); | |
| echo $numero->cualEsSuValor(); // Imprime 5 | |
| $numero->sumarUnidad(); | |
| echo $numero->cualEsSuValor(); // Imprime 6 | |
| $numero->restarUnidad(); | |
| echo $numero->cualEsSuValor(); // Imprime 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment