Last active
January 30, 2020 13:13
-
-
Save akash-coded/b9702121d7f735f12fa41234aa9ffe02 to your computer and use it in GitHub Desktop.
PHP function overloading with __call()
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 OverloadingTest | |
{ | |
public function __call($method, $params) | |
{ | |
if($method === "select") | |
{ | |
$this->testing1($params[0]); | |
} elseif($method === "insert") { | |
$this->testing2($params[0], | |
$params[1]); | |
} elseif($method === "delete") { | |
$this->testing3($params[0], | |
$params[1], | |
$params[2]); | |
} | |
} | |
public function testing1($arg1) | |
{ | |
print_r(func_num_args()); | |
echo "</br>"; | |
print_r(func_get_args()); | |
echo "</br>"; | |
echo $arg1."</br></br>"; | |
} | |
public function testing2($arg1, $arg2) | |
{ | |
print_r(func_num_args()); | |
echo "</br>"; | |
print_r(func_get_args()); | |
echo "</br>"; | |
echo "{$arg1}, {$arg2} </br></br>"; | |
} | |
public function testing3($arg1, $arg2, $arg3) | |
{ | |
print_r(func_num_args()); | |
echo "</br>"; | |
print_r(func_get_args()); | |
echo "</br>"; | |
echo "{$arg1}, {$arg2}, {$arg3} </br></br>"; | |
} | |
} | |
$obj = new OverloadingTest(); | |
$obj->select('Akash Das'); | |
$obj->insert('Akash Das', 14); | |
$obj->delete('Akash Das', 14, 'CS166355'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment