Demo\Example\IntroductionDemo::testSerializable PHP Method

testSerializable() public method

Method that checks if the current instance implementing Serializable interface
public testSerializable ( )
    public function testSerializable()
    {
        if ($this instanceof \Serializable) {
            echo get_class($this), ' implements `Serializable` interface now!', PHP_EOL;
            $reflection = new \ReflectionObject($this);
            echo "List of interfaces:", PHP_EOL;
            foreach ($reflection->getInterfaceNames() as $interfaceName) {
                echo '-> ', $interfaceName, PHP_EOL;
            }
            echo "List of traits:", PHP_EOL;
            foreach ($reflection->getTraitNames() as $traitName) {
                echo '-> ', $traitName, PHP_EOL;
            }
        } else {
            echo get_class($this), ' does not implement `Serializable` interface', PHP_EOL;
        }
    }

Usage Example

Beispiel #1
0
        break;
    case 'human-advices':
        $aspectName = 'Demo\\Aspect\\HealthyLiveAspect';
        $example = new HumanDemo();
        echo "Want to eat something, let's have a breakfast!", PHP_EOL;
        $example->eat();
        echo "I should work to earn some money", PHP_EOL;
        $example->work();
        echo "It was a nice day, go to bed", PHP_EOL;
        $example->sleep();
        break;
    case 'dynamic-traits':
        $aspectName = 'Demo\\Aspect\\IntroductionAspect';
        $example = new IntroductionDemo();
        // Original class doesn't implement Serializable
        $example->testSerializable();
        break;
    case 'declare-errors':
        $aspectName = 'Demo\\Aspect\\DeclareErrorAspect';
        $example = new ErrorDemo();
        $example->oldMethod();
        $example->notSoGoodMethod();
        break;
    default:
}
?>
  </pre></div>
  <div class="panel-group" id="accordion">
<?php 
// Conditional block with source code of aspect
if ($aspectName) {
IntroductionDemo