I'm resubmitting this little patch for the ZE; when presented with
code like this:
<?php
class Foo {
}
class Foo {
}
?>
The engine will generate an error message like this:
Cannot redeclare class Foo (previously declared in file.php:2)
Caveat Emptor: if someone tries to redeclare an internal/builtin class
such as Directory, the previous declaration will appear to be the
actual declaration in the script. I'm not sure of the best way to
resolve this.
--Wez.
--
Wez Furlong
The Brain Room Ltd.
Index: Zend/zend.h
===================================================================
RCS file: /repository/Zend/zend.h,v
retrieving revision 1.161
diff -u -r1.161 zend.h
--- Zend/zend.h 19 Sep 2002 15:54:10 -0000 1.161
+++ Zend/zend.h 23 Sep 2002 14:51:44 -0000
@@ -275,6 +275,10 @@
void (*handle_function_call)(INTERNAL_FUNCTION_PARAMETERS,
zend_property_reference *property_reference);
zval (*handle_property_get)(zend_property_reference *property_reference);
int (*handle_property_set)(zend_property_reference *property_reference, zval
*value);
+
+ /* location of definition of this class */
+ char *def_file;
+ int def_lineno;
};
Index: Zend/zend_compile.c
===================================================================
RCS file: /repository/Zend/zend_compile.c,v
retrieving revision 1.236
diff -u -r1.236 zend_compile.c
--- Zend/zend_compile.c 20 Aug 2002 14:26:31 -0000 1.236
+++ Zend/zend_compile.c 23 Sep 2002 14:51:45 -0000
@@ -1190,7 +1190,10 @@
if (zend_hash_add(class_table,
opline->op2.u.constant.value.str.val, opline->op2.u.constant.value.str.len+1, ce,
sizeof(zend_class_entry), NULL)==FAILURE) {
(*ce->refcount)--;
if (!compile_time) {
- zend_error(E_ERROR, "Cannot redeclare
class %s", opline->op2.u.constant.value.str.val);
+ zend_error(E_ERROR, "Cannot redeclare
+class %s (previously declared in %s:%d)",
+
+opline->op2.u.constant.value.str.val,
+ ce->def_file,
+ ce->def_lineno);
}
return FAILURE;
} else {
@@ -1581,6 +1584,9 @@
CG(class_entry).handle_property_set = NULL;
CG(class_entry).handle_property_get = NULL;
+ CG(class_entry).def_file = estrdup(zend_get_compiled_filename(TSRMLS_C));
+ CG(class_entry).def_lineno = CG(zend_lineno);
+
/* code for inheritance from parent class */
if (parent_class_name) {
zend_class_entry *parent_class;
Index: Zend/zend_opcode.c
===================================================================
RCS file: /repository/Zend/zend_opcode.c,v
retrieving revision 1.56
diff -u -r1.56 zend_opcode.c
--- Zend/zend_opcode.c 6 Jan 2002 15:21:09 -0000 1.56
+++ Zend/zend_opcode.c 23 Sep 2002 14:51:46 -0000
@@ -115,6 +115,7 @@
case ZEND_USER_CLASS:
efree(ce->name);
efree(ce->refcount);
+ efree(ce->def_file);
zend_hash_destroy(&ce->function_table);
zend_hash_destroy(&ce->default_properties);
break;
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php