Skip to content

Instantly share code, notes, and snippets.

@gustavoalvesdev
Created August 6, 2022 19:01
Show Gist options
  • Save gustavoalvesdev/49bced472de3c23b5561955b38e4949f to your computer and use it in GitHub Desktop.
Save gustavoalvesdev/49bced472de3c23b5561955b38e4949f to your computer and use it in GitHub Desktop.
Exemplo de como usar method overloading no PHP
<?php
class Poly {
public function __call($name, $arg) {
if ($name == 'test') {
switch(count($arg)) {
case 0:
return 'Test without argument';
break;
case 1:
return 'Test with an argument ' . $arg[0];
}
}
}
}
$poly = new Poly();
print $poly->test() . PHP_EOL;
print $poly->test('Look at me!') . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment