Re: [ZEND-ENGINE-CVS] cvs: ZendEngine2(PHP_5_2) / zend_object_handlers.c /tests access_modifiers_011.phpt php-src NEWS

[email protected] (Jani Taskinen) Thu, 08 Jan 2009 13:03:19 +0200
Newsgroups php.zend-engine.cvs
Message-ID <[email protected]>
Andrei Zmievski wrote:
> andrei		Thu Jan  8 00:39:16 2009 UTC
> 
>   Added files:                 (Branch: PHP_5_2)
>     /ZendEngine2/tests	access_modifiers_011.phpt 
> 
>   Modified files:              
>     /php-src	NEWS 
>     /ZendEngine2	zend_object_handlers.c 
>   Log:
>   MFB
>   
>   
> http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.1381&r2=1.2027.2.547.2.1382&diff_format=u
> Index: php-src/NEWS
> diff -u php-src/NEWS:1.2027.2.547.2.1381 php-src/NEWS:1.2027.2.547.2.1382
> --- php-src/NEWS:1.2027.2.547.2.1381	Wed Jan  7 17:38:12 2009
> +++ php-src/NEWS	Thu Jan  8 00:39:14 2009
> @@ -1,6 +1,8 @@
>  PHP                                                                        NEWS
>  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
>  ?? ??? 2009, PHP 5.2.9
> +- Changed __call() to be invoked on private/protected method access, similar to
> +  properties and __get(). (Andrei)

Wasn't this actually a fix..? ;) (PHP_5_2 is supposed to be bugfix-only)

--Jani


>  - Added optional sorting type flag parameter to array_unique(). Default is
>    SORT_REGULAR. (Andrei)
>  
> http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_object_handlers.c?r1=1.135.2.6.2.30&r2=1.135.2.6.2.31&diff_format=u
> Index: ZendEngine2/zend_object_handlers.c
> diff -u ZendEngine2/zend_object_handlers.c:1.135.2.6.2.30 ZendEngine2/zend_object_handlers.c:1.135.2.6.2.31
> --- ZendEngine2/zend_object_handlers.c:1.135.2.6.2.30	Wed Dec 31 11:17:33 2008
> +++ ZendEngine2/zend_object_handlers.c	Thu Jan  8 00:39:15 2009
> @@ -17,7 +17,7 @@
>     +----------------------------------------------------------------------+
>  */
>  
> -/* $Id: zend_object_handlers.c,v 1.135.2.6.2.30 2008/12/31 11:17:33 sebastian Exp $ */
> +/* $Id: zend_object_handlers.c,v 1.135.2.6.2.31 2009/01/08 00:39:15 andrei Exp $ */
>  
>  #include "zend.h"
>  #include "zend_globals.h"
> @@ -758,6 +758,24 @@
>  }
>  
>  
> +static inline union _zend_function *zend_get_user_call_function(zend_object *zobj, char *method_name, int method_len) /* {{{ */
> +{
> +	zend_internal_function *call_user_call = emalloc(sizeof(zend_internal_function));
> +	call_user_call->type = ZEND_INTERNAL_FUNCTION;
> +	call_user_call->module = zobj->ce->module;
> +	call_user_call->handler = zend_std_call_user_call;
> +	call_user_call->arg_info = NULL;
> +	call_user_call->num_args = 0;
> +	call_user_call->scope = zobj->ce;
> +	call_user_call->fn_flags = 0;
> +	call_user_call->function_name = estrndup(method_name, method_len);
> +	call_user_call->pass_rest_by_reference = 0;
> +	call_user_call->return_reference = ZEND_RETURN_VALUE;
> +
> +	return (union _zend_function *)call_user_call;
> +}
> +/* }}} */
> +
>  static union _zend_function *zend_std_get_method(zval **object_ptr, char *method_name, int method_len TSRMLS_DC)
>  {
>  	zend_object *zobj;
> @@ -774,19 +792,7 @@
>  	if (zend_hash_find(&zobj->ce->function_table, lc_method_name, method_len+1, (void **)&fbc) == FAILURE) {
>  		free_alloca_with_limit(lc_method_name, use_heap);
>  		if (zobj->ce->__call) {
> -			zend_internal_function *call_user_call = emalloc(sizeof(zend_internal_function));
> -			call_user_call->type = ZEND_INTERNAL_FUNCTION;
> -			call_user_call->module = zobj->ce->module;
> -			call_user_call->handler = zend_std_call_user_call;
> -			call_user_call->arg_info = NULL;
> -			call_user_call->num_args = 0;
> -			call_user_call->scope = zobj->ce;
> -			call_user_call->fn_flags = 0;
> -			call_user_call->function_name = estrndup(method_name, method_len);
> -			call_user_call->pass_rest_by_reference = 0;
> -			call_user_call->return_reference = ZEND_RETURN_VALUE;
> -
> -			return (union _zend_function *)call_user_call;
> +			return zend_get_user_call_function(zobj, method_name, method_len);
>  		} else {
>  			return NULL;
>  		}
> @@ -797,12 +803,18 @@
>  		zend_function *updated_fbc;
>  
>  		/* Ensure that if we're calling a private function, we're allowed to do so.
> +		 * If we're not and __call() handler exists, invoke it, otherwise error out.
>  		 */
>  		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 %s::%s() from context '%s'", zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), method_name, EG(scope) ? EG(scope)->name : "");
> +		if (updated_fbc) {
> +			fbc = updated_fbc;
> +		} else {
> +			if (zobj->ce->__call) {
> +				fbc = zend_get_user_call_function(zobj, method_name, method_len);
> +			} else {
> +				zend_error(E_ERROR, "Call to %s method %s::%s() from context '%s'", zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), method_name, EG(scope) ? EG(scope)->name : "");
> +			}
>  		}
> -		fbc = updated_fbc;
>  	} else {
>  		/* Ensure that we haven't overridden a private function and end up calling
>  		 * the overriding public function...
> @@ -820,9 +832,14 @@
>  		}
>  		if ((fbc->common.fn_flags & ZEND_ACC_PROTECTED)) {
>  			/* Ensure that if we're calling a protected function, we're allowed to do so.
> +			 * If we're not and __call() handler exists, invoke it, otherwise error out.
>  			 */
>  			if (!zend_check_protected(zend_get_function_root_class(fbc), EG(scope))) {
> -				zend_error(E_ERROR, "Call to %s method %s::%s() from context '%s'", zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), method_name, EG(scope) ? EG(scope)->name : "");
> +				if (zobj->ce->__call) {
> +					fbc = zend_get_user_call_function(zobj, method_name, method_len);
> +				} else {
> +					zend_error(E_ERROR, "Call to %s method %s::%s() from context '%s'", zend_visibility_string(fbc->common.fn_flags), ZEND_FN_SCOPE_NAME(fbc), method_name, EG(scope) ? EG(scope)->name : "");
> +				}
>  			}
>  		}
>  	}
> 
> http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/access_modifiers_011.phpt?view=markup&rev=1.1
> Index: ZendEngine2/tests/access_modifiers_011.phpt
> +++ ZendEngine2/tests/access_modifiers_011.phpt
> 
> 
>