@@ -38,46 +38,18 @@ ClassImpl::~ClassImpl()
3838 */
3939static ClassImpl *self (zend_class_entry *entry)
4040{
41- #if PHP_VERSION_ID >= 50400
42-
43- /* *
44- * somebody could have extended this class from PHP userland, in which
45- * case trying to dereference the doc_comment would result in a disaster
46- * because it does not point to a class implemented by PHP-CPP at all!
47- *
48- * if this happens we need to keep going until we find the object that
49- * was implemented by us. For this we are going to make the assumption
50- * that we are the only ones misusing the doc_comment the way we do.
51- *
52- * Usually the doc_comment is not set (it equals the nullptr) and if it
53- * is set, the accompanying doc_comment_len should be non-zero to
54- * indicate the number of characters in it.
55- */
56- while (entry->parent && entry->info .user .doc_comment == nullptr && entry->info .user .doc_comment_len == 0 )
57- {
58- // we did not create this class entry, but luckily we have a parent
59- entry = entry->parent ;
60- }
41+ // we need the base class (in user space the class may have been overridden,
42+ // but we are not interested in these user space classes)
43+ while (entry->parent ) entry = entry->parent ;
6144
45+ #if PHP_VERSION_ID >= 50400
6246 // retrieve the comment (it has a pointer hidden in it to the ClassBase object)
6347 const char *comment = entry->info .user .doc_comment ;
6448
6549 // the first byte of the comment is an empty string (null character), but
6650 // the next bytes contain a pointer to the ClassBase class
6751 return *((ClassImpl **)(comment + 1 ));
6852#else
69-
70- /* *
71- * This is likely not correct: If the class was extended using PHP-CPP
72- * itself, we should retrieve the ClassImpl directly, however there is
73- * no sane way to check this here, unlike in PHP 5.4.
74- *
75- * We therefore always go to the very base, of which we are sure that
76- * we are the implementers. This way - at least - we don't cause any
77- * segfaults.
78- */
79- while (entry->parent ) entry = entry->parent ;
80-
8153 // on php 5.3 we store the pointer to impl after the name in the entry
8254 ClassImpl** impl = (ClassImpl**)(entry->name + 1 + entry->name_length );
8355
@@ -504,7 +476,7 @@ int ClassImpl::cast(zval *val, zval *retval, int type TSRMLS_DC)
504476
505477 // @todo do we turn into endless conversion if the __toString object returns 'this' ??
506478 // (and if it does: who cares? If the extension programmer is stupid, why do we have to suffer?)
507-
479+
508480 // is the original parameter overwritten?
509481 if (val == retval) zval_dtor (val);
510482
0 commit comments