Skip to content

Commit

Permalink
The correction for the situation when a method or function having sta…
Browse files Browse the repository at this point in the history
…tic variables in itself and copied by runkit crashes afterwards on calling if the original method or function was removed.

This change corrects copying of static variables and adds the test for the described behaviour.
  • Loading branch information
zenovich committed Nov 11, 2009
1 parent f60ed0c commit 687bc07
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions runkit_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ void php_runkit_function_copy_ctor(zend_function *fe, char *newname)
zval tmpZval;

ALLOC_HASHTABLE(tmpHash);
zend_hash_init(tmpHash, 2, NULL, ZVAL_PTR_DTOR, 0);
zend_hash_copy(tmpHash, fe->op_array.static_variables, ZVAL_COPY_CTOR, &tmpZval, sizeof(zval));
zend_hash_init(tmpHash, zend_hash_num_elements(fe->op_array.static_variables), NULL, ZVAL_PTR_DTOR, 0);
zend_hash_copy(tmpHash, fe->op_array.static_variables, (copy_ctor_func_t) zval_add_ref, (void*) &tmpZval, sizeof(zval*));
fe->op_array.static_variables = tmpHash;
}

Expand Down
28 changes: 28 additions & 0 deletions tests/static_vars.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
redefining methods with static variables
--SKIPIF--
<?php if(!extension_loaded("runkit") || !RUNKIT_FEATURE_MANIPULATION) print "skip"; ?>
--INI--
error_reporting=E_ALL
display_errors=on
--FILE--
<?php

class A {
public function m() {
static $a = 0;
$a++;
return $a;
}
}

echo A::m(), "\n";

runkit_method_copy('A', 'm1', 'A', 'm');
runkit_method_remove('A', 'm');

echo A::m1();
?>
--EXPECT--
1
2

0 comments on commit 687bc07

Please sign in to comment.