cvs: ZendEngine2 / zend_execute.c
| From: | Zeev Suraski | Date: | Sat, 07 Dec 2002 21:37:10 +0000 |
| Subject: | cvs: ZendEngine2 / zend_execute.c | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-689@lists.php.net to get a copy of this message | ||
zeev Sat Dec 7 16:37:10 2002 EDT
Modified files:
/ZendEngine2 zend_execute.c
Log:
Support private/protected constructors
Index: ZendEngine2/zend_execute.c
diff -u ZendEngine2/zend_execute.c:1.402 ZendEngine2/zend_execute.c:1.403
--- ZendEngine2/zend_execute.c:1.402 Sat Dec 7 10:53:37 2002
+++ ZendEngine2/zend_execute.c Sat Dec 7 16:37:09 2002
@@ -2217,41 +2217,6 @@
NEXT_OPCODE();
}
-int zend_init_ctor_call_handler(ZEND_OPCODE_HANDLER_ARGS)
-{
- zend_ptr_stack_n_push(&EG(arg_types_stack), 3, EX(fbc), EX(object), EX(calling_scope));
-
- if (EX(opline)->op1.op_type == IS_VAR) {
- SELECTIVE_PZVAL_LOCK(*EX_T(EX(opline)->op1.u.var).var.ptr_ptr, &EX(opline)->op1);
- }
-
- /* We are not handling overloaded classes right now */
- EX(object) = get_zval_ptr(&EX(opline)->op1, EX(Ts), &EG(free_op1), BP_VAR_R);
- if (!PZVAL_IS_REF(EX(object))) {
- EX(object)->refcount++; /* For $this pointer */
- } else {
- zval *this_ptr;
-
- ALLOC_ZVAL(this_ptr);
- *this_ptr = *EX(object);
- INIT_PZVAL(this_ptr);
- zval_copy_ctor(this_ptr);
- EX(object) = this_ptr;
- }
-
- EX(fbc) = EX(fbc_constructor);
- if (EX(fbc)->type == ZEND_USER_FUNCTION) { /* HACK!! */
- /* The scope should be the scope of the class where the constructor
- was initially declared in */
- EX(calling_scope) = EX(fbc)->common.scope;
- } else {
- EX(calling_scope) = NULL;
- }
-
- NEXT_OPCODE();
-}
-
-
/* Ensures that we're allowed to call a private method.
* Will update EX(fbc) with the correct handler as necessary.
*/
@@ -2306,6 +2271,57 @@
}
+int zend_init_ctor_call_handler(ZEND_OPCODE_HANDLER_ARGS)
+{
+ zend_ptr_stack_n_push(&EG(arg_types_stack), 3, EX(fbc), EX(object), EX(calling_scope));
+
+ if (EX(opline)->op1.op_type == IS_VAR) {
+ SELECTIVE_PZVAL_LOCK(*EX_T(EX(opline)->op1.u.var).var.ptr_ptr, &EX(opline)->op1);
+ }
+
+ /* We are not handling overloaded classes right now */
+ EX(object) = get_zval_ptr(&EX(opline)->op1, EX(Ts), &EG(free_op1), BP_VAR_R);
+ if (!PZVAL_IS_REF(EX(object))) {
+ EX(object)->refcount++; /* For $this pointer */
+ } else {
+ zval *this_ptr;
+
+ ALLOC_ZVAL(this_ptr);
+ *this_ptr = *EX(object);
+ INIT_PZVAL(this_ptr);
+ zval_copy_ctor(this_ptr);
+ EX(object) = this_ptr;
+ }
+
+ EX(fbc) = EX(fbc_constructor);
+ if (EX(fbc)->type == ZEND_USER_FUNCTION) { /* HACK!! */
+ if (EX(fbc)->op_array.fn_flags & ZEND_ACC_PUBLIC) {
+ /* No further checks necessary, most common case */
+ } else if (EX(fbc)->op_array.fn_flags & ZEND_ACC_PRIVATE) {
+ /* Ensure that if we're calling a private function, we're allowed to do so.
+ */
+ if (EX(object)->value.obj.handlers->get_class_entry(EX(object) TSRMLS_CC) != EG(scope)) {
+ zend_error(E_ERROR, "Call to private constructor from context '%s'",
EG(scope) ? EG(scope)->name : "");
+ }
+ } 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)) {
+ zend_error(E_ERROR, "Call to protected constructor from context '%s'",
EG(scope) ? EG(scope)->name : "");
+ }
+ }
+
+ /* The scope should be the scope of the class where the constructor
+ was initially declared in */
+ EX(calling_scope) = EX(fbc)->common.scope;
+ } else {
+ EX(calling_scope) = NULL;
+ }
+
+ NEXT_OPCODE();
+}
+
+
int zend_init_method_call_handler(ZEND_OPCODE_HANDLER_ARGS)
{
zval *function_name;
@@ -3004,7 +3020,7 @@
int zend_new_handler(ZEND_OPCODE_HANDLER_ARGS)
{
if (EX_T(EX(opline)->op1.u.var).EA.class_entry->ce_flags & ZEND_ACC_ABSTRACT) {
- zend_error(E_ERROR, "Cannot instanciate abstract class %s",
EX_T(EX(opline)->op1.u.var).EA.class_entry->name);
+ zend_error(E_ERROR, "Cannot instantiate abstract class %s",
EX_T(EX(opline)->op1.u.var).EA.class_entry->name);
}
EX_T(EX(opline)->result.u.var).var.ptr_ptr = &EX_T(EX(opline)->result.u.var).var.ptr;
ALLOC_ZVAL(EX_T(EX(opline)->result.u.var).var.ptr);