How to resolve this duplicate name error?

Refresh

December 2018

Views

497 time

2

I want to create a native primitive data type extension, which can be good for strong typing. I have first defined an interface called ObjectInterface, and then a class called Object. Obviously, Object implements ObjectInterface, and I have this following code:

/* {{{ scalarclass_functions[]
 *
 * Every user visible function must have an entry in scalarclass_functions[].
 */
const zend_function_entry scalarclass_functions[] = {
        PHP_ABSTRACT_ME(ObjectInterface, equals, arginfo_object)
        PHP_ABSTRACT_ME(ObjectInterface, getClass, arginfo_void)
        PHP_ABSTRACT_ME(ObjectInterface, getClassName, arginfo_void)
        PHP_ABSTRACT_ME(ObjectInterface, hashCode, arginfo_void)
        PHP_ABSTRACT_ME(ObjectInterface, __toString, arginfo_void)
        PHP_ME(Object, equals, arginfo_object, ZEND_ACC_PUBLIC)
        PHP_ME(Object, getClass, arginfo_void, ZEND_ACC_PUBLIC)
        PHP_ME(Object, getClassName, arginfo_void, ZEND_ACC_PUBLIC)
        PHP_ME(Object, hashCode, arginfo_void, ZEND_ACC_PUBLIC)
        PHP_ME(Object, __toString, arginfo_void, ZEND_ACC_PUBLIC)
        PHP_FE_END      /* Must be the last line in scalarclass_functions[] */
};

Of course, this is just part of the code, and I did not show the method definition for object class' methods since the code can be a bit long and distracting. Then I run into a problem, it gave me duplicate name errors for object class' methods.

PHP Warning:  Function registration failed - duplicate name - equals in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - getClass in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - getClassName in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - hashcode in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - __toString in Unknown on line 0

It seems that the compiler cannot tell that the methods Object::equals() and ObjectInterface::equals() are different methods, instead it assumes they are the same and throws a duplicate name warning. How can I fix this issue?

I tried to define a second zend_function_entry struct, but it won't work either as the second zend_function_entry is just ignored by the compiler. I saw PHP's built-in DateTime and Reflection extensions were able to solve this problem, but how is this possible?

1 answers

1

Вы должны использовать эти два zend_function_entries с INIT_CLASS_ENTRY макрокомандой в качестве записей методы для соответствующей записи класса и зарегистрировать свой класс в Minit.

Zend_function_entry для структуры модуля может иметь только функцию, а не методы.