AOP-PHP / AOP

AOP in PHP
Other
565 stars 95 forks source link

Pointcut on certain internal functions causing "could not obtain parameters" #99

Open yogeshpandey009 opened 8 years ago

yogeshpandey009 commented 8 years ago
<?php
aop_add_around('array_push()', 'aroundSystemCall');
function aroundSystemCall (AopJoinPoint $joinpoint) {
    echo "Called before invoking -> {$joinpoint->getFunctionName()} with args: ", print_r($joinpoint->getArguments(), true);
    return $joinpoint->process(); //Issue: crashing for some system functions
    // Workaround: to use call_user_func_array instead
    //return call_user_func_array($joinpoint->getFunctionName(), $joinpoint->getArguments());
}
$a = array();
array_push($a, "apple");
print_r($a);

Warning: array_push(): could not obtain parameters for parsing

Same error for mysql_query() $ php -v PHP 5.4.14 (cli) (built: Jun 27 2016 14:02:51) (DEBUG) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

yogeshpandey009 commented 8 years ago

Workaround: comment out _zval_ptrdtor(&obj->value) insde aop.c:get_aopJoinpoint()

if (Z_REFCOUNT_P(aop_object) == 1) {
    AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(aop_object TSRMLS_CC);
    if (obj->value) {
        zval_ptr_dtor(&obj->value); // is causing ((zval**)ex->function_state.arguments)[-1] value corruption
    }

@Juliens : Could you please share some proper fix for this issue. Thanks!

juliens commented 8 years ago

Commenting out this line doesn't fix the issue.

Warning: array_push(): could not obtain parameters for parsing in /home/juliens/devext/c/AOP/tests/issues/array_push_around.php on line 5

The problem seems to be elsewhere.

yogeshpandey009 commented 8 years ago

Oh sorry I forgot to mention. This fixes "before" pointcut for multiple executions of array_push()

<?php
aop_add_before('array_push()', 'beforeSystemCall');
function beforeSystemCall (AopJoinPoint $joinpoint) {
    echo "Called before invoking -> {$joinpoint->getFunctionName()} with args: ", print_r($joinpoint->getArguments(), true);
}
$a = array();
array_push($a, "apple");
array_push($a, "banana");
array_push($a, "mango");
print_r($a);