Created
March 30, 2017 00:37
-
-
Save acapps/c0ec9ea0b7b4a97fc3f71687461d254a to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Interface ApplicantAPI | |
*/ | |
interface ApplicantAPI { | |
/** | |
* @param $title | |
* @return int|null | |
*/ | |
public function title($title); | |
} | |
class A implements ApplicantAPI { | |
/** | |
* @param $title | |
* @return int|null | |
*/ | |
public function title($title) { | |
switch ($title) { | |
case 'Mr.' : | |
return 1; | |
case 'Mrs.' : | |
return 2; | |
case 'Ms.' : | |
return 3; | |
case 'Miss' : | |
return 4; | |
} | |
return null; // Return null or throw an exception. | |
} | |
} | |
class B implements ApplicantAPI { | |
/** | |
* @param $title | |
* @return int|null | |
*/ | |
public function title($title) { | |
switch ($title) { | |
case 'Mr.' : | |
return 10; | |
case 'Mrs.' : | |
return 20; | |
case 'Ms.' : | |
return 30; | |
case 'Miss' : | |
return 40; | |
} | |
return null; // Return null or throw an exception. | |
} | |
} | |
$applicantAPI = new A(); | |
echo $applicantAPI->title('Mr.'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the example above the value of
1
is echoed to STDOUT.