felipe Thu, 03 Dec 2009 12:34:50 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=291642
Log:
- Fixed bug #49472 (Constants defined in Interfaces can be overridden)
Bug: http://bugs.php.net/49472 (Assigned) Constants defined in Interfaces can
be overridden
Changed paths:
U php/php-src/branches/PHP_5_2/NEWS
A php/php-src/branches/PHP_5_2/Zend/tests/bug49472.phpt
U php/php-src/branches/PHP_5_2/Zend/tests/errmsg_025.phpt
U php/php-src/branches/PHP_5_2/Zend/zend_compile.c
U php/php-src/branches/PHP_5_3/NEWS
A php/php-src/branches/PHP_5_3/Zend/tests/bug49472.phpt
U php/php-src/branches/PHP_5_3/Zend/tests/errmsg_025.phpt
U php/php-src/branches/PHP_5_3/Zend/tests/inter_01.phpt
U php/php-src/branches/PHP_5_3/Zend/zend_compile.c
A php/php-src/trunk/Zend/tests/bug49472.phpt
U php/php-src/trunk/Zend/tests/errmsg_025.phpt
U php/php-src/trunk/Zend/tests/inter_01.phpt
U php/php-src/trunk/Zend/zend_compile.c
Modified: php/php-src/branches/PHP_5_2/NEWS
===================================================================
--- php/php-src/branches/PHP_5_2/NEWS 2009-12-03 12:11:38 UTC (rev 291641)
+++ php/php-src/branches/PHP_5_2/NEWS 2009-12-03 12:34:50 UTC (rev 291642)
@@ -12,6 +12,8 @@
- Fixed bug #50168 (FastCGI fails with wrong error on HEAD request to
non-existent file). (Dmitry)
- Fixed bug #49660 (libxml 2.7.3+ limits text nodes to 10MB). (Felipe)
+- Fixed bug #49472 (Constants defined in Interfaces can be overridden).
+ (Felipe)
27 Nov 2009, PHP 5.2.12RC3
Added: php/php-src/branches/PHP_5_2/Zend/tests/bug49472.phpt
===================================================================
--- php/php-src/branches/PHP_5_2/Zend/tests/bug49472.phpt (rev 0)
+++ php/php-src/branches/PHP_5_2/Zend/tests/bug49472.phpt 2009-12-03 12:34:50 UTC (rev 291642)
@@ -0,0 +1,27 @@
+--TEST--
+Bug #49472 (Constants defined in Interfaces can be overridden)
+--FILE--
+<?php
+
+interface ia {
+ const c = 'Sea';
+ const y = 2;
+}
+
+class Foo implements ia {
+}
+
+class FooBar extends Foo implements ia {
+ const x = 1;
+ const c = 'Ocean';
+
+ public function show() {
+ return ia::c;
+ }
+}
+
+new FooBar;
+
+?>
+--EXPECTF--
+Fatal error: Cannot inherit previously-inherited or override constant c from interface ia in %s on line %d
Property changes on: php/php-src/branches/PHP_5_2/Zend/tests/bug49472.phpt
___________________________________________________________________
Added: svn:keywords
+ Id Rev Revision
Added: svn:eol-style
+ native
Modified: php/php-src/branches/PHP_5_2/Zend/tests/errmsg_025.phpt
===================================================================
--- php/php-src/branches/PHP_5_2/Zend/tests/errmsg_025.phpt 2009-12-03 12:11:38 UTC (rev 291641)
+++ php/php-src/branches/PHP_5_2/Zend/tests/errmsg_025.phpt 2009-12-03 12:34:50 UTC (rev 291642)
@@ -16,5 +16,5 @@
echo "Done\n";
?>
---EXPECTF--
-Fatal error: Cannot inherit previously-inherited constant FOO from interface test2 in %s on line %d
+--EXPECTF--
+Fatal error: Cannot inherit previously-inherited or override constant FOO from interface test2 in %s on line %d
Modified: php/php-src/branches/PHP_5_2/Zend/zend_compile.c
===================================================================
--- php/php-src/branches/PHP_5_2/Zend/zend_compile.c 2009-12-03 12:11:38 UTC (rev 291641)
+++ php/php-src/branches/PHP_5_2/Zend/zend_compile.c 2009-12-03 12:34:50 UTC (rev 291642)
@@ -2333,21 +2333,29 @@
}
}
-
static zend_bool do_inherit_constant_check(HashTable *child_constants_table, zval **parent_constant, zend_hash_key *hash_key, zend_class_entry *iface)
{
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);
+ if (*old_constant != *parent_constant) {
+ zend_error(E_COMPILE_ERROR, "Cannot inherit previously-inherited or override constant %s from interface %s", hash_key->arKey, iface->name);
}
return 0;
}
return 1;
}
+static int do_interface_constant_check(zval **val, int num_args, va_list args, zend_hash_key *key) /* {{{ */
+{
+ zend_class_entry **iface = va_arg(args, zend_class_entry**);
+ do_inherit_constant_check(&(*iface)->constants_table, val, key, *iface);
+
+ return ZEND_HASH_APPLY_KEEP;
+}
+/* }}} */
+
ZEND_API void zend_do_implement_interface(zend_class_entry *ce, zend_class_entry *iface TSRMLS_DC)
{
zend_uint i, ignore = 0;
@@ -2366,7 +2374,10 @@
}
}
}
- if (!ignore) {
+ if (ignore) {
+ /* Check for attempt to redeclare interface constants */
+ zend_hash_apply_with_arguments(&ce->constants_table, (apply_func_args_t) do_interface_constant_check, 1, &iface);
+ } else {
if (ce->num_interfaces >= current_iface_num) {
if (ce->type == ZEND_INTERNAL_CLASS) {
ce->interfaces = (zend_class_entry **) realloc(ce->interfaces, sizeof(zend_class_entry *) * (++current_iface_num));
Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS 2009-12-03 12:11:38 UTC (rev 291641)
+++ php/php-src/branches/PHP_5_3/NEWS 2009-12-03 12:34:50 UTC (rev 291642)
@@ -92,6 +92,8 @@
- Fixed bug #49647 (DOMUserData does not exist). (Rob)
- Fixed bug #49521 (PDO fetchObject sets values before calling constructor).
(Pierrick)
+- Fixed bug #49472 (Constants defined in Interfaces can be overridden).
+ (Felipe)
- Fixed bug #49244 (Floating point NaN cause garbage characters). (Sjoerd)
- Fixed bug #49224 (Compile error due to old DNS functions on AIX systems).
(Scott)
Added: php/php-src/branches/PHP_5_3/Zend/tests/bug49472.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/Zend/tests/bug49472.phpt (rev 0)
+++ php/php-src/branches/PHP_5_3/Zend/tests/bug49472.phpt 2009-12-03 12:34:50 UTC (rev 291642)
@@ -0,0 +1,27 @@
+--TEST--
+Bug #49472 (Constants defined in Interfaces can be overridden)
+--FILE--
+<?php
+
+interface ia {
+ const c = 'Sea';
+ const y = 2;
+}
+
+class Foo implements ia {
+}
+
+class FooBar extends Foo implements ia {
+ const x = 1;
+ const c = 'Ocean';
+
+ public function show() {
+ return ia::c;
+ }
+}
+
+new FooBar;
+
+?>
+--EXPECTF--
+Fatal error: Cannot inherit previously-inherited or override constant c from interface ia in %s on line %d
Property changes on: php/php-src/branches/PHP_5_3/Zend/tests/bug49472.phpt
___________________________________________________________________
Added: svn:keywords
+ Id Rev Revision
Added: svn:eol-style
+ native
Modified: php/php-src/branches/PHP_5_3/Zend/tests/errmsg_025.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/Zend/tests/errmsg_025.phpt 2009-12-03 12:11:38 UTC (rev 291641)
+++ php/php-src/branches/PHP_5_3/Zend/tests/errmsg_025.phpt 2009-12-03 12:34:50 UTC (rev 291642)
@@ -16,5 +16,5 @@
echo "Done\n";
?>
---EXPECTF--
-Fatal error: Cannot inherit previously-inherited constant FOO from interface test2 in %s on line %d
+--EXPECTF--
+Fatal error: Cannot inherit previously-inherited or override constant FOO from interface test2 in %s on line %d
Modified: php/php-src/branches/PHP_5_3/Zend/tests/inter_01.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/Zend/tests/inter_01.phpt 2009-12-03 12:11:38 UTC (rev 291641)
+++ php/php-src/branches/PHP_5_3/Zend/tests/inter_01.phpt 2009-12-03 12:34:50 UTC (rev 291642)
@@ -15,4 +15,4 @@
}
?>
--EXPECTF--
-Fatal error: Cannot inherit previously-inherited constant foo from interface foo in %s on line %d
+Fatal error: Cannot inherit previously-inherited or override constant foo from interface foo in %s on line %d
Modified: php/php-src/branches/PHP_5_3/Zend/zend_compile.c
===================================================================
--- php/php-src/branches/PHP_5_3/Zend/zend_compile.c 2009-12-03 12:11:38 UTC (rev 291641)
+++ php/php-src/branches/PHP_5_3/Zend/zend_compile.c 2009-12-03 12:34:50 UTC (rev 291642)
@@ -2876,8 +2876,8 @@
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);
+ if (*old_constant != *parent_constant) {
+ zend_error(E_COMPILE_ERROR, "Cannot inherit previously-inherited or override constant %s from interface %s", hash_key->arKey, iface->name);
}
return 0;
}
@@ -2885,6 +2885,16 @@
}
/* }}} */
+static int do_interface_constant_check(zval **val TSRMLS_DC, int num_args, va_list args, const zend_hash_key *key) /* {{{ */
+{
+ zend_class_entry **iface = va_arg(args, zend_class_entry**);
+
+ do_inherit_constant_check(&(*iface)->constants_table, (const zval **) val, key, *iface);
+
+ return ZEND_HASH_APPLY_KEEP;
+}
+/* }}} */
+
ZEND_API void zend_do_implement_interface(zend_class_entry *ce, zend_class_entry *iface TSRMLS_DC) /* {{{ */
{
zend_uint i, ignore = 0;
@@ -2903,7 +2913,10 @@
}
}
}
- if (!ignore) {
+ if (ignore) {
+ /* Check for attempt to redeclare interface constants */
+ zend_hash_apply_with_arguments(&ce->constants_table TSRMLS_CC, (apply_func_args_t) do_interface_constant_check, 1, &iface);
+ } else {
if (ce->num_interfaces >= current_iface_num) {
if (ce->type == ZEND_INTERNAL_CLASS) {
ce->interfaces = (zend_class_entry **) realloc(ce->interfaces, sizeof(zend_class_entry *) * (++current_iface_num));
Added: php/php-src/trunk/Zend/tests/bug49472.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/bug49472.phpt (rev 0)
+++ php/php-src/trunk/Zend/tests/bug49472.phpt 2009-12-03 12:34:50 UTC (rev 291642)
@@ -0,0 +1,27 @@
+--TEST--
+Bug #49472 (Constants defined in Interfaces can be overridden)
+--FILE--
+<?php
+
+interface ia {
+ const c = 'Sea';
+ const y = 2;
+}
+
+class Foo implements ia {
+}
+
+class FooBar extends Foo implements ia {
+ const x = 1;
+ const c = 'Ocean';
+
+ public function show() {
+ return ia::c;
+ }
+}
+
+new FooBar;
+
+?>
+--EXPECTF--
+Fatal error: Cannot inherit previously-inherited or override constant c from interface ia in %s on line %d
Property changes on: php/php-src/trunk/Zend/tests/bug49472.phpt
___________________________________________________________________
Added: svn:keywords
+ Id Rev Revision
Added: svn:eol-style
+ native
Modified: php/php-src/trunk/Zend/tests/errmsg_025.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/errmsg_025.phpt 2009-12-03 12:11:38 UTC (rev 291641)
+++ php/php-src/trunk/Zend/tests/errmsg_025.phpt 2009-12-03 12:34:50 UTC (rev 291642)
@@ -17,4 +17,4 @@
echo "Done\n";
?>
--EXPECTF--
-Fatal error: Cannot inherit previously-inherited constant FOO from interface test2 in %s on line %d
+Fatal error: Cannot inherit previously-inherited or override constant FOO from interface test2 in %s on line %d
Modified: php/php-src/trunk/Zend/tests/inter_01.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/inter_01.phpt 2009-12-03 12:11:38 UTC (rev 291641)
+++ php/php-src/trunk/Zend/tests/inter_01.phpt 2009-12-03 12:34:50 UTC (rev 291642)
@@ -15,4 +15,4 @@
}
?>
--EXPECTF--
-Fatal error: Cannot inherit previously-inherited constant foo from interface foo in %s on line %d
+Fatal error: Cannot inherit previously-inherited or override constant foo from interface foo in %s on line %d
Modified: php/php-src/trunk/Zend/zend_compile.c
===================================================================
--- php/php-src/trunk/Zend/zend_compile.c 2009-12-03 12:11:38 UTC (rev 291641)
+++ php/php-src/trunk/Zend/zend_compile.c 2009-12-03 12:34:50 UTC (rev 291642)
@@ -2938,7 +2938,7 @@
if (zend_u_hash_quick_find(child_constants_table, hash_key->type, 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 %R from interface %v", hash_key->type, hash_key->arKey, iface->name);
+ zend_error(E_COMPILE_ERROR, "Cannot inherit previously-inherited or override constant %R from interface %v", hash_key->type, hash_key->arKey, iface->name);
}
return 0;
}
@@ -2946,6 +2946,16 @@
}
/* }}} */
+static int do_interface_constant_check(zval **val TSRMLS_DC, int num_args, va_list args, const zend_hash_key *key) /* {{{ */
+{
+ zend_class_entry **iface = va_arg(args, zend_class_entry**);
+
+ do_inherit_constant_check(&(*iface)->constants_table, (const zval **) val, key, *iface);
+
+ return ZEND_HASH_APPLY_KEEP;
+}
+/* }}} */
+
ZEND_API void zend_do_implement_interface(zend_class_entry *ce, zend_class_entry *iface TSRMLS_DC) /* {{{ */
{
zend_uint i, ignore = 0;
@@ -2964,7 +2974,10 @@
}
}
}
- if (!ignore) {
+ if (ignore) {
+ /* Check for attempt to redeclare interface constants */
+ zend_hash_apply_with_arguments(&ce->constants_table TSRMLS_CC, (apply_func_args_t) do_interface_constant_check, 1, &iface);
+ } else {
if (ce->num_interfaces >= current_iface_num) {
if (ce->type == ZEND_INTERNAL_CLASS) {
ce->interfaces = (zend_class_entry **) realloc(ce->interfaces, sizeof(zend_class_entry *) * (++current_iface_num));
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php