Skip to content

Instantly share code, notes, and snippets.

@acapps
Created March 30, 2017 00:37
Show Gist options
  • Save acapps/c0ec9ea0b7b4a97fc3f71687461d254a to your computer and use it in GitHub Desktop.
Save acapps/c0ec9ea0b7b4a97fc3f71687461d254a to your computer and use it in GitHub Desktop.
<?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.');
@acapps
Copy link
Author

acapps commented Mar 30, 2017

In the example above the value of 1 is echoed to STDOUT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment