Skip to content

Instantly share code, notes, and snippets.

@gorkamu
Last active December 4, 2016 11:25
Show Gist options
  • Save gorkamu/f6c60c96029c7fbf81c1b2635de39c90 to your computer and use it in GitHub Desktop.
Save gorkamu/f6c60c96029c7fbf81c1b2635de39c90 to your computer and use it in GitHub Desktop.
Ejemplo de sobrecarga de métodos
<?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