summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@php.net>2005-11-23 09:26:22 +0000
committerDmitry Stogov <dmitry@php.net>2005-11-23 09:26:22 +0000
commit49ebc7f0469e0263fb6945f449f5d589d20b98d2 (patch)
treef1ff2ea9e51fc5ec9e7a2e2a6c20f39e3b52aa5b
parent3ba85be3bbd0f4713fb14846713adf141eaad784 (diff)
downloadphp-git-49ebc7f0469e0263fb6945f449f5d589d20b98d2.tar.gz
Fixed bug #33732 (Wrong behavior of constants in class and interface extending)
-rw-r--r--NEWS2
-rwxr-xr-xZend/tests/bug33732.phpt45
-rw-r--r--Zend/zend_compile.c10
3 files changed, 54 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index 378ff2da23..52f467f54c 100644
--- a/NEWS
+++ b/NEWS
@@ -53,6 +53,8 @@ PHP NEWS
(Marcus)
- Fixed bug #34199 (if($obj)/if(!$obj) inconsistency because of cast handler).
(Dmitry, Alex)
+- Fixed bug #33732 (Wrong behavior of constants in class and interface
+ extending). (Dmitry)
- Fixed bug #33720 (mb_encode_mimeheader does not work for multibyte
chars). (Rui)
- Fixed bug #33383 (crash when retrieving empty LOBs). (Tony)
diff --git a/Zend/tests/bug33732.phpt b/Zend/tests/bug33732.phpt
new file mode 100755
index 0000000000..f1e5a14956
--- /dev/null
+++ b/Zend/tests/bug33732.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Bug #33732 (Wrong behavior of constants in class and interface extending)
+--FILE--
+<?php
+interface iA {
+ const cA = "const of iA\n";
+}
+
+class A implements iA {
+}
+
+class B extends A implements iA {
+}
+
+echo iA::cA;
+echo A::cA;
+echo B::cA;
+
+
+interface iA2 {
+ const cA = "const of iA2\n";
+}
+
+interface iB2 extends iA2 {
+}
+
+class A2 implements iA2 {
+}
+
+class B2 extends A2 implements iB2 {
+}
+
+echo iA2::cA;
+echo A2::cA;
+echo iB2::cA;
+echo B2::cA;
+?>
+--EXPECT--
+const of iA
+const of iA
+const of iA
+const of iA2
+const of iA2
+const of iA2
+const of iA2
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index cb606159b7..c76f9d996e 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -2027,10 +2027,14 @@ void zend_do_inheritance(zend_class_entry *ce, zend_class_entry *parent_ce TSRML
}
-static zend_bool do_inherit_constant_check(HashTable *child_constants_table, zval *parent_constant, zend_hash_key *hash_key, zend_class_entry *iface)
+static zend_bool do_inherit_constant_check(HashTable *child_constants_table, zval **parent_constant, zend_hash_key *hash_key, zend_class_entry *iface)
{
- if (zend_hash_quick_exists(child_constants_table, hash_key->arKey, hash_key->nKeyLength, hash_key->h)) {
- zend_error(E_COMPILE_ERROR, "Cannot inherit previously-inherited constant %s from interface %s", hash_key->arKey, iface->name);
+ zval **old_constant;
+
+ if (zend_hash_quick_find(child_constants_table, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void**)&old_constant) == SUCCESS) {
+ if (*old_constant != *parent_constant) {
+ zend_error(E_COMPILE_ERROR, "Cannot inherit previously-inherited constant %s from interface %s", hash_key->arKey, iface->name);
+ }
return 0;
}
return 1;