如何解决此重复名称错误



我想创建一个本地基元数据类型扩展,它可以用于强类型。我首先定义了一个名为ObjectInterface的接口,然后定义了一种名为Object的类。显然,Object实现了ObjectInterface,我有以下代码:

/* {{{ 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[] */
};

当然,这只是代码的一部分,我没有展示对象类方法的方法定义,因为代码可能有点长,而且会分散注意力。然后我遇到了一个问题,它给了我对象类方法的重复名称错误。

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

编译器似乎无法判断方法Object::equals()ObjectInterface::equals()是不同的方法,而是假设它们是相同的,并抛出重复名称警告。如何解决此问题?

我试图定义第二个zend_function_entry结构,但它也不起作用,因为第二个zend_function_entry被编译器忽略了。我看到PHP内置的DateTime和Reflection扩展能够解决这个问题,但这怎么可能呢?

您必须将这两个zend_function_entries与INIT_class_ENTRY宏一起用作相应类条目的方法条目,并在MINIT中注册您的类。

模块结构的zend_function_entry只能有函数,不能有方法。

相关内容

  • 没有找到相关文章

最新更新