Permalink
Browse files

fix for PHP4

  • Loading branch information...
1 parent c592699 commit 7d99f95d2d251a70205b8ed7b7149095011f1852 @zenovich committed May 18, 2013
Showing with 16 additions and 17 deletions.
  1. +12 −12 runkit_classes.c
  2. +2 −2 runkit_methods.c
  3. +1 −1 tests/bug57649.inc
  4. +1 −2 tests/bug57649.phpt
View
@@ -149,15 +149,21 @@ static int php_runkit_inherit_methods(zend_function *fe, zend_class_entry *ce TS
int php_runkit_class_copy(zend_class_entry *src, const char *classname, int classname_len TSRMLS_DC)
{
zend_class_entry *new_class_entry;
+ char *lcname;
+ lcname = estrndup(classname, classname_len);
+ php_strtolower(lcname, classname_len);
-#ifndef ZEND_ENGINE_2
new_class_entry = emalloc(sizeof(zend_class_entry));
-
+ new_class_entry->parent = NULL;
+ if (src->parent && src->parent->name) {
+ php_runkit_fetch_class_int(src->parent->name, src->parent->name_length, &new_class_entry->parent TSRMLS_CC);
+ }
+#ifndef ZEND_ENGINE_2
new_class_entry->type = ZEND_USER_CLASS;
new_class_entry->name = estrdup(classname);
new_class_entry->name_length = classname_len;
new_class_entry->refcount = (int *) emalloc(sizeof(int));
- *(new_class_entry->refcount) = 1;
+ *(new_class_entry->refcount) = 0;
new_class_entry->constants_updated = 0;
zend_hash_init(&new_class_entry->function_table, 10, NULL, ZEND_FUNCTION_DTOR, 0);
@@ -167,13 +173,9 @@ int php_runkit_class_copy(zend_class_entry *src, const char *classname, int clas
new_class_entry->handle_property_set = src->handle_property_set;
new_class_entry->handle_property_get = src->handle_property_get;
- new_class_entry->parent = src->parent;
-
- zend_hash_update(CG(class_table), new_class_entry->name, classname_len, new_class_entry, sizeof(zend_class_entry), (void **) &new_class_entry);
+ zend_hash_update(EG(class_table), lcname, classname_len+1, new_class_entry, sizeof(zend_class_entry), NULL);
+ efree(new_class_entry);
#else
- char *lcname;
-
- new_class_entry = emalloc(sizeof(zend_class_entry));
new_class_entry->type = ZEND_USER_CLASS;
new_class_entry->name = estrndup(classname, classname_len);
new_class_entry->name_length = classname_len;
@@ -196,13 +198,11 @@ int php_runkit_class_copy(zend_class_entry *src, const char *classname, int clas
#endif
new_class_entry->ce_flags = src->ce_flags;
- lcname = zend_str_tolower_dup(classname, classname_len);
zend_hash_update(EG(class_table), lcname, classname_len + 1, &new_class_entry, sizeof(zend_class_entry *), NULL);
- efree(lcname);
-
new_class_entry->num_interfaces = src->num_interfaces;
#endif
+ efree(lcname);
return SUCCESS;
}
/* }}} */
View
@@ -97,15 +97,15 @@ int php_runkit_fetch_class_int(const char *classname, int classname_len, zend_cl
if (zend_hash_find(EG(class_table), lclass, classname_len + 1, (void*)&ze) == FAILURE ||
!ze || !*ze) {
efree(lclass);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "class %s not found", classname);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Class %s not found", classname);
return FAILURE;
}
ce = *ze;
#else
if (zend_hash_find(EG(class_table), lclass, classname_len + 1, (void*)&ce) == FAILURE ||
!ce) {
efree(lclass);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "class %s not found", classname);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Class %s not found", classname);
return FAILURE;
}
#endif
View
@@ -1,6 +1,6 @@
<?php
class a {
- public function foo() {
+ function foo() {
echo "foo()\n";
}
}
View
@@ -2,12 +2,11 @@
Bug#57649 - runkit_import() - methods not added - multiple classes in one file
--SKIPIF--
<?php if(!extension_loaded("runkit")) print "skip";
- if(version_compare(PHP_VERSION, '5.0.0', '<')) print "skip";
?>
--FILE--
<?php
class b {
- public function foobar() {
+ function foobar() {
echo "foobar()\n";
}
}

0 comments on commit 7d99f95

Please sign in to comment.