Skip to content

Instantly share code, notes, and snippets.

@gorkamu
Created November 9, 2016 08:23
Show Gist options
  • Select an option

  • Save gorkamu/970503dd8b0398a5a016d1005501c9b6 to your computer and use it in GitHub Desktop.

Select an option

Save gorkamu/970503dd8b0398a5a016d1005501c9b6 to your computer and use it in GitHub Desktop.
Ejemplo de objeto
<?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