Permalink
Browse files

Fixed bug #46409 (__invoke method called outside of object context wh…

…en using array_map)
  • Loading branch information...
1 parent d741138 commit 7d4fd3fd380a7fe9b497684775a38190786b93ba Dmitry Stogov committed Nov 27, 2008
View
2 NEWS
@@ -41,6 +41,8 @@ PHP NEWS
- Fixed bug #46546 (Segmentation fault when using declare statement with
non-string value). (Felipe)
- Fixed bug #46421 (SplFileInfo not correctly handling /). (Etienne)
+- Fixed bug #46409 (__invoke method called outside of object context when using
+ array_map). (Dmitry)
- Fixed bug #46331 - (Segfault when using internal fileinfo magic file on big
endian systems). (Scott)
- Fixed bug #46285 (lastInsertId() returns "0" when a deferenced PDOStatement is
View
@@ -0,0 +1,25 @@
+--TEST--
+Bug #46409 (__invoke method called outside of object context when using array_map)
+--FILE--
+<?php
+class Callback {
+ protected $val = 'hello, world';
+
+ public function __invoke() {
+ return $this->val;
+ }
+}
+
+$cb = new Callback();
+echo $cb(),"\n";
+$a = array(1, 2);
+$b = array_map($cb, $a);
+print_r($b);
+?>
+--EXPECT--
+hello, world
+Array
+(
+ [0] => hello, world
+ [1] => hello, world
+)
View
@@ -2329,8 +2329,8 @@ static int zend_is_callable_check_class(const char *name, int name_len, zend_fca
} else {
fcc->called_scope = EG(called_scope);
fcc->calling_scope = EG(scope);
- if (!fcc->object_pp) {
- fcc->object_pp = EG(This) ? &EG(This) : NULL;
+ if (!fcc->object_ptr) {
+ fcc->object_ptr = EG(This);
}
ret = 1;
}
@@ -2343,8 +2343,8 @@ static int zend_is_callable_check_class(const char *name, int name_len, zend_fca
} else {
fcc->called_scope = EG(called_scope);
fcc->calling_scope = EG(scope)->parent;
- if (!fcc->object_pp) {
- fcc->object_pp = EG(This) ? &EG(This) : NULL;
+ if (!fcc->object_ptr) {
+ fcc->object_ptr = EG(This);
}
ret = 1;
}
@@ -2355,22 +2355,22 @@ static int zend_is_callable_check_class(const char *name, int name_len, zend_fca
} else {
fcc->called_scope = EG(called_scope);
fcc->calling_scope = EG(called_scope);
- if (!fcc->object_pp) {
- fcc->object_pp = EG(This) ? &EG(This) : NULL;
+ if (!fcc->object_ptr) {
+ fcc->object_ptr = EG(This);
}
ret = 1;
}
} else if (zend_lookup_class_ex(name, name_len, 1, &pce TSRMLS_CC) == SUCCESS) {
zend_class_entry *scope = EG(active_op_array) ? EG(active_op_array)->scope : NULL;
fcc->calling_scope = *pce;
- if (scope && !fcc->object_pp && EG(This) &&
+ if (scope && !fcc->object_ptr && EG(This) &&
instanceof_function(Z_OBJCE_P(EG(This)), scope TSRMLS_CC) &&
instanceof_function(scope, fcc->calling_scope TSRMLS_CC)) {
- fcc->object_pp = &EG(This);
- fcc->called_scope = Z_OBJCE_PP(fcc->object_pp);
+ fcc->object_ptr = EG(This);
+ fcc->called_scope = Z_OBJCE_P(fcc->object_ptr);
} else {
- fcc->called_scope = fcc->object_pp ? Z_OBJCE_PP(fcc->object_pp) : fcc->calling_scope;
+ fcc->called_scope = fcc->object_ptr ? Z_OBJCE_P(fcc->object_ptr) : fcc->calling_scope;
}
ret = 1;
} else {
@@ -2480,9 +2480,9 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca
fcc->function_handler = priv_fbc;
}
}
- } else if (fcc->object_pp) {
- if (Z_OBJ_HT_PP(fcc->object_pp)->get_method) {
- fcc->function_handler = Z_OBJ_HT_PP(fcc->object_pp)->get_method(fcc->object_pp, mname, mlen TSRMLS_CC);
+ } else if (fcc->object_ptr) {
+ if (Z_OBJ_HT_P(fcc->object_ptr)->get_method) {
+ fcc->function_handler = Z_OBJ_HT_P(fcc->object_ptr)->get_method(&fcc->object_ptr, mname, mlen TSRMLS_CC);
retval = fcc->function_handler ? 1 : 0;
call_via_handler = 1;
}
@@ -2498,7 +2498,7 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca
if (retval) {
if (fcc->calling_scope && !call_via_handler) {
- if (!fcc->object_pp && !(fcc->function_handler->common.fn_flags & ZEND_ACC_STATIC)) {
+ if (!fcc->object_ptr && !(fcc->function_handler->common.fn_flags & ZEND_ACC_STATIC)) {
int severity;
char *verb;
if (fcc->function_handler->common.fn_flags & ZEND_ACC_ALLOW_STATIC) {
@@ -2513,7 +2513,7 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca
retval = 0;
}
if (EG(This) && instanceof_function(Z_OBJCE_P(EG(This)), fcc->calling_scope TSRMLS_CC)) {
- fcc->object_pp = &EG(This);
+ fcc->object_ptr = EG(This);
if (error) {
zend_spprintf(error, 0, "non-static method %s::%s() %s be called statically, assuming $this from compatible context %s", fcc->calling_scope->name, fcc->function_handler->common.function_name, verb, Z_OBJCE_P(EG(This))->name);
} else if (retval) {
@@ -2529,7 +2529,7 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca
}
if (retval && (check_flags & IS_CALLABLE_CHECK_NO_ACCESS) == 0) {
if (fcc->function_handler->op_array.fn_flags & ZEND_ACC_PRIVATE) {
- if (!zend_check_private(fcc->function_handler, fcc->object_pp ? Z_OBJCE_PP(fcc->object_pp) : EG(scope), lmname, mlen TSRMLS_CC)) {
+ if (!zend_check_private(fcc->function_handler, fcc->object_ptr ? Z_OBJCE_P(fcc->object_ptr) : EG(scope), lmname, mlen TSRMLS_CC)) {
if (error) {
if (*error) {
efree(*error);
@@ -2560,8 +2560,8 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca
}
efree(lmname);
- if (fcc->object_pp) {
- fcc->called_scope = Z_OBJCE_PP(fcc->object_pp);
+ if (fcc->object_ptr) {
+ fcc->called_scope = Z_OBJCE_P(fcc->object_ptr);
}
if (retval) {
fcc->initialized = 1;
@@ -2570,7 +2570,7 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca
}
/* }}} */
-ZEND_API zend_bool zend_is_callable_ex(zval *callable, zval **object_pp, uint check_flags, char **callable_name, int *callable_name_len, zend_fcall_info_cache *fcc, char **error TSRMLS_DC) /* {{{ */
+ZEND_API zend_bool zend_is_callable_ex(zval *callable, zval *object_ptr, uint check_flags, char **callable_name, int *callable_name_len, zend_fcall_info_cache *fcc, char **error TSRMLS_DC) /* {{{ */
{
zend_bool ret;
int callable_name_len_local;
@@ -2594,22 +2594,22 @@ ZEND_API zend_bool zend_is_callable_ex(zval *callable, zval **object_pp, uint ch
fcc->called_scope = NULL;
fcc->function_handler = NULL;
fcc->calling_scope = NULL;
- fcc->object_pp = NULL;
+ fcc->object_ptr = NULL;
- if (object_pp && (!*object_pp || Z_TYPE_PP(object_pp) != IS_OBJECT)) {
- object_pp = NULL;
+ if (object_ptr && Z_TYPE_P(object_ptr) != IS_OBJECT) {
+ object_ptr = NULL;
}
- if (object_pp &&
+ if (object_ptr &&
(!EG(objects_store).object_buckets ||
- !EG(objects_store).object_buckets[Z_OBJ_HANDLE_PP(object_pp)].valid)) {
+ !EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(object_ptr)].valid)) {
return 0;
}
switch (Z_TYPE_P(callable)) {
case IS_STRING:
- if (object_pp && *object_pp) {
- fcc->object_pp = object_pp;
- fcc->calling_scope = Z_OBJCE_PP(object_pp);
+ if (object_ptr) {
+ fcc->object_ptr = object_ptr;
+ fcc->calling_scope = Z_OBJCE_P(object_ptr);
if (callable_name) {
char *ptr;
@@ -2687,7 +2687,7 @@ ZEND_API zend_bool zend_is_callable_ex(zval *callable, zval **object_pp, uint ch
fcc->calling_scope = Z_OBJCE_PP(obj); /* TBFixed: what if it's overloaded? */
- fcc->object_pp = obj;
+ fcc->object_ptr = *obj;
if (callable_name) {
char *ptr;
@@ -2740,7 +2740,7 @@ ZEND_API zend_bool zend_is_callable_ex(zval *callable, zval **object_pp, uint ch
return 0;
case IS_OBJECT:
- if (Z_OBJ_HANDLER_P(callable, get_closure) && Z_OBJ_HANDLER_P(callable, get_closure)(callable, &fcc->calling_scope, &fcc->function_handler, NULL, &fcc->object_pp TSRMLS_CC) == SUCCESS) {
+ if (Z_OBJ_HANDLER_P(callable, get_closure) && Z_OBJ_HANDLER_P(callable, get_closure)(callable, &fcc->calling_scope, &fcc->function_handler, &fcc->object_ptr TSRMLS_CC) == SUCCESS) {
fcc->called_scope = fcc->calling_scope;
if (callable_name) {
zend_class_entry *ce = Z_OBJCE_P(callable); /* TBFixed: what if it's overloaded? */
@@ -2811,7 +2811,7 @@ ZEND_API int zend_fcall_info_init(zval *callable, uint check_flags, zend_fcall_i
fci->size = sizeof(*fci);
fci->function_table = fcc->calling_scope ? &fcc->calling_scope->function_table : EG(function_table);
- fci->object_pp = fcc->object_pp;
+ fci->object_ptr = fcc->object_ptr;
fci->function_name = callable;
fci->retval_ptr_ptr = NULL;
fci->param_count = 0;
View
@@ -48,7 +48,7 @@ typedef struct _zend_fcall_info {
zval **retval_ptr_ptr;
zend_uint param_count;
zval ***params;
- zval **object_pp;
+ zval *object_ptr;
zend_bool no_separation;
} zend_fcall_info;
@@ -57,7 +57,7 @@ typedef struct _zend_fcall_info_cache {
zend_function *function_handler;
zend_class_entry *calling_scope;
zend_class_entry *called_scope;
- zval **object_pp;
+ zval *object_ptr;
} zend_fcall_info_cache;
#define ZEND_NS_NAME(ns, name) ns"\\"name
@@ -277,7 +277,7 @@ ZEND_API void zend_wrong_param_count(TSRMLS_D);
#define IS_CALLABLE_STRICT (IS_CALLABLE_CHECK_IS_STATIC)
-ZEND_API zend_bool zend_is_callable_ex(zval *callable, zval **object_pp, uint check_flags, char **callable_name, int *callable_name_len, zend_fcall_info_cache *fcc, char **error TSRMLS_DC);
+ZEND_API zend_bool zend_is_callable_ex(zval *callable, zval *object_ptr, uint check_flags, char **callable_name, int *callable_name_len, zend_fcall_info_cache *fcc, char **error TSRMLS_DC);
ZEND_API zend_bool zend_is_callable(zval *callable, uint check_flags, char **callable_name TSRMLS_DC);
ZEND_API zend_bool zend_make_callable(zval *callable, char **callable_name TSRMLS_DC);
ZEND_API const char *zend_get_module_version(const char *module_name);
View
@@ -209,7 +209,7 @@ static zend_object_value zend_closure_new(zend_class_entry *class_type TSRMLS_DC
}
/* }}} */
-int zend_closure_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zval **zobj_ptr, zval ***zobj_ptr_ptr TSRMLS_DC) /* {{{ */
+int zend_closure_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zval **zobj_ptr TSRMLS_DC) /* {{{ */
{
zend_closure *closure;
@@ -224,17 +224,11 @@ int zend_closure_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function
if (zobj_ptr) {
*zobj_ptr = closure->this_ptr;
}
- if (zobj_ptr_ptr) {
- *zobj_ptr_ptr = &closure->this_ptr;
- }
*ce_ptr = Z_OBJCE_P(closure->this_ptr);
} else {
if (zobj_ptr) {
*zobj_ptr = NULL;
}
- if (zobj_ptr_ptr) {
- *zobj_ptr_ptr = NULL;
- }
*ce_ptr = closure->func.common.scope;
}
return SUCCESS;
View
@@ -551,7 +551,7 @@ ZEND_METHOD(exception, __toString)
fci.function_table = &Z_OBJCE_P(exception)->function_table;
fci.function_name = &fname;
fci.symbol_table = NULL;
- fci.object_pp = &exception;
+ fci.object_ptr = exception;
fci.retval_ptr_ptr = &trace;
fci.param_count = 0;
fci.params = NULL;
View
@@ -715,7 +715,7 @@ int call_user_function_ex(HashTable *function_table, zval **object_pp, zval *fun
fci.size = sizeof(fci);
fci.function_table = function_table;
- fci.object_pp = object_pp;
+ fci.object_ptr = object_pp ? *object_pp : NULL;
fci.function_name = function_name;
fci.retval_ptr_ptr = retval_ptr_ptr;
fci.param_count = param_count;
@@ -782,7 +782,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
fci_cache = &fci_cache_local;
}
- if (!zend_is_callable_ex(fci->function_name, fci->object_pp, IS_CALLABLE_CHECK_SILENT, &callable_name, NULL, fci_cache, &error TSRMLS_CC)) {
+ if (!zend_is_callable_ex(fci->function_name, fci->object_ptr, IS_CALLABLE_CHECK_SILENT, &callable_name, NULL, fci_cache, &error TSRMLS_CC)) {
if (error) {
zend_error(E_WARNING, "Invalid callback %s, %s", callable_name, error);
efree(error);
@@ -805,10 +805,10 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
EX(function_state).function = fci_cache->function_handler;
calling_scope = fci_cache->calling_scope;
called_scope = fci_cache->called_scope;
- fci->object_pp = fci_cache->object_pp;
- EX(object) = fci->object_pp ? *fci->object_pp : NULL;
- if (fci->object_pp && *fci->object_pp && Z_TYPE_PP(fci->object_pp) == IS_OBJECT &&
- (!EG(objects_store).object_buckets || !EG(objects_store).object_buckets[Z_OBJ_HANDLE_PP(fci->object_pp)].valid)) {
+ fci->object_ptr = fci_cache->object_ptr;
+ EX(object) = fci->object_ptr;
+ if (fci->object_ptr && Z_TYPE_P(fci->object_ptr) == IS_OBJECT &&
+ (!EG(objects_store).object_buckets || !EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(fci->object_ptr)].valid)) {
return FAILURE;
}
@@ -886,11 +886,11 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
EG(called_scope) = NULL;
}
- if (fci->object_pp) {
+ if (fci->object_ptr) {
if ((EX(function_state).function->common.fn_flags & ZEND_ACC_STATIC)) {
EG(This) = NULL;
} else {
- EG(This) = *fci->object_pp;
+ EG(This) = fci->object_ptr;
if (!PZVAL_IS_REF(EG(This))) {
Z_ADDREF_P(EG(This)); /* For $this pointer */
@@ -947,7 +947,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
if (EX(function_state).function->common.scope) {
EG(scope) = EX(function_state).function->common.scope;
}
- ((zend_internal_function *) EX(function_state).function)->handler(fci->param_count, *fci->retval_ptr_ptr, fci->retval_ptr_ptr, (fci->object_pp?*fci->object_pp:NULL), 1 TSRMLS_CC);
+ ((zend_internal_function *) EX(function_state).function)->handler(fci->param_count, *fci->retval_ptr_ptr, fci->retval_ptr_ptr, fci->object_ptr, 1 TSRMLS_CC);
/* We shouldn't fix bad extensions here,
because it can break proper ones (Bug #34045)
if (!EX(function_state).function->common.return_reference)
@@ -967,8 +967,8 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
ALLOC_INIT_ZVAL(*fci->retval_ptr_ptr);
/* Not sure what should be done here if it's a static method */
- if (fci->object_pp) {
- Z_OBJ_HT_PP(fci->object_pp)->call_method(EX(function_state).function->common.function_name, fci->param_count, *fci->retval_ptr_ptr, fci->retval_ptr_ptr, *fci->object_pp, 1 TSRMLS_CC);
+ if (fci->object_ptr) {
+ Z_OBJ_HT_P(fci->object_ptr)->call_method(EX(function_state).function->common.function_name, fci->param_count, *fci->retval_ptr_ptr, fci->retval_ptr_ptr, fci->object_ptr, 1 TSRMLS_CC);
} else {
zend_error_noreturn(E_ERROR, "Cannot call overloaded function for non-object");
}
@@ -1065,14 +1065,14 @@ ZEND_API int zend_lookup_class_ex(const char *name, int name_length, int use_aut
fcall_info.retval_ptr_ptr = &retval_ptr;
fcall_info.param_count = 1;
fcall_info.params = args;
- fcall_info.object_pp = NULL;
+ fcall_info.object_ptr = NULL;
fcall_info.no_separation = 1;
fcall_cache.initialized = EG(autoload_func) ? 1 : 0;
fcall_cache.function_handler = EG(autoload_func);
fcall_cache.calling_scope = NULL;
fcall_cache.called_scope = NULL;
- fcall_cache.object_pp = NULL;
+ fcall_cache.object_ptr = NULL;
zend_exception_save(TSRMLS_C);
retval = zend_call_function(&fcall_info, &fcall_cache TSRMLS_CC);
View
@@ -46,7 +46,7 @@ ZEND_API zval* zend_call_method(zval **object_pp, zend_class_entry *obj_ce, zend
fci.size = sizeof(fci);
/*fci.function_table = NULL; will be read form zend_class_entry of object if needed */
- fci.object_pp = object_pp;
+ fci.object_ptr = object_pp ? *object_pp : NULL;
fci.function_name = &z_fname;
fci.retval_ptr_ptr = retval_ptr_ptr ? retval_ptr_ptr : &retval;
fci.param_count = param_count;
@@ -85,7 +85,7 @@ ZEND_API zval* zend_call_method(zval **object_pp, zend_class_entry *obj_ce, zend
}
fcic.calling_scope = obj_ce;
fcic.called_scope = object_pp ? obj_ce : EG(called_scope);
- fcic.object_pp = object_pp;
+ fcic.object_ptr = object_pp ? *object_pp : NULL;
result = zend_call_function(&fci, &fcic TSRMLS_CC);
}
if (result == FAILURE) {
@@ -1270,7 +1270,7 @@ ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int ty
}
/* }}} */
-int zend_std_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zval **zobj_ptr, zval ***zobj_ptr_ptr TSRMLS_DC) /* {{{ */
+int zend_std_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zval **zobj_ptr TSRMLS_DC) /* {{{ */
{
zend_class_entry *ce;
if (Z_TYPE_P(obj) != IS_OBJECT) {
@@ -1288,16 +1288,10 @@ int zend_std_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function **f
if (zobj_ptr) {
*zobj_ptr = NULL;
}
- if (zobj_ptr_ptr) {
- *zobj_ptr_ptr = NULL;
- }
} else {
if (zobj_ptr) {
*zobj_ptr = obj;
}
- if (zobj_ptr_ptr) {
- *zobj_ptr_ptr = NULL;
- }
}
return SUCCESS;
}
Oops, something went wrong.

0 comments on commit 7d4fd3f

Please sign in to comment.