cvs: ZendEngine2 / zend_execute.c
| From: | Zeev Suraski | Date: | Tue, 28 Jan 2003 09:44:19 +0000 |
| Subject: | cvs: ZendEngine2 / zend_execute.c | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-849@lists.php.net to get a copy of this message | ||
zeev Tue Jan 28 04:44:19 2003 EDT
Modified files:
/ZendEngine2 zend_execute.c
Log:
Allow methods in parent classes to call protected methods in derived
classes
Index: ZendEngine2/zend_execute.c
diff -u ZendEngine2/zend_execute.c:1.413 ZendEngine2/zend_execute.c:1.414
--- ZendEngine2/zend_execute.c:1.413 Mon Jan 27 10:13:01 2003
+++ ZendEngine2/zend_execute.c Tue Jan 28 04:44:18 2003
@@ -2308,13 +2308,28 @@
/* Ensures that we're allowed to call a protected method.
*/
-inline int zend_check_protected(zend_class_entry *ce, zend_class_entry *scope, int fn_flags)
+inline int zend_check_protected(zend_class_entry *ce, zend_class_entry *scope)
{
- while (ce) {
- if (ce==scope) {
+ zend_class_entry *fbc_scope = ce;
+
+ /* Is the context that's calling the function, the same as one of
+ * the function's parents?
+ */
+ while (fbc_scope) {
+ if (fbc_scope==scope) {
+ return 1;
+ }
+ fbc_scope = fbc_scope->parent;
+ }
+
+ /* Is the function's scope the same as our current object context,
+ * or any of the parents of our context?
+ */
+ while (scope) {
+ if (scope==ce) {
return 1;
}
- ce = ce->parent;
+ scope = scope->parent;
}
return 0;
}
@@ -2355,7 +2370,7 @@
} else if ((EX(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(EG(scope), EX(fbc)->common.scope, EX(fbc)->common.fn_flags)) {
+ if (!zend_check_protected(EX(fbc)->common.scope, EG(scope))) {
zend_error(E_ERROR, "Call to protected constructor from context '%s'",
EG(scope) ? EG(scope)->name : "");
}
}
@@ -2416,7 +2431,7 @@
} else if ((EX(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(EG(scope), EX(fbc)->common.scope, EX(fbc)->common.fn_flags)) {
+ if (!zend_check_protected(EX(fbc)->common.scope, EG(scope))) {
zend_error(E_ERROR, "Call to %s method %s::%s() from context '%s'",
zend_visibility_string(EX(fbc)->common.fn_flags), ZEND_FN_SCOPE_NAME(EX(fbc)),
function_name_strval, EG(scope) ? EG(scope)->name : "");
}
}
@@ -2498,7 +2513,7 @@
} else if ((EX(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(EG(scope), EX(fbc)->common.scope, EX(fbc)->common.fn_flags)) {
+ if (!zend_check_protected(EG(scope), EX(fbc)->common.scope)) {
zend_error(E_ERROR, "Call to %s method %s::%s() from context '%s'",
zend_visibility_string(EX(fbc)->common.fn_flags), ZEND_FN_SCOPE_NAME(EX(fbc)),
function_name_strval, EG(scope) ? EG(scope)->name : "");
}
}