cvs: ZendEngine2 / zend_compile.c zend_object_handlers.c /tests bug38772.phpt
| From: | Dmitry Stogov | Date: | Tue, 12 Sep 2006 11:01:31 +0000 |
| Subject: | cvs: ZendEngine2 / zend_compile.c zend_object_handlers.c /tests bug38772.phpt | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-5248@lists.php.net to get a copy of this message | ||
dmitry Tue Sep 12 11:01:31 2006 UTC
Modified files:
/ZendEngine2 zend_compile.c zend_object_handlers.c
/ZendEngine2/tests bug38772.phpt
Log:
Fixed bug #38772 (inconsistent overriding of methods in different visibility contexts)
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.c?r1=1.721&r2=1.722&diff_format=u
Index: ZendEngine2/zend_compile.c
diff -u ZendEngine2/zend_compile.c:1.721 ZendEngine2/zend_compile.c:1.722
--- ZendEngine2/zend_compile.c:1.721 Tue Jul 25 00:01:40 2006
+++ ZendEngine2/zend_compile.c Tue Sep 12 11:01:31 2006
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_compile.c,v 1.721 2006/07/25 00:01:40 helly Exp $ */
+/* $Id: zend_compile.c,v 1.722 2006/09/12 11:01:31 dmitry Exp $ */
#include <zend_language_parser.h>
#include "zend.h"
@@ -2160,7 +2160,9 @@
}
}
- if (parent_flags & ZEND_ACC_ABSTRACT) {
+ if (parent_flags & ZEND_ACC_PRIVATE) {
+ child->common.prototype = NULL;
+ } else if (parent_flags & ZEND_ACC_ABSTRACT) {
child->common.fn_flags |= ZEND_ACC_IMPLEMENTED_ABSTRACT;
child->common.prototype = parent;
} else if (!(parent->common.fn_flags & ZEND_ACC_CTOR) || (parent->common.prototype
&& (parent->common.prototype->common.scope->ce_flags & ZEND_ACC_INTERFACE))) {
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_object_handlers.c?r1=1.175&r2=1.176&diff_format=u
Index: ZendEngine2/zend_object_handlers.c
diff -u ZendEngine2/zend_object_handlers.c:1.175 ZendEngine2/zend_object_handlers.c:1.176
--- ZendEngine2/zend_object_handlers.c:1.175 Tue Aug 15 20:30:26 2006
+++ ZendEngine2/zend_object_handlers.c Tue Sep 12 11:01:31 2006
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_object_handlers.c,v 1.175 2006/08/15 20:30:26 tony2001 Exp $ */
+/* $Id: zend_object_handlers.c,v 1.176 2006/09/12 11:01:31 dmitry Exp $ */
#include "zend.h"
#include "zend_globals.h"
@@ -798,7 +798,17 @@
}
/* Check access level */
- if (fbc->op_array.fn_flags & ZEND_ACC_PUBLIC) {
+ if (fbc->op_array.fn_flags & ZEND_ACC_PRIVATE) {
+ zend_function *updated_fbc;
+
+ /* Ensure that if we're calling a private function, we're allowed to do so.
+ */
+ updated_fbc = zend_check_private_int(fbc, Z_OBJ_HANDLER_P(object, get_class_entry)(object
TSRMLS_CC), lc_method_name, method_len TSRMLS_CC);
+ if (!updated_fbc) {
+ zend_error(E_ERROR, "Call to %s method %v::%v() from context '%v'",
zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), method_name, EG(scope) ?
EG(scope)->name : EMPTY_ZSTR);
+ }
+ fbc = updated_fbc;
+ } else {
/* Ensure that we haven't overridden a private function and end up calling
* the overriding public function...
*/
@@ -811,21 +821,12 @@
fbc = priv_fbc;
}
}
- } else if (fbc->op_array.fn_flags & ZEND_ACC_PRIVATE) {
- zend_function *updated_fbc;
-
- /* Ensure that if we're calling a private function, we're allowed to do so.
- */
- updated_fbc = zend_check_private_int(fbc, Z_OBJ_HANDLER_P(object, get_class_entry)(object
TSRMLS_CC), lc_method_name, method_len TSRMLS_CC);
- if (!updated_fbc) {
- zend_error(E_ERROR, "Call to %s method %v::%v() from context '%v'",
zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), method_name, EG(scope) ?
EG(scope)->name : EMPTY_ZSTR);
- }
- fbc = updated_fbc;
- } else if ((fbc->common.fn_flags & ZEND_ACC_PROTECTED)) {
- /* Ensure that if we're calling a protected function, we're allowed to do so.
- */
- if (!zend_check_protected(zend_get_function_root_class(fbc), EG(scope))) {
- zend_error(E_ERROR, "Call to %s method %v::%v() from context '%v'",
zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), method_name, EG(scope) ?
EG(scope)->name : EMPTY_ZSTR);
+ if ((fbc->common.fn_flags & ZEND_ACC_PROTECTED)) {
+ /* Ensure that if we're calling a protected function, we're allowed to do so.
+ */
+ if (!zend_check_protected(zend_get_function_root_class(fbc), EG(scope))) {
+ zend_error(E_ERROR, "Call to %s method %v::%v() from context '%v'",
zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), method_name, EG(scope) ?
EG(scope)->name : EMPTY_ZSTR);
+ }
}
}
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug38772.phpt?r1=1.1&r2=1.2&diff_format=u
Index: ZendEngine2/tests/bug38772.phpt
diff -u /dev/null ZendEngine2/tests/bug38772.phpt:1.2
--- /dev/null Tue Sep 12 11:01:31 2006
+++ ZendEngine2/tests/bug38772.phpt Tue Sep 12 11:01:31 2006
@@ -0,0 +1,42 @@
+--TEST--
+Bug #38772 (inconsistent overriding of methods in different visibility contexts)
+--FILE--
+<?php
+class A {
+
+ public function __construct() {
+ $this -> foo();
+ }
+
+ private function foo() {
+ echo __METHOD__ . "\r\n";
+ }
+}
+
+class B extends A {
+ public function foo() {
+ echo __METHOD__ . "\r\n";
+ }
+}
+
+class C extends A {
+ protected function foo() {
+ echo __METHOD__ . "\r\n";
+ }
+}
+
+class D extends A {
+ private function foo() {
+ echo __METHOD__ . "\r\n";
+ }
+}
+
+$a = new A();
+$b = new B();
+$c = new C();
+$d = new D();
+--EXPECT--
+A::foo
+A::foo
+A::foo
+A::foo