unable to call runkit_class_adopt multiple times on single class #46

Closed
kkozlik opened this Issue Mar 20, 2013 · 5 comments

Comments

Projects
None yet
3 participants

kkozlik commented Mar 20, 2013

If I call following code using runkit from actual master branch (2013-03-20) the second call of runkit_class_adopt() function does not work. With runkit-1.0.3 it works fine.

class myParent {
  function parentFunc() {
    echo "Parent Function Output\n";
  }
}

class myParent2 {
  function parentFunc2() {
    echo "Parent 2 Function Output\n";
  }
}

class myChild {
}

runkit_class_adopt('myChild','myParent');
print_r(get_class_methods('myChild'));

runkit_class_adopt('myChild','myParent2');
print_r(get_class_methods('myChild'));

Expected result

(works with runkit-1.0.3 and older)

Array
(
    [0] => parentFunc
)
Array
(
    [0] => parentFunc
    [1] => parentFunc2
)

Actual result

Array
(
    [0] => parentFunc
)
Warning: runkit_class_adopt(): Class myChild already has a parent in /var/lib/frafos-sbc-gui/webmin-module/runkit.php.cgi on line 22 
Array
(
    [0] => parentFunc
)
Contributor

tony2001 commented Oct 15, 2014

It's not supposed to work and the code checking for existing parent is there since 2005.
So I kind of doubt your code ever worked correctly.

kkozlik commented Oct 15, 2014

I am using runkit since beginning as replacement for aggregate_methods() function from PHP4. And this has been working perfectly all the times. It's quite funny that it has not been supposed to work :-). Apparently the checking code did not work earlier :-).

Contributor

tony2001 commented Oct 15, 2014

I fail to see how it could not work:

cf33fe5d (pollita         2005-04-29 23:55:01 +0000 223) PHP_FUNCTION(runkit_class_adopt)
cf33fe5d (pollita         2005-04-29 23:55:01 +0000 224) {
cf33fe5d (pollita         2005-04-29 23:55:01 +0000 225)        zend_class_entry *ce, *parent;
cf33fe5d (pollita         2005-04-29 23:55:01 +0000 226)        char *classname, *parentname;
cf33fe5d (pollita         2005-04-29 23:55:01 +0000 227)        int classname_len, parentname_len;
cf33fe5d (pollita         2005-04-29 23:55:01 +0000 228) 
7e8032d4 (pollita         2005-10-31 05:48:08 +0000 229)        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s/s/", &classname, &classname_len, &parentname, &parentname_len) == FAILURE) {
cf33fe5d (pollita         2005-04-29 23:55:01 +0000 230)                RETURN_FALSE;
cf33fe5d (pollita         2005-04-29 23:55:01 +0000 231)        }
cf33fe5d (pollita         2005-04-29 23:55:01 +0000 232) 
cf33fe5d (pollita         2005-04-29 23:55:01 +0000 233)        if (php_runkit_fetch_class(classname, classname_len, &ce TSRMLS_CC) == FAILURE) {
cf33fe5d (pollita         2005-04-29 23:55:01 +0000 234)                RETURN_FALSE;
cf33fe5d (pollita         2005-04-29 23:55:01 +0000 235)        }
cf33fe5d (pollita         2005-04-29 23:55:01 +0000 236) 
cf33fe5d (pollita         2005-04-29 23:55:01 +0000 237)        if (ce->parent) {
cf33fe5d (pollita         2005-04-29 23:55:01 +0000 238)                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Class %s already has a parent", classname);
cf33fe5d (pollita         2005-04-29 23:55:01 +0000 239)                RETURN_FALSE;
cf33fe5d (pollita         2005-04-29 23:55:01 +0000 240)        }

kkozlik commented Oct 15, 2014

I do not know. I don't understand the internals of runkit. But if you do not belive me, just try my example with PHP 5.3 and runkit 1.0.3 (or any older)

Owner

zenovich commented Aug 18, 2015

runkit_class_adopt did not change classes hierarchy in Runkit below version 1.0.4, so adopted classes in fact had no parent. The bug was fixed here: 7f5b7b1

zenovich closed this Aug 18, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment