Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Class Competence
- * Пример утиной типизации.
- * Если нечто ходит как утка и крякает как утка, то это утка
- */
- class Competence {
- public $mood;
- public $name;
- /**
- * Competence constructor.
- * @param $mood
- * @param $name
- */
- public function __construct($mood, $name)
- {
- $this->mood = $mood;
- $this->name = $name;
- }
- public function equal($obj) {
- $cl = new ReflectionClass($obj);
- if ($cl->hasProperty('mood') && $cl->hasProperty('name')) {
- if ($obj->mood == $this->mood && $obj->name == $this->name)
- return true;
- }
- return false;
- }
- }
- class SomeClass
- {
- public $some_thing;
- }
- $competence = new Competence('good', 'Programming');
- $compy = new Competence('bad', 'Programming');
- $smth = new SomeClass();
- echo $competence->equal($compy);
- echo $competence->equal($smth);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement