Created
August 6, 2022 19:01
-
-
Save gustavoalvesdev/49bced472de3c23b5561955b38e4949f to your computer and use it in GitHub Desktop.
Exemplo de como usar method overloading no PHP
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 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