PHP code example of aop-io / php-aop

1. Go to this page and download the library: Download aop-io/php-aop library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aop-io / php-aop example snippets


use Aop\Aop;

// Init
new Aop();

function hello($name)
{
    return $name
}

// Interception of kind 'around'
Aop::addAround('hello()', function($joinPoint) {

    // In this context,
    // $joinPoint is an instance of \Aop\JoinPoint\AroundFunctionJoinPoint

    // get an array with all arguments values
    var_dump($joinPoint->getArgs()); // (array) 0 => World !

    // change the return value
    $joinPoint->setReturnValue('Hello Nico !');

    // Proceed the execution of the function ( hello() )
    $joinPoint->proceed();
});

echo hello('World !'); // Hello Nico !