Last active
December 4, 2016 11:25
-
-
Save gorkamu/f6c60c96029c7fbf81c1b2635de39c90 to your computer and use it in GitHub Desktop.
Ejemplo de sobrecarga de métodos
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 Gorkamu | |
{ | |
public function __call($method_name, $arguments) | |
{ | |
if(count($arguments) == 0) { | |
$this->saluda1(); | |
} elseif(count($arguments) == 1) { | |
$this->saluda2($arguments[0]); | |
} elseif(count($arguments) == 2) { | |
$this->saluda3($arguments[0], $arguments[1]); | |
} else { | |
return false; | |
} | |
} | |
public function saluda1() | |
{ | |
echo "Hola".PHP_EOL; | |
} | |
public function saluda2($nombre) | |
{ | |
echo "Hola $nombre".PHP_EOL; | |
} | |
public function saluda3($nombre, $apellido) | |
{ | |
echo "Hola $nombre $apellido".PHP_EOL; | |
} | |
} | |
$gorkamu = new Gorkamu(); | |
$gorkamu->saluda(); | |
$gorkamu->saluda("hamijo"); | |
$gorkamu->saluda("shurs", "de fc"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment