| 1 | <?php |
||
| 16 | class IntroductionDemo |
||
| 17 | { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Method that checks if the current instance implementing Serializable interface |
||
| 21 | */ |
||
| 22 | public function testSerializable() |
||
| 23 | { |
||
| 24 | if ($this instanceof \Serializable) { |
||
| 25 | echo get_class($this), ' implements `Serializable` interface now!', PHP_EOL; |
||
| 26 | $reflection = new \ReflectionObject($this); |
||
| 27 | echo "List of interfaces:", PHP_EOL; |
||
| 28 | foreach ($reflection->getInterfaceNames() as $interfaceName) { |
||
| 29 | echo '-> ', $interfaceName, PHP_EOL; |
||
| 30 | } |
||
| 31 | echo "List of traits:", PHP_EOL; |
||
| 32 | foreach ($reflection->getTraitNames() as $traitName) { |
||
| 33 | echo '-> ', $traitName, PHP_EOL; |
||
| 34 | } |
||
| 35 | } else { |
||
| 36 | echo get_class($this), ' does not implement `Serializable` interface', PHP_EOL; |
||
| 37 | } |
||
| 38 | } |
||
| 39 | } |
||
| 40 |