1999-04-08 02:10:10 +08:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| Zend Engine |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2017-01-02 23:30:12 +08:00
| Copyright ( c ) 1998 - 2017 Zend Technologies Ltd . ( http : //www.zend.com) |
1999-04-08 02:10:10 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2001-12-11 23:16:21 +08:00
| This source file is subject to version 2.00 of the Zend license , |
2006-05-13 18:37:45 +08:00
| that is bundled with this package in the file LICENSE , and is |
2003-06-11 04:04:29 +08:00
| available through the world - wide - web at the following url : |
2001-12-11 23:16:21 +08:00
| http : //www.zend.com/license/2_00.txt. |
1999-07-16 22:58:16 +08:00
| If you did not receive a copy of the Zend license and are unable to |
| obtain it through the world - wide - web , please send a note to |
| license @ zend . com so we can mail you a copy immediately . |
1999-04-08 02:10:10 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| Authors : Andi Gutmans < andi @ zend . com > |
| Zeev Suraski < zeev @ zend . com > |
2001-07-10 02:51:29 +08:00
| Andrei Zmievski < andrei @ php . net > |
2015-08-31 16:38:16 +08:00
| Dmitry Stogov < dmitry @ zend . com > |
1999-04-08 02:10:10 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
2003-02-01 09:49:15 +08:00
/* $Id$ */
1999-07-16 22:58:16 +08:00
1999-04-08 02:10:10 +08:00
# include "zend.h"
# include "zend_execute.h"
# include "zend_API.h"
2001-02-27 02:18:34 +08:00
# include "zend_modules.h"
2015-12-13 21:06:08 +08:00
# include "zend_extensions.h"
1999-04-08 02:10:10 +08:00
# include "zend_constants.h"
2016-06-04 06:42:04 +08:00
# include "zend_interfaces.h"
2008-02-02 05:27:55 +08:00
# include "zend_exceptions.h"
2008-07-14 17:49:03 +08:00
# include "zend_closures.h"
2014-09-19 06:01:05 +08:00
# include "zend_inheritance.h"
1999-04-08 02:10:10 +08:00
1999-09-07 00:14:08 +08:00
# ifdef HAVE_STDARG_H
2000-06-06 10:47:43 +08:00
# include <stdarg.h>
1999-04-08 02:10:10 +08:00
# endif
/* these variables are true statics/globals, and have to be mutex'ed on every access */
2000-10-27 07:50:17 +08:00
ZEND_API HashTable module_registry ;
1999-04-08 02:10:10 +08:00
2010-07-06 19:40:17 +08:00
static zend_module_entry * * module_request_startup_handlers ;
static zend_module_entry * * module_request_shutdown_handlers ;
static zend_module_entry * * module_post_deactivate_handlers ;
static zend_class_entry * * class_cleanup_handlers ;
2014-12-14 06:06:14 +08:00
ZEND_API int _zend_get_parameters_array_ex ( int param_count , zval * argument_array ) /* { { { */
1999-04-15 03:53:33 +08:00
{
2014-06-24 06:17:16 +08:00
zval * param_ptr ;
1999-04-21 11:49:09 +08:00
int arg_count ;
1999-04-15 03:53:33 +08:00
2014-07-03 02:01:25 +08:00
param_ptr = ZEND_CALL_ARG ( EG ( current_execute_data ) , 1 ) ;
2014-11-28 15:28:49 +08:00
arg_count = ZEND_CALL_NUM_ARGS ( EG ( current_execute_data ) ) ;
1999-04-21 11:49:09 +08:00
1999-04-15 03:53:33 +08:00
if ( param_count > arg_count ) {
return FAILURE ;
}
2000-06-10 09:08:55 +08:00
while ( param_count - - > 0 ) {
2014-06-24 06:17:16 +08:00
ZVAL_COPY_VALUE ( argument_array , param_ptr ) ;
2014-02-10 14:04:30 +08:00
argument_array + + ;
2014-06-24 06:17:16 +08:00
param_ptr + + ;
1999-04-15 03:53:33 +08:00
}
return SUCCESS ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-15 03:53:33 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_copy_parameters_array ( int param_count , zval * argument_array ) /* { { { */
2004-09-29 06:55:22 +08:00
{
2014-06-24 06:17:16 +08:00
zval * param_ptr ;
2004-09-29 06:55:22 +08:00
int arg_count ;
2014-07-03 02:01:25 +08:00
param_ptr = ZEND_CALL_ARG ( EG ( current_execute_data ) , 1 ) ;
2014-11-28 15:28:49 +08:00
arg_count = ZEND_CALL_NUM_ARGS ( EG ( current_execute_data ) ) ;
2004-09-29 06:55:22 +08:00
if ( param_count > arg_count ) {
return FAILURE ;
}
while ( param_count - - > 0 ) {
2014-06-24 06:17:16 +08:00
if ( Z_REFCOUNTED_P ( param_ptr ) ) {
Z_ADDREF_P ( param_ptr ) ;
2014-02-21 21:12:12 +08:00
}
2014-06-27 03:51:14 +08:00
zend_hash_next_index_insert_new ( Z_ARRVAL_P ( argument_array ) , param_ptr ) ;
2014-06-24 06:17:16 +08:00
param_ptr + + ;
2004-09-29 06:55:22 +08:00
}
return SUCCESS ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2004-09-29 06:55:22 +08:00
2015-08-19 19:40:56 +08:00
ZEND_API ZEND_COLD void zend_wrong_param_count ( void ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2011-09-13 21:29:35 +08:00
const char * space ;
2014-12-14 06:06:14 +08:00
const char * class_name = get_active_class_name ( & space ) ;
2007-11-03 03:40:39 +08:00
2016-08-31 03:09:26 +08:00
zend_internal_argument_count_error ( ZEND_ARG_USES_STRICT_TYPES ( ) , " Wrong parameter count for %s%s%s() " , class_name , space , get_active_function_name ( ) ) ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2001-07-10 02:51:29 +08:00
/* Argument parsing API -- andrei */
2007-11-03 03:40:39 +08:00
ZEND_API char * zend_get_type_by_const ( int type ) /* { { { */
2001-07-10 02:51:29 +08:00
{
2006-05-25 18:01:06 +08:00
switch ( type ) {
2014-04-30 22:32:42 +08:00
case IS_FALSE :
case IS_TRUE :
2014-12-13 11:35:51 +08:00
case _IS_BOOL :
2006-05-25 18:01:06 +08:00
return " boolean " ;
2014-08-26 01:24:55 +08:00
case IS_LONG :
2001-07-10 02:51:29 +08:00
return " integer " ;
case IS_DOUBLE :
2014-12-15 02:20:23 +08:00
return " float " ;
2001-07-10 02:51:29 +08:00
case IS_STRING :
return " string " ;
case IS_OBJECT :
return " object " ;
case IS_RESOURCE :
return " resource " ;
2006-05-25 18:01:06 +08:00
case IS_NULL :
return " null " ;
2011-08-16 18:44:47 +08:00
case IS_CALLABLE :
return " callable " ;
2016-06-04 06:56:13 +08:00
case IS_ITERABLE :
return " iterable " ;
2006-05-25 18:01:06 +08:00
case IS_ARRAY :
return " array " ;
2015-10-15 02:15:32 +08:00
case IS_VOID :
return " void " ;
2001-07-10 02:51:29 +08:00
default :
return " unknown " ;
}
}
2007-11-03 03:40:39 +08:00
/* }}} */
2001-07-10 02:51:29 +08:00
2008-08-13 01:20:25 +08:00
ZEND_API char * zend_zval_type_name ( const zval * arg ) /* { { { */
2006-05-25 18:01:06 +08:00
{
2014-03-27 17:39:09 +08:00
ZVAL_DEREF ( arg ) ;
2006-05-25 18:01:06 +08:00
return zend_get_type_by_const ( Z_TYPE_P ( arg ) ) ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2001-07-10 02:51:29 +08:00
2017-05-25 23:41:28 +08:00
ZEND_API zend_string * zend_zval_get_type ( const zval * arg ) /* { { { */
{
switch ( Z_TYPE_P ( arg ) ) {
case IS_NULL :
return ZSTR_KNOWN ( ZEND_STR_NULL ) ;
case IS_FALSE :
case IS_TRUE :
return ZSTR_KNOWN ( ZEND_STR_BOOLEAN ) ;
case IS_LONG :
return ZSTR_KNOWN ( ZEND_STR_INTEGER ) ;
case IS_DOUBLE :
return ZSTR_KNOWN ( ZEND_STR_DOUBLE ) ;
case IS_STRING :
return ZSTR_KNOWN ( ZEND_STR_STRING ) ;
case IS_ARRAY :
return ZSTR_KNOWN ( ZEND_STR_ARRAY ) ;
case IS_OBJECT :
return ZSTR_KNOWN ( ZEND_STR_OBJECT ) ;
case IS_RESOURCE :
if ( zend_rsrc_list_get_rsrc_type ( Z_RES_P ( arg ) ) ) {
return ZSTR_KNOWN ( ZEND_STR_RESOURCE ) ;
} else {
return ZSTR_KNOWN ( ZEND_STR_CLOSED_RESOURCE ) ;
}
default :
return NULL ;
}
}
/* }}} */
2016-12-29 03:14:43 +08:00
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error ( zend_bool throw_ , int num_args , int min_num_args , int max_num_args ) /* { { { */
2014-07-11 20:32:20 +08:00
{
zend_function * active_function = EG ( current_execute_data ) - > func ;
2015-06-30 18:59:27 +08:00
const char * class_name = active_function - > common . scope ? ZSTR_VAL ( active_function - > common . scope - > name ) : " " ;
2014-07-11 20:32:20 +08:00
2016-08-31 03:09:26 +08:00
zend_internal_argument_count_error (
2016-12-29 03:14:43 +08:00
throw_ | | ZEND_ARG_USES_STRICT_TYPES ( ) ,
2016-08-31 03:09:26 +08:00
" %s%s%s() expects %s %d parameter%s, %d given " ,
class_name , \
class_name [ 0 ] ? " :: " : " " , \
ZSTR_VAL ( active_function - > common . function_name ) ,
min_num_args = = max_num_args ? " exactly " : num_args < min_num_args ? " at least " : " at most " ,
num_args < min_num_args ? min_num_args : max_num_args ,
( num_args < min_num_args ? min_num_args : max_num_args ) = = 1 ? " " : " s " ,
num_args ) ;
2014-07-11 20:32:20 +08:00
}
/* }}} */
2016-12-29 03:14:43 +08:00
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_type_error ( zend_bool throw_ , int num , zend_expected_type expected_type , zval * arg ) /* { { { */
2014-07-11 20:32:20 +08:00
{
const char * space ;
2014-12-14 06:06:14 +08:00
const char * class_name = get_active_class_name ( & space ) ;
2014-07-11 20:32:20 +08:00
static const char * const expected_error [ ] = {
Z_EXPECTED_TYPES ( Z_EXPECTED_TYPE_STR )
NULL
} ;
2016-12-29 03:14:43 +08:00
zend_internal_type_error ( throw_ | | ZEND_ARG_USES_STRICT_TYPES ( ) , " %s%s%s() expects parameter %d to be %s, %s given " ,
2014-12-14 06:06:14 +08:00
class_name , space , get_active_function_name ( ) , num , expected_error [ expected_type ] , zend_zval_type_name ( arg ) ) ;
2014-07-11 20:32:20 +08:00
}
/* }}} */
2016-12-29 03:14:43 +08:00
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameter_class_error ( zend_bool throw_ , int num , char * name , zval * arg ) /* { { { */
2014-07-11 20:32:20 +08:00
{
const char * space ;
2014-12-14 06:06:14 +08:00
const char * class_name = get_active_class_name ( & space ) ;
2014-07-11 20:32:20 +08:00
2016-12-29 03:14:43 +08:00
zend_internal_type_error ( throw_ | | ZEND_ARG_USES_STRICT_TYPES ( ) , " %s%s%s() expects parameter %d to be %s, %s given " ,
2014-12-14 06:06:14 +08:00
class_name , space , get_active_function_name ( ) , num , name , zend_zval_type_name ( arg ) ) ;
2014-07-11 20:32:20 +08:00
}
/* }}} */
2016-12-29 03:14:43 +08:00
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error ( zend_bool throw_ , int severity , int num , char * error ) /* { { { */
2014-07-11 20:32:20 +08:00
{
const char * space ;
2014-12-14 06:06:14 +08:00
const char * class_name = get_active_class_name ( & space ) ;
2014-07-11 20:32:20 +08:00
2015-03-20 00:26:34 +08:00
if ( severity = = E_WARNING ) {
2016-12-29 03:14:43 +08:00
zend_internal_type_error ( throw_ | | ZEND_ARG_USES_STRICT_TYPES ( ) , " %s%s%s() expects parameter %d to be a valid callback, %s " ,
2015-03-20 00:26:34 +08:00
class_name , space , get_active_function_name ( ) , num , error ) ;
2015-07-04 05:04:33 +08:00
} else if ( severity = = E_ERROR ) {
2015-07-07 04:03:35 +08:00
zend_throw_error ( zend_ce_type_error , " %s%s%s() expects parameter %d to be a valid callback, %s " ,
2015-07-04 05:04:33 +08:00
class_name , space , get_active_function_name ( ) , num , error ) ;
2015-03-20 00:26:34 +08:00
} else {
2015-07-04 05:04:33 +08:00
zend_error ( severity , " %s%s%s() expects parameter %d to be a valid callback, %s " ,
2015-03-20 00:26:34 +08:00
class_name , space , get_active_function_name ( ) , num , error ) ;
}
2014-07-11 20:32:20 +08:00
efree ( error ) ;
}
/* }}} */
2015-03-21 04:18:52 +08:00
ZEND_API int ZEND_FASTCALL zend_parse_arg_class ( zval * arg , zend_class_entry * * pce , int num , int check_null ) /* { { { */
2014-07-11 20:32:20 +08:00
{
zend_class_entry * ce_base = * pce ;
if ( check_null & & Z_TYPE_P ( arg ) = = IS_NULL ) {
* pce = NULL ;
return 1 ;
}
convert_to_string_ex ( arg ) ;
2014-12-14 06:06:14 +08:00
* pce = zend_lookup_class ( Z_STR_P ( arg ) ) ;
2014-07-11 20:32:20 +08:00
if ( ce_base ) {
2014-12-14 06:06:14 +08:00
if ( ( ! * pce | | ! instanceof_function ( * pce , ce_base ) ) ) {
2014-07-11 20:32:20 +08:00
const char * space ;
2014-12-14 06:06:14 +08:00
const char * class_name = get_active_class_name ( & space ) ;
2014-07-11 20:32:20 +08:00
2015-03-21 04:18:52 +08:00
zend_internal_type_error ( ZEND_ARG_USES_STRICT_TYPES ( ) , " %s%s%s() expects parameter %d to be a class name derived from %s, '%s' given " ,
2014-12-14 06:06:14 +08:00
class_name , space , get_active_function_name ( ) , num ,
2015-06-30 18:59:27 +08:00
ZSTR_VAL ( ce_base - > name ) , Z_STRVAL_P ( arg ) ) ;
2014-07-11 20:32:20 +08:00
* pce = NULL ;
return 0 ;
}
}
if ( ! * pce ) {
const char * space ;
2014-12-14 06:06:14 +08:00
const char * class_name = get_active_class_name ( & space ) ;
2014-07-11 20:32:20 +08:00
2015-03-21 04:18:52 +08:00
zend_internal_type_error ( ZEND_ARG_USES_STRICT_TYPES ( ) , " %s%s%s() expects parameter %d to be a valid class name, '%s' given " ,
2014-12-14 06:06:14 +08:00
class_name , space , get_active_function_name ( ) , num ,
2014-07-11 20:32:20 +08:00
Z_STRVAL_P ( arg ) ) ;
return 0 ;
}
return 1 ;
}
/* }}} */
2015-03-21 04:18:52 +08:00
ZEND_API int ZEND_FASTCALL zend_parse_arg_bool_weak ( zval * arg , zend_bool * dest ) /* { { { */
{
if ( EXPECTED ( Z_TYPE_P ( arg ) < = IS_STRING ) ) {
* dest = zend_is_true ( arg ) ;
} else {
return 0 ;
}
return 1 ;
}
/* }}} */
ZEND_API int ZEND_FASTCALL zend_parse_arg_bool_slow ( zval * arg , zend_bool * dest ) /* { { { */
{
if ( UNEXPECTED ( ZEND_ARG_USES_STRICT_TYPES ( ) ) ) {
return 0 ;
}
return zend_parse_arg_bool_weak ( arg , dest ) ;
}
/* }}} */
ZEND_API int ZEND_FASTCALL zend_parse_arg_long_weak ( zval * arg , zend_long * dest ) /* { { { */
{
if ( EXPECTED ( Z_TYPE_P ( arg ) = = IS_DOUBLE ) ) {
if ( UNEXPECTED ( zend_isnan ( Z_DVAL_P ( arg ) ) ) ) {
return 0 ;
}
if ( UNEXPECTED ( ! ZEND_DOUBLE_FITS_LONG ( Z_DVAL_P ( arg ) ) ) ) {
return 0 ;
} else {
* dest = zend_dval_to_lval ( Z_DVAL_P ( arg ) ) ;
}
} else if ( EXPECTED ( Z_TYPE_P ( arg ) = = IS_STRING ) ) {
double d ;
int type ;
if ( UNEXPECTED ( ( type = is_numeric_str_function ( Z_STR_P ( arg ) , dest , & d ) ) ! = IS_LONG ) ) {
if ( EXPECTED ( type ! = 0 ) ) {
if ( UNEXPECTED ( zend_isnan ( d ) ) ) {
return 0 ;
}
if ( UNEXPECTED ( ! ZEND_DOUBLE_FITS_LONG ( d ) ) ) {
return 0 ;
} else {
* dest = zend_dval_to_lval ( d ) ;
}
} else {
return 0 ;
}
}
} else if ( EXPECTED ( Z_TYPE_P ( arg ) < IS_TRUE ) ) {
* dest = 0 ;
} else if ( EXPECTED ( Z_TYPE_P ( arg ) = = IS_TRUE ) ) {
* dest = 1 ;
} else {
return 0 ;
}
return 1 ;
}
/* }}} */
ZEND_API int ZEND_FASTCALL zend_parse_arg_long_slow ( zval * arg , zend_long * dest ) /* { { { */
{
if ( UNEXPECTED ( ZEND_ARG_USES_STRICT_TYPES ( ) ) ) {
return 0 ;
}
return zend_parse_arg_long_weak ( arg , dest ) ;
}
/* }}} */
ZEND_API int ZEND_FASTCALL zend_parse_arg_long_cap_weak ( zval * arg , zend_long * dest ) /* { { { */
{
if ( EXPECTED ( Z_TYPE_P ( arg ) = = IS_DOUBLE ) ) {
if ( UNEXPECTED ( zend_isnan ( Z_DVAL_P ( arg ) ) ) ) {
return 0 ;
}
2016-03-30 08:44:27 +08:00
* dest = zend_dval_to_lval_cap ( Z_DVAL_P ( arg ) ) ;
2015-03-21 04:18:52 +08:00
} else if ( EXPECTED ( Z_TYPE_P ( arg ) = = IS_STRING ) ) {
double d ;
int type ;
if ( UNEXPECTED ( ( type = is_numeric_str_function ( Z_STR_P ( arg ) , dest , & d ) ) ! = IS_LONG ) ) {
if ( EXPECTED ( type ! = 0 ) ) {
if ( UNEXPECTED ( zend_isnan ( d ) ) ) {
return 0 ;
}
2016-03-30 08:44:27 +08:00
* dest = zend_dval_to_lval_cap ( d ) ;
2015-03-21 04:18:52 +08:00
} else {
return 0 ;
}
}
} else if ( EXPECTED ( Z_TYPE_P ( arg ) < IS_TRUE ) ) {
* dest = 0 ;
} else if ( EXPECTED ( Z_TYPE_P ( arg ) = = IS_TRUE ) ) {
* dest = 1 ;
} else {
return 0 ;
}
return 1 ;
}
/* }}} */
ZEND_API int ZEND_FASTCALL zend_parse_arg_long_cap_slow ( zval * arg , zend_long * dest ) /* { { { */
{
if ( UNEXPECTED ( ZEND_ARG_USES_STRICT_TYPES ( ) ) ) {
return 0 ;
}
return zend_parse_arg_long_cap_weak ( arg , dest ) ;
}
/* }}} */
ZEND_API int ZEND_FASTCALL zend_parse_arg_double_weak ( zval * arg , double * dest ) /* { { { */
{
if ( EXPECTED ( Z_TYPE_P ( arg ) = = IS_LONG ) ) {
* dest = ( double ) Z_LVAL_P ( arg ) ;
} else if ( EXPECTED ( Z_TYPE_P ( arg ) = = IS_STRING ) ) {
zend_long l ;
int type ;
if ( UNEXPECTED ( ( type = is_numeric_str_function ( Z_STR_P ( arg ) , & l , dest ) ) ! = IS_DOUBLE ) ) {
if ( EXPECTED ( type ! = 0 ) ) {
* dest = ( double ) ( l ) ;
} else {
return 0 ;
}
}
} else if ( EXPECTED ( Z_TYPE_P ( arg ) < IS_TRUE ) ) {
* dest = 0.0 ;
} else if ( EXPECTED ( Z_TYPE_P ( arg ) = = IS_TRUE ) ) {
* dest = 1.0 ;
} else {
return 0 ;
}
return 1 ;
}
/* }}} */
ZEND_API int ZEND_FASTCALL zend_parse_arg_double_slow ( zval * arg , double * dest ) /* { { { */
{
if ( EXPECTED ( Z_TYPE_P ( arg ) = = IS_LONG ) ) {
/* SSTH Exception: IS_LONG may be accepted instead as IS_DOUBLE */
* dest = ( double ) Z_LVAL_P ( arg ) ;
} else if ( UNEXPECTED ( ZEND_ARG_USES_STRICT_TYPES ( ) ) ) {
return 0 ;
}
return zend_parse_arg_double_weak ( arg , dest ) ;
}
/* }}} */
ZEND_API int ZEND_FASTCALL zend_parse_arg_str_weak ( zval * arg , zend_string * * dest ) /* { { { */
{
if ( EXPECTED ( Z_TYPE_P ( arg ) < IS_STRING ) ) {
convert_to_string ( arg ) ;
* dest = Z_STR_P ( arg ) ;
} else if ( UNEXPECTED ( Z_TYPE_P ( arg ) = = IS_OBJECT ) ) {
if ( Z_OBJ_HANDLER_P ( arg , cast_object ) ) {
zval obj ;
if ( Z_OBJ_HANDLER_P ( arg , cast_object ) ( arg , & obj , IS_STRING ) = = SUCCESS ) {
zval_ptr_dtor ( arg ) ;
ZVAL_COPY_VALUE ( arg , & obj ) ;
* dest = Z_STR_P ( arg ) ;
return 1 ;
}
2015-06-22 21:33:41 +08:00
} else if ( Z_OBJ_HANDLER_P ( arg , get ) ) {
2015-03-21 04:18:52 +08:00
zval rv ;
zval * z = Z_OBJ_HANDLER_P ( arg , get ) ( arg , & rv ) ;
Z_ADDREF_P ( z ) ;
if ( Z_TYPE_P ( z ) ! = IS_OBJECT ) {
2016-05-06 14:23:37 +08:00
zval_dtor ( arg ) ;
2015-03-21 04:18:52 +08:00
ZVAL_NULL ( arg ) ;
if ( ! zend_make_printable_zval ( z , arg ) ) {
2015-06-12 17:33:23 +08:00
ZVAL_COPY_VALUE ( arg , z ) ;
2015-03-21 04:18:52 +08:00
}
* dest = Z_STR_P ( arg ) ;
return 1 ;
}
zval_ptr_dtor ( z ) ;
}
return 0 ;
} else {
return 0 ;
}
return 1 ;
}
/* }}} */
ZEND_API int ZEND_FASTCALL zend_parse_arg_str_slow ( zval * arg , zend_string * * dest ) /* { { { */
{
if ( UNEXPECTED ( ZEND_ARG_USES_STRICT_TYPES ( ) ) ) {
return 0 ;
}
return zend_parse_arg_str_weak ( arg , dest ) ;
}
/* }}} */
static const char * zend_parse_arg_impl ( int arg_num , zval * arg , va_list * va , const char * * spec , char * * error , int * severity ) /* { { { */
2001-07-10 02:51:29 +08:00
{
2010-10-15 05:33:10 +08:00
const char * spec_walk = * spec ;
2001-07-10 02:51:29 +08:00
char c = * spec_walk + + ;
zend_parse_parameters: allow ! for non pointers
This commit allows getting information about whether a certain value
was a NULL value by using the ! modifier together with the l/L, d and
b.
Example:
long l;
zend_bool is_null;
zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l!", &l, &is_null)
For the specifiers l/L, d and b, NULL values are reported as 0, 0., or
false. But sometimes one wants to distinguish NULL from those other
values -- for instance, to give NULL the same effect as the argument
not having been passed.
The usual way this problem is handled is by fetching the parameter
with 'z' or 'Z', check if it is NULL and if not use
convert_to_long_ex()/convert_to_double_ex(), etc. Unfortunately, this
is not equivalent. convert_to_long_ex() does a cast, while zpp() is
stricter. For instance, zpp will not accept 'foo' for a long argument,
and it will emit a notice when encountering '5foo'.
In fact, the only way to otherwise zpp semantics (without duplicating
its logic) is to fetch the raw zval from the stack and check whether
it's NULL (with zpp itself or its relatives) and then run zpp again.
That is not an elegant solution.
2012-07-19 03:42:36 +08:00
int check_null = 0 ;
2016-06-08 04:18:52 +08:00
int separate = 0 ;
2014-02-19 18:35:28 +08:00
zval * real_arg = arg ;
2001-07-10 02:51:29 +08:00
2007-11-03 03:40:39 +08:00
/* scan through modifiers */
2014-06-05 20:04:11 +08:00
ZVAL_DEREF ( arg ) ;
2007-11-03 03:40:39 +08:00
while ( 1 ) {
2001-07-10 02:51:29 +08:00
if ( * spec_walk = = ' / ' ) {
2015-09-29 16:17:43 +08:00
SEPARATE_ZVAL_NOREF ( arg ) ;
2014-06-05 20:04:11 +08:00
real_arg = arg ;
2016-06-08 04:18:52 +08:00
separate = 1 ;
2007-11-03 03:40:39 +08:00
} else if ( * spec_walk = = ' ! ' ) {
zend_parse_parameters: allow ! for non pointers
This commit allows getting information about whether a certain value
was a NULL value by using the ! modifier together with the l/L, d and
b.
Example:
long l;
zend_bool is_null;
zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l!", &l, &is_null)
For the specifiers l/L, d and b, NULL values are reported as 0, 0., or
false. But sometimes one wants to distinguish NULL from those other
values -- for instance, to give NULL the same effect as the argument
not having been passed.
The usual way this problem is handled is by fetching the parameter
with 'z' or 'Z', check if it is NULL and if not use
convert_to_long_ex()/convert_to_double_ex(), etc. Unfortunately, this
is not equivalent. convert_to_long_ex() does a cast, while zpp() is
stricter. For instance, zpp will not accept 'foo' for a long argument,
and it will emit a notice when encountering '5foo'.
In fact, the only way to otherwise zpp semantics (without duplicating
its logic) is to fetch the raw zval from the stack and check whether
it's NULL (with zpp itself or its relatives) and then run zpp again.
That is not an elegant solution.
2012-07-19 03:42:36 +08:00
check_null = 1 ;
2007-11-03 03:40:39 +08:00
} else {
break ;
2001-07-10 02:51:29 +08:00
}
spec_walk + + ;
}
switch ( c ) {
case ' l ' :
2009-06-05 02:20:45 +08:00
case ' L ' :
2001-07-10 02:51:29 +08:00
{
2014-08-26 01:24:55 +08:00
zend_long * p = va_arg ( * va , zend_long * ) ;
2014-12-15 08:51:41 +08:00
zend_bool * is_null = NULL ;
zend_parse_parameters: allow ! for non pointers
This commit allows getting information about whether a certain value
was a NULL value by using the ! modifier together with the l/L, d and
b.
Example:
long l;
zend_bool is_null;
zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l!", &l, &is_null)
For the specifiers l/L, d and b, NULL values are reported as 0, 0., or
false. But sometimes one wants to distinguish NULL from those other
values -- for instance, to give NULL the same effect as the argument
not having been passed.
The usual way this problem is handled is by fetching the parameter
with 'z' or 'Z', check if it is NULL and if not use
convert_to_long_ex()/convert_to_double_ex(), etc. Unfortunately, this
is not equivalent. convert_to_long_ex() does a cast, while zpp() is
stricter. For instance, zpp will not accept 'foo' for a long argument,
and it will emit a notice when encountering '5foo'.
In fact, the only way to otherwise zpp semantics (without duplicating
its logic) is to fetch the raw zval from the stack and check whether
it's NULL (with zpp itself or its relatives) and then run zpp again.
That is not an elegant solution.
2012-07-19 03:42:36 +08:00
if ( check_null ) {
2014-12-15 08:51:41 +08:00
is_null = va_arg ( * va , zend_bool * ) ;
zend_parse_parameters: allow ! for non pointers
This commit allows getting information about whether a certain value
was a NULL value by using the ! modifier together with the l/L, d and
b.
Example:
long l;
zend_bool is_null;
zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l!", &l, &is_null)
For the specifiers l/L, d and b, NULL values are reported as 0, 0., or
false. But sometimes one wants to distinguish NULL from those other
values -- for instance, to give NULL the same effect as the argument
not having been passed.
The usual way this problem is handled is by fetching the parameter
with 'z' or 'Z', check if it is NULL and if not use
convert_to_long_ex()/convert_to_double_ex(), etc. Unfortunately, this
is not equivalent. convert_to_long_ex() does a cast, while zpp() is
stricter. For instance, zpp will not accept 'foo' for a long argument,
and it will emit a notice when encountering '5foo'.
In fact, the only way to otherwise zpp semantics (without duplicating
its logic) is to fetch the raw zval from the stack and check whether
it's NULL (with zpp itself or its relatives) and then run zpp again.
That is not an elegant solution.
2012-07-19 03:42:36 +08:00
}
2015-03-21 04:18:52 +08:00
if ( ! zend_parse_arg_long ( arg , p , is_null , check_null , c = = ' L ' ) ) {
2014-12-15 08:51:41 +08:00
return " integer " ;
2001-07-10 02:51:29 +08:00
}
}
break ;
case ' d ' :
{
double * p = va_arg ( * va , double * ) ;
2014-12-15 08:51:41 +08:00
zend_bool * is_null = NULL ;
zend_parse_parameters: allow ! for non pointers
This commit allows getting information about whether a certain value
was a NULL value by using the ! modifier together with the l/L, d and
b.
Example:
long l;
zend_bool is_null;
zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l!", &l, &is_null)
For the specifiers l/L, d and b, NULL values are reported as 0, 0., or
false. But sometimes one wants to distinguish NULL from those other
values -- for instance, to give NULL the same effect as the argument
not having been passed.
The usual way this problem is handled is by fetching the parameter
with 'z' or 'Z', check if it is NULL and if not use
convert_to_long_ex()/convert_to_double_ex(), etc. Unfortunately, this
is not equivalent. convert_to_long_ex() does a cast, while zpp() is
stricter. For instance, zpp will not accept 'foo' for a long argument,
and it will emit a notice when encountering '5foo'.
In fact, the only way to otherwise zpp semantics (without duplicating
its logic) is to fetch the raw zval from the stack and check whether
it's NULL (with zpp itself or its relatives) and then run zpp again.
That is not an elegant solution.
2012-07-19 03:42:36 +08:00
if ( check_null ) {
2014-12-15 08:51:41 +08:00
is_null = va_arg ( * va , zend_bool * ) ;
zend_parse_parameters: allow ! for non pointers
This commit allows getting information about whether a certain value
was a NULL value by using the ! modifier together with the l/L, d and
b.
Example:
long l;
zend_bool is_null;
zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l!", &l, &is_null)
For the specifiers l/L, d and b, NULL values are reported as 0, 0., or
false. But sometimes one wants to distinguish NULL from those other
values -- for instance, to give NULL the same effect as the argument
not having been passed.
The usual way this problem is handled is by fetching the parameter
with 'z' or 'Z', check if it is NULL and if not use
convert_to_long_ex()/convert_to_double_ex(), etc. Unfortunately, this
is not equivalent. convert_to_long_ex() does a cast, while zpp() is
stricter. For instance, zpp will not accept 'foo' for a long argument,
and it will emit a notice when encountering '5foo'.
In fact, the only way to otherwise zpp semantics (without duplicating
its logic) is to fetch the raw zval from the stack and check whether
it's NULL (with zpp itself or its relatives) and then run zpp again.
That is not an elegant solution.
2012-07-19 03:42:36 +08:00
}
2015-03-21 04:18:52 +08:00
if ( ! zend_parse_arg_double ( arg , p , is_null , check_null ) ) {
2014-12-15 08:51:41 +08:00
return " float " ;
2001-07-10 02:51:29 +08:00
}
}
break ;
case ' s ' :
{
char * * p = va_arg ( * va , char * * ) ;
2014-08-27 21:31:48 +08:00
size_t * pl = va_arg ( * va , size_t * ) ;
2015-03-21 04:18:52 +08:00
if ( ! zend_parse_arg_string ( arg , p , pl , check_null ) ) {
2014-12-15 08:51:41 +08:00
return " string " ;
}
}
break ;
2015-01-03 17:22:58 +08:00
2014-12-15 08:51:41 +08:00
case ' p ' :
{
char * * p = va_arg ( * va , char * * ) ;
size_t * pl = va_arg ( * va , size_t * ) ;
2015-03-21 04:18:52 +08:00
if ( ! zend_parse_arg_path ( arg , p , pl , check_null ) ) {
2014-12-15 08:51:41 +08:00
return " a valid path " ;
2001-07-10 02:51:29 +08:00
}
}
break ;
2014-05-05 10:49:27 +08:00
case ' P ' :
2014-12-15 08:51:41 +08:00
{
zend_string * * str = va_arg ( * va , zend_string * * ) ;
2015-03-21 04:18:52 +08:00
if ( ! zend_parse_arg_path_str ( arg , str , check_null ) ) {
2014-12-15 08:51:41 +08:00
return " a valid path " ;
}
}
break ;
2014-02-10 14:04:30 +08:00
case ' S ' :
{
zend_string * * str = va_arg ( * va , zend_string * * ) ;
2015-03-21 04:18:52 +08:00
if ( ! zend_parse_arg_str ( arg , str , check_null ) ) {
2014-12-15 08:51:41 +08:00
return " string " ;
2014-02-10 14:04:30 +08:00
}
}
break ;
2001-07-10 02:51:29 +08:00
case ' b ' :
{
zend_bool * p = va_arg ( * va , zend_bool * ) ;
2014-12-15 08:51:41 +08:00
zend_bool * is_null = NULL ;
zend_parse_parameters: allow ! for non pointers
This commit allows getting information about whether a certain value
was a NULL value by using the ! modifier together with the l/L, d and
b.
Example:
long l;
zend_bool is_null;
zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l!", &l, &is_null)
For the specifiers l/L, d and b, NULL values are reported as 0, 0., or
false. But sometimes one wants to distinguish NULL from those other
values -- for instance, to give NULL the same effect as the argument
not having been passed.
The usual way this problem is handled is by fetching the parameter
with 'z' or 'Z', check if it is NULL and if not use
convert_to_long_ex()/convert_to_double_ex(), etc. Unfortunately, this
is not equivalent. convert_to_long_ex() does a cast, while zpp() is
stricter. For instance, zpp will not accept 'foo' for a long argument,
and it will emit a notice when encountering '5foo'.
In fact, the only way to otherwise zpp semantics (without duplicating
its logic) is to fetch the raw zval from the stack and check whether
it's NULL (with zpp itself or its relatives) and then run zpp again.
That is not an elegant solution.
2012-07-19 03:42:36 +08:00
if ( check_null ) {
2014-12-15 08:51:41 +08:00
is_null = va_arg ( * va , zend_bool * ) ;
zend_parse_parameters: allow ! for non pointers
This commit allows getting information about whether a certain value
was a NULL value by using the ! modifier together with the l/L, d and
b.
Example:
long l;
zend_bool is_null;
zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l!", &l, &is_null)
For the specifiers l/L, d and b, NULL values are reported as 0, 0., or
false. But sometimes one wants to distinguish NULL from those other
values -- for instance, to give NULL the same effect as the argument
not having been passed.
The usual way this problem is handled is by fetching the parameter
with 'z' or 'Z', check if it is NULL and if not use
convert_to_long_ex()/convert_to_double_ex(), etc. Unfortunately, this
is not equivalent. convert_to_long_ex() does a cast, while zpp() is
stricter. For instance, zpp will not accept 'foo' for a long argument,
and it will emit a notice when encountering '5foo'.
In fact, the only way to otherwise zpp semantics (without duplicating
its logic) is to fetch the raw zval from the stack and check whether
it's NULL (with zpp itself or its relatives) and then run zpp again.
That is not an elegant solution.
2012-07-19 03:42:36 +08:00
}
2015-03-21 04:18:52 +08:00
if ( ! zend_parse_arg_bool ( arg , p , is_null , check_null ) ) {
2014-12-15 08:51:41 +08:00
return " boolean " ;
2001-07-10 02:51:29 +08:00
}
}
break ;
case ' r ' :
{
zval * * p = va_arg ( * va , zval * * ) ;
2014-12-15 08:51:41 +08:00
if ( ! zend_parse_arg_resource ( arg , p , check_null ) ) {
2007-11-03 03:40:39 +08:00
return " resource " ;
2006-05-10 07:53:23 +08:00
}
2001-07-10 02:51:29 +08:00
}
break ;
2014-12-15 08:51:41 +08:00
2008-11-25 02:10:36 +08:00
case ' A ' :
2001-07-10 02:51:29 +08:00
case ' a ' :
{
zval * * p = va_arg ( * va , zval * * ) ;
2014-12-15 08:51:41 +08:00
if ( ! zend_parse_arg_array ( arg , p , check_null , c = = ' A ' ) ) {
2007-11-03 03:40:39 +08:00
return " array " ;
2006-05-10 07:53:23 +08:00
}
2001-07-10 02:51:29 +08:00
}
break ;
2014-12-15 08:51:41 +08:00
2008-11-25 02:10:36 +08:00
case ' H ' :
2006-01-26 06:03:18 +08:00
case ' h ' :
{
HashTable * * p = va_arg ( * va , HashTable * * ) ;
2014-12-15 08:51:41 +08:00
2016-06-08 04:18:52 +08:00
if ( ! zend_parse_arg_array_ht ( arg , p , check_null , c = = ' H ' , separate ) ) {
2007-11-03 03:40:39 +08:00
return " array " ;
2006-01-26 06:03:18 +08:00
}
}
break ;
2001-07-10 02:51:29 +08:00
case ' o ' :
{
zval * * p = va_arg ( * va , zval * * ) ;
2014-12-15 08:51:41 +08:00
if ( ! zend_parse_arg_object ( arg , p , NULL , check_null ) ) {
2007-11-03 03:40:39 +08:00
return " object " ;
2006-05-10 07:53:23 +08:00
}
2001-07-10 02:51:29 +08:00
}
break ;
case ' O ' :
{
zval * * p = va_arg ( * va , zval * * ) ;
zend_class_entry * ce = va_arg ( * va , zend_class_entry * ) ;
2003-08-02 01:51:56 +08:00
2014-12-15 08:51:41 +08:00
if ( ! zend_parse_arg_object ( arg , p , ce , check_null ) ) {
2007-11-03 03:40:39 +08:00
if ( ce ) {
2015-06-30 18:59:27 +08:00
return ZSTR_VAL ( ce - > name ) ;
2001-07-10 02:51:29 +08:00
} else {
2006-05-28 03:06:06 +08:00
return " object " ;
2001-07-10 02:51:29 +08:00
}
2003-08-02 01:51:56 +08:00
}
2001-07-10 02:51:29 +08:00
}
break ;
2006-02-28 06:23:21 +08:00
case ' C ' :
{
2014-02-10 14:04:30 +08:00
zend_class_entry * lookup , * * pce = va_arg ( * va , zend_class_entry * * ) ;
2006-02-28 06:23:21 +08:00
zend_class_entry * ce_base = * pce ;
2014-02-10 14:04:30 +08:00
if ( check_null & & Z_TYPE_P ( arg ) = = IS_NULL ) {
2006-05-24 06:22:11 +08:00
* pce = NULL ;
break ;
}
2006-02-28 06:23:21 +08:00
convert_to_string_ex ( arg ) ;
2014-12-14 06:06:14 +08:00
if ( ( lookup = zend_lookup_class ( Z_STR_P ( arg ) ) ) = = NULL ) {
2006-02-28 06:23:21 +08:00
* pce = NULL ;
} else {
2014-02-10 14:04:30 +08:00
* pce = lookup ;
2006-02-28 06:23:21 +08:00
}
if ( ce_base ) {
2014-12-14 06:06:14 +08:00
if ( ( ! * pce | | ! instanceof_function ( * pce , ce_base ) ) ) {
2008-02-02 05:27:55 +08:00
zend_spprintf ( error , 0 , " to be a class name derived from %s, '%s' given " ,
2015-06-30 18:59:27 +08:00
ZSTR_VAL ( ce_base - > name ) , Z_STRVAL_P ( arg ) ) ;
2006-02-28 06:23:21 +08:00
* pce = NULL ;
return " " ;
}
}
2006-05-24 06:22:11 +08:00
if ( ! * pce ) {
2008-02-02 05:27:55 +08:00
zend_spprintf ( error , 0 , " to be a valid class name, '%s' given " ,
2014-02-10 14:04:30 +08:00
Z_STRVAL_P ( arg ) ) ;
2006-02-28 06:23:21 +08:00
return " " ;
}
break ;
}
break ;
2006-06-07 17:43:54 +08:00
case ' f ' :
{
2007-11-03 03:40:39 +08:00
zend_fcall_info * fci = va_arg ( * va , zend_fcall_info * ) ;
2006-06-07 17:43:54 +08:00
zend_fcall_info_cache * fcc = va_arg ( * va , zend_fcall_info_cache * ) ;
2008-02-02 05:27:55 +08:00
char * is_callable_error = NULL ;
2006-06-07 17:43:54 +08:00
2014-02-10 14:04:30 +08:00
if ( check_null & & Z_TYPE_P ( arg ) = = IS_NULL ) {
2006-06-07 17:43:54 +08:00
fci - > size = 0 ;
fcc - > initialized = 0 ;
break ;
2007-11-03 03:40:39 +08:00
}
2014-12-14 06:06:14 +08:00
if ( zend_fcall_info_init ( arg , 0 , fci , fcc , NULL , & is_callable_error ) = = SUCCESS ) {
2008-02-02 05:27:55 +08:00
if ( is_callable_error ) {
2015-03-15 16:47:25 +08:00
* severity = E_DEPRECATED ;
2015-03-22 16:24:56 +08:00
zend_spprintf ( error , 0 , " to be a valid callback, %s " , is_callable_error ) ;
2008-02-02 05:27:55 +08:00
efree ( is_callable_error ) ;
2008-02-02 23:18:30 +08:00
* spec = spec_walk ;
2008-02-02 05:27:55 +08:00
return " " ;
}
2007-11-03 03:40:39 +08:00
break ;
2006-06-07 17:43:54 +08:00
} else {
2008-02-02 05:27:55 +08:00
if ( is_callable_error ) {
2015-07-04 05:04:33 +08:00
* severity = E_ERROR ;
2015-03-22 16:24:56 +08:00
zend_spprintf ( error , 0 , " to be a valid callback, %s " , is_callable_error ) ;
2008-02-02 05:27:55 +08:00
efree ( is_callable_error ) ;
return " " ;
} else {
return " valid callback " ;
}
2006-06-07 17:43:54 +08:00
}
}
2001-07-10 02:51:29 +08:00
case ' z ' :
{
zval * * p = va_arg ( * va , zval * * ) ;
2014-12-15 08:51:41 +08:00
zend_parse_arg_zval_deref ( real_arg , p , check_null ) ;
2003-07-11 18:21:39 +08:00
}
break ;
2007-11-03 03:40:39 +08:00
2014-02-10 14:04:30 +08:00
case ' Z ' :
2014-04-16 01:56:30 +08:00
/* 'Z' iz not supported anymore and should be replaced with 'z' */
2014-02-21 21:22:02 +08:00
ZEND_ASSERT ( c ! = ' Z ' ) ;
2001-07-10 02:51:29 +08:00
default :
return " unknown " ;
}
* spec = spec_walk ;
return NULL ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2001-07-10 02:51:29 +08:00
2015-03-21 04:18:52 +08:00
static int zend_parse_arg ( int arg_num , zval * arg , va_list * va , const char * * spec , int flags ) /* { { { */
2001-07-10 02:51:29 +08:00
{
2011-09-13 21:29:35 +08:00
const char * expected_type = NULL ;
char * error = NULL ;
2015-03-22 07:14:47 +08:00
int severity = 0 ;
2001-07-10 02:51:29 +08:00
2015-03-21 04:18:52 +08:00
expected_type = zend_parse_arg_impl ( arg_num , arg , va , spec , & error , & severity ) ;
2001-07-10 02:51:29 +08:00
if ( expected_type ) {
2015-03-21 04:18:52 +08:00
if ( ! ( flags & ZEND_PARSE_PARAMS_QUIET ) & & ( * expected_type | | error ) ) {
2011-09-13 21:29:35 +08:00
const char * space ;
2014-12-14 06:06:14 +08:00
const char * class_name = get_active_class_name ( & space ) ;
2015-04-03 00:52:32 +08:00
zend_bool throw_exception =
ZEND_ARG_USES_STRICT_TYPES ( ) | | ( flags & ZEND_PARSE_PARAMS_THROW ) ;
2005-06-17 19:25:31 +08:00
2008-02-02 05:27:55 +08:00
if ( error ) {
2015-04-03 00:52:32 +08:00
zend_internal_type_error ( throw_exception , " %s%s%s() expects parameter %d %s " ,
class_name , space , get_active_function_name ( ) , arg_num , error ) ;
2008-02-02 05:27:55 +08:00
efree ( error ) ;
} else {
2015-04-03 00:52:32 +08:00
zend_internal_type_error ( throw_exception ,
" %s%s%s() expects parameter %d to be %s, %s given " ,
2014-12-14 06:06:14 +08:00
class_name , space , get_active_function_name ( ) , arg_num , expected_type ,
2014-02-10 14:04:30 +08:00
zend_zval_type_name ( arg ) ) ;
2008-02-02 05:27:55 +08:00
}
}
2015-03-15 16:47:25 +08:00
if ( severity ! = E_DEPRECATED ) {
2008-02-02 05:27:55 +08:00
return FAILURE ;
2001-07-10 02:51:29 +08:00
}
}
2006-05-10 07:53:23 +08:00
2001-07-10 02:51:29 +08:00
return SUCCESS ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2001-07-10 02:51:29 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_parse_parameter ( int flags , int arg_num , zval * arg , const char * spec , . . . )
Expose zend_parse_arg() as zend_parse_parameter()
Sometimes, one wants to accept several types for a given parameter. zpp
has special functionality for detecting the NULL type, since the NULL
type is frequently used to skip parameters.
However, supporting several types is otherwise very tedious. There are
many cases where this situation arises -- for instance one may want
to accept an arbitrary number of integer and expect them in an array,
but allow a bare integer too; one may want to accept something that
will be used as an array key (which can be either and int or a string);
one may want to accept integer and double numbers. A search for IS_LONG
reveals many situations where this need arises.
The usual solution is to fetch the argument with 'z'/'Z', check its
type, and then convert the argument, e.g. with convert_to_long_ex().
As explain in the last commit, this has different behavior and
generates inconsistency.
Another -- even more flawed strategy --, is to try zpp with a specific
format, forcing it quiet, and if it fails retrying with another form.
But because zpp changes the arguments directly in the stack (for
instance, using "l" converts the zval in the stack to IS_LONG), the
arguments may look different after the first zpp, leaving subtle bugs.
This commit also allows more complex scenarios, for instance where the
expected type of one parameter depends on other parameters.
2012-07-19 04:05:42 +08:00
{
va_list va ;
int ret ;
va_start ( va , spec ) ;
2015-03-21 04:18:52 +08:00
ret = zend_parse_arg ( arg_num , arg , & va , & spec , flags ) ;
Expose zend_parse_arg() as zend_parse_parameter()
Sometimes, one wants to accept several types for a given parameter. zpp
has special functionality for detecting the NULL type, since the NULL
type is frequently used to skip parameters.
However, supporting several types is otherwise very tedious. There are
many cases where this situation arises -- for instance one may want
to accept an arbitrary number of integer and expect them in an array,
but allow a bare integer too; one may want to accept something that
will be used as an array key (which can be either and int or a string);
one may want to accept integer and double numbers. A search for IS_LONG
reveals many situations where this need arises.
The usual solution is to fetch the argument with 'z'/'Z', check its
type, and then convert the argument, e.g. with convert_to_long_ex().
As explain in the last commit, this has different behavior and
generates inconsistency.
Another -- even more flawed strategy --, is to try zpp with a specific
format, forcing it quiet, and if it fails retrying with another form.
But because zpp changes the arguments directly in the stack (for
instance, using "l" converts the zval in the stack to IS_LONG), the
arguments may look different after the first zpp, leaving subtle bugs.
This commit also allows more complex scenarios, for instance where the
expected type of one parameter depends on other parameters.
2012-07-19 04:05:42 +08:00
va_end ( va ) ;
return ret ;
}
2015-08-19 19:40:56 +08:00
static ZEND_COLD void zend_parse_parameters_debug_error ( const char * msg ) {
2015-04-04 16:24:00 +08:00
zend_function * active_function = EG ( current_execute_data ) - > func ;
const char * class_name = active_function - > common . scope
2015-06-30 18:59:27 +08:00
? ZSTR_VAL ( active_function - > common . scope - > name ) : " " ;
2015-04-04 16:24:00 +08:00
zend_error_noreturn ( E_CORE_ERROR , " %s%s%s(): %s " ,
class_name , class_name [ 0 ] ? " :: " : " " ,
2015-06-30 18:59:27 +08:00
ZSTR_VAL ( active_function - > common . function_name ) , msg ) ;
2015-04-04 16:24:00 +08:00
}
2014-12-14 06:06:14 +08:00
static int zend_parse_va_args ( int num_args , const char * type_spec , va_list * va , int flags ) /* { { { */
2001-07-10 02:51:29 +08:00
{
2010-10-15 05:33:10 +08:00
const char * spec_walk ;
2001-07-10 02:51:29 +08:00
int c , i ;
int min_num_args = - 1 ;
int max_num_args = 0 ;
2007-10-30 01:09:57 +08:00
int post_varargs = 0 ;
2014-02-10 14:04:30 +08:00
zval * arg ;
2001-07-10 02:51:29 +08:00
int arg_count ;
2007-10-30 01:09:57 +08:00
zend_bool have_varargs = 0 ;
2014-02-18 05:41:23 +08:00
zval * * varargs = NULL ;
2007-11-03 03:40:39 +08:00
int * n_varargs = NULL ;
2001-07-10 02:51:29 +08:00
for ( spec_walk = type_spec ; * spec_walk ; spec_walk + + ) {
c = * spec_walk ;
switch ( c ) {
case ' l ' : case ' d ' :
case ' s ' : case ' b ' :
case ' r ' : case ' a ' :
case ' o ' : case ' O ' :
2003-07-12 22:54:53 +08:00
case ' z ' : case ' Z ' :
2006-02-28 06:23:21 +08:00
case ' C ' : case ' h ' :
2008-11-25 02:10:36 +08:00
case ' f ' : case ' A ' :
2011-06-07 05:28:16 +08:00
case ' H ' : case ' p ' :
2014-05-05 10:49:27 +08:00
case ' S ' : case ' P ' :
2014-08-26 01:24:55 +08:00
case ' L ' :
2001-07-10 02:51:29 +08:00
max_num_args + + ;
break ;
case ' | ' :
min_num_args = max_num_args ;
break ;
case ' / ' :
case ' ! ' :
/* Pass */
break ;
2007-10-30 01:09:57 +08:00
case ' * ' :
case ' + ' :
if ( have_varargs ) {
2015-04-04 16:24:00 +08:00
zend_parse_parameters_debug_error (
" only one varargs specifier (* or +) is permitted " ) ;
2007-10-30 01:09:57 +08:00
return FAILURE ;
}
have_varargs = 1 ;
/* we expect at least one parameter in varargs */
if ( c = = ' + ' ) {
max_num_args + + ;
}
/* mark the beginning of varargs */
post_varargs = max_num_args ;
break ;
2001-07-10 02:51:29 +08:00
default :
2015-04-04 16:24:00 +08:00
zend_parse_parameters_debug_error ( " bad type specifier while parsing parameters " ) ;
2001-07-10 02:51:29 +08:00
return FAILURE ;
}
}
if ( min_num_args < 0 ) {
min_num_args = max_num_args ;
}
2007-10-30 01:09:57 +08:00
if ( have_varargs ) {
/* calculate how many required args are at the end of the specifier list */
post_varargs = max_num_args - post_varargs ;
max_num_args = - 1 ;
}
2015-09-20 08:43:22 +08:00
if ( num_args < min_num_args | | ( num_args > max_num_args & & max_num_args > = 0 ) ) {
2015-03-21 04:18:52 +08:00
if ( ! ( flags & ZEND_PARSE_PARAMS_QUIET ) ) {
2014-07-03 02:01:25 +08:00
zend_function * active_function = EG ( current_execute_data ) - > func ;
2015-06-30 18:59:27 +08:00
const char * class_name = active_function - > common . scope ? ZSTR_VAL ( active_function - > common . scope - > name ) : " " ;
2015-09-20 08:43:22 +08:00
zend_bool throw_exception = ZEND_ARG_USES_STRICT_TYPES ( ) | | ( flags & ZEND_PARSE_PARAMS_THROW ) ;
2016-08-31 03:09:26 +08:00
zend_internal_argument_count_error ( throw_exception , " %s%s%s() expects %s %d parameter%s, %d given " ,
2003-08-13 15:02:44 +08:00
class_name ,
class_name [ 0 ] ? " :: " : " " ,
2015-06-30 18:59:27 +08:00
ZSTR_VAL ( active_function - > common . function_name ) ,
2001-07-10 02:51:29 +08:00
min_num_args = = max_num_args ? " exactly " : num_args < min_num_args ? " at least " : " at most " ,
num_args < min_num_args ? min_num_args : max_num_args ,
( num_args < min_num_args ? min_num_args : max_num_args ) = = 1 ? " " : " s " ,
num_args ) ;
}
return FAILURE ;
}
2014-11-28 15:28:49 +08:00
arg_count = ZEND_CALL_NUM_ARGS ( EG ( current_execute_data ) ) ;
2001-07-10 02:51:29 +08:00
if ( num_args > arg_count ) {
2015-04-04 16:24:00 +08:00
zend_parse_parameters_debug_error ( " could not obtain parameters for parsing " ) ;
2001-07-10 02:51:29 +08:00
return FAILURE ;
}
i = 0 ;
while ( num_args - - > 0 ) {
if ( * type_spec = = ' | ' ) {
type_spec + + ;
}
2007-10-30 01:09:57 +08:00
if ( * type_spec = = ' * ' | | * type_spec = = ' + ' ) {
int num_varargs = num_args + 1 - post_varargs ;
/* eat up the passed in storage even if it won't be filled in with varargs */
2014-02-18 05:41:23 +08:00
varargs = va_arg ( * va , zval * * ) ;
2007-11-03 03:40:39 +08:00
n_varargs = va_arg ( * va , int * ) ;
2007-10-30 01:09:57 +08:00
type_spec + + ;
if ( num_varargs > 0 ) {
* n_varargs = num_varargs ;
2014-07-03 02:01:25 +08:00
* varargs = ZEND_CALL_ARG ( EG ( current_execute_data ) , i + 1 ) ;
2007-10-30 01:09:57 +08:00
/* adjust how many args we have left and restart loop */
2014-03-05 15:10:52 +08:00
num_args + = 1 - num_varargs ;
i + = num_varargs ;
2007-10-30 01:09:57 +08:00
continue ;
} else {
* varargs = NULL ;
* n_varargs = 0 ;
}
}
2014-07-03 02:01:25 +08:00
arg = ZEND_CALL_ARG ( EG ( current_execute_data ) , i + 1 ) ;
2007-10-30 01:09:57 +08:00
2015-03-21 04:18:52 +08:00
if ( zend_parse_arg ( i + 1 , arg , va , & type_spec , flags ) = = FAILURE ) {
2007-11-03 03:40:39 +08:00
/* clean up varargs array if it was used */
if ( varargs & & * varargs ) {
* varargs = NULL ;
}
2001-07-10 02:51:29 +08:00
return FAILURE ;
}
i + + ;
}
return SUCCESS ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2001-07-10 02:51:29 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_parse_parameters_ex ( int flags , int num_args , const char * type_spec , . . . ) /* { { { */
2001-07-10 02:51:29 +08:00
{
va_list va ;
int retval ;
2006-05-10 07:53:23 +08:00
2001-07-10 02:51:29 +08:00
va_start ( va , type_spec ) ;
2014-12-14 06:06:14 +08:00
retval = zend_parse_va_args ( num_args , type_spec , & va , flags ) ;
2001-07-10 02:51:29 +08:00
va_end ( va ) ;
return retval ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2001-07-10 02:51:29 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_parse_parameters ( int num_args , const char * type_spec , . . . ) /* { { { */
2001-07-10 02:51:29 +08:00
{
va_list va ;
int retval ;
2015-01-13 08:57:56 +08:00
int flags = 0 ;
2001-07-10 02:51:29 +08:00
va_start ( va , type_spec ) ;
2015-01-13 08:57:56 +08:00
retval = zend_parse_va_args ( num_args , type_spec , & va , flags ) ;
2001-07-10 02:51:29 +08:00
va_end ( va ) ;
return retval ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2015-04-03 00:52:32 +08:00
ZEND_API int zend_parse_parameters_throw ( int num_args , const char * type_spec , . . . ) /* { { { */
{
va_list va ;
int retval ;
int flags = ZEND_PARSE_PARAMS_THROW ;
va_start ( va , type_spec ) ;
retval = zend_parse_va_args ( num_args , type_spec , & va , flags ) ;
va_end ( va ) ;
return retval ;
}
/* }}} */
2001-07-10 02:51:29 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_parse_method_parameters ( int num_args , zval * this_ptr , const char * type_spec , . . . ) /* { { { */
2003-02-03 07:30:14 +08:00
{
va_list va ;
int retval ;
2015-01-13 08:57:56 +08:00
int flags = 0 ;
2010-10-15 05:33:10 +08:00
const char * p = type_spec ;
2003-02-09 04:54:02 +08:00
zval * * object ;
zend_class_entry * ce ;
2003-02-03 07:30:14 +08:00
2014-05-07 03:56:01 +08:00
/* Just checking this_ptr is not enough, because fcall_common_helper does not set
* Z_OBJ ( EG ( This ) ) to NULL when calling an internal function with common . scope = = NULL .
* In that case EG ( This ) would still be the $ this from the calling code and we ' d take the
* wrong branch here . */
2014-07-03 02:01:25 +08:00
zend_bool is_method = EG ( current_execute_data ) - > func - > common . scope ! = NULL ;
2015-03-19 06:38:16 +08:00
2014-05-07 03:56:01 +08:00
if ( ! is_method | | ! this_ptr | | Z_TYPE_P ( this_ptr ) ! = IS_OBJECT ) {
2003-02-09 04:54:02 +08:00
va_start ( va , type_spec ) ;
2015-01-13 08:57:56 +08:00
retval = zend_parse_va_args ( num_args , type_spec , & va , flags ) ;
2003-02-09 04:54:02 +08:00
va_end ( va ) ;
2003-08-01 00:30:15 +08:00
} else {
2003-02-09 04:54:02 +08:00
p + + ;
2007-10-30 18:17:41 +08:00
2003-02-09 04:54:02 +08:00
va_start ( va , type_spec ) ;
2003-02-03 07:30:14 +08:00
2003-02-09 04:54:02 +08:00
object = va_arg ( va , zval * * ) ;
ce = va_arg ( va , zend_class_entry * ) ;
* object = this_ptr ;
2008-08-13 01:20:25 +08:00
2014-12-14 06:06:14 +08:00
if ( ce & & ! instanceof_function ( Z_OBJCE_P ( this_ptr ) , ce ) ) {
2015-04-01 18:32:23 +08:00
zend_error_noreturn ( E_CORE_ERROR , " %s::%s() must be derived from %s::%s " ,
2015-06-30 18:59:27 +08:00
ZSTR_VAL ( Z_OBJCE_P ( this_ptr ) - > name ) , get_active_function_name ( ) , ZSTR_VAL ( ce - > name ) , get_active_function_name ( ) ) ;
2003-08-21 22:39:17 +08:00
}
2003-02-03 07:30:14 +08:00
2015-01-13 08:57:56 +08:00
retval = zend_parse_va_args ( num_args , p , & va , flags ) ;
2003-02-09 04:54:02 +08:00
va_end ( va ) ;
}
2003-02-03 07:30:14 +08:00
return retval ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-02-03 07:30:14 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_parse_method_parameters_ex ( int flags , int num_args , zval * this_ptr , const char * type_spec , . . . ) /* { { { */
2003-02-03 07:30:14 +08:00
{
va_list va ;
int retval ;
2010-10-15 05:33:10 +08:00
const char * p = type_spec ;
2004-03-03 00:17:58 +08:00
zval * * object ;
zend_class_entry * ce ;
2015-01-13 08:57:56 +08:00
2004-03-03 00:17:58 +08:00
if ( ! this_ptr ) {
va_start ( va , type_spec ) ;
2014-12-14 06:06:14 +08:00
retval = zend_parse_va_args ( num_args , type_spec , & va , flags ) ;
2004-03-03 00:17:58 +08:00
va_end ( va ) ;
} else {
p + + ;
va_start ( va , type_spec ) ;
2003-02-03 07:30:14 +08:00
2004-03-03 00:17:58 +08:00
object = va_arg ( va , zval * * ) ;
ce = va_arg ( va , zend_class_entry * ) ;
* object = this_ptr ;
2008-08-13 01:20:25 +08:00
2014-12-14 06:06:14 +08:00
if ( ce & & ! instanceof_function ( Z_OBJCE_P ( this_ptr ) , ce ) ) {
2015-01-13 08:57:56 +08:00
if ( ! ( flags & ZEND_PARSE_PARAMS_QUIET ) ) {
2015-04-01 18:32:23 +08:00
zend_error_noreturn ( E_CORE_ERROR , " %s::%s() must be derived from %s::%s " ,
2015-06-30 18:59:27 +08:00
ZSTR_VAL ( ce - > name ) , get_active_function_name ( ) , ZSTR_VAL ( Z_OBJCE_P ( this_ptr ) - > name ) , get_active_function_name ( ) ) ;
2003-02-03 07:30:14 +08:00
}
2011-08-06 06:26:16 +08:00
va_end ( va ) ;
2003-02-03 07:30:14 +08:00
return FAILURE ;
}
2014-12-14 06:06:14 +08:00
retval = zend_parse_va_args ( num_args , p , & va , flags ) ;
2004-03-03 00:17:58 +08:00
va_end ( va ) ;
}
2003-02-03 07:30:14 +08:00
return retval ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2004-03-03 00:17:58 +08:00
2006-05-10 07:53:23 +08:00
/* This function should be called after the constructor has been called
2003-08-30 07:27:22 +08:00
* because it may call __set from the uninitialized object otherwise . */
2014-12-14 06:06:14 +08:00
ZEND_API void zend_merge_properties ( zval * obj , HashTable * properties ) /* { { { */
2003-08-30 07:27:22 +08:00
{
2011-09-13 21:29:35 +08:00
const zend_object_handlers * obj_ht = Z_OBJ_HT_P ( obj ) ;
2016-04-28 09:13:34 +08:00
zend_class_entry * old_scope = EG ( fake_scope ) ;
2014-05-27 04:38:58 +08:00
zend_string * key ;
zval * value ;
2003-08-30 07:27:22 +08:00
2016-04-28 09:13:34 +08:00
EG ( fake_scope ) = Z_OBJCE_P ( obj ) ;
2014-05-27 04:38:58 +08:00
ZEND_HASH_FOREACH_STR_KEY_VAL ( properties , key , value ) {
if ( key ) {
zval member ;
2014-09-19 19:41:01 +08:00
ZVAL_STR ( & member , key ) ;
2014-12-14 06:06:14 +08:00
obj_ht - > write_property ( obj , & member , value , NULL ) ;
2014-05-27 04:38:58 +08:00
}
} ZEND_HASH_FOREACH_END ( ) ;
2016-04-28 09:13:34 +08:00
EG ( fake_scope ) = old_scope ;
2003-08-30 07:27:22 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-08-30 07:27:22 +08:00
2015-04-02 07:05:25 +08:00
ZEND_API int zend_update_class_constants ( zend_class_entry * class_type ) /* { { { */
2005-01-22 20:23:01 +08:00
{
2015-05-21 09:13:10 +08:00
if ( ! ( class_type - > ce_flags & ZEND_ACC_CONSTANTS_UPDATED ) ) {
2014-06-17 03:32:58 +08:00
if ( class_type - > parent ) {
2015-04-02 07:05:25 +08:00
if ( UNEXPECTED ( zend_update_class_constants ( class_type - > parent ) ! = SUCCESS ) ) {
return FAILURE ;
}
2014-06-17 03:32:58 +08:00
}
2015-05-21 09:13:10 +08:00
if ( ! CE_STATIC_MEMBERS ( class_type ) & & class_type - > default_static_members_count ) {
/* initialize static members of internal class */
int i ;
zval * p ;
2014-06-17 03:32:58 +08:00
# if ZTS
2015-05-21 09:13:10 +08:00
CG ( static_members_table ) [ ( zend_intptr_t ) ( class_type - > static_members_table ) ] = emalloc ( sizeof ( zval ) * class_type - > default_static_members_count ) ;
2014-06-17 03:32:58 +08:00
# else
2015-05-21 09:13:10 +08:00
class_type - > static_members_table = emalloc ( sizeof ( zval ) * class_type - > default_static_members_count ) ;
2014-06-17 03:32:58 +08:00
# endif
2015-05-21 09:13:10 +08:00
for ( i = 0 ; i < class_type - > default_static_members_count ; i + + ) {
p = & class_type - > default_static_members_table [ i ] ;
2017-10-31 04:13:10 +08:00
if ( Z_ISREF_P ( p ) ) {
if ( class_type - > parent & &
i < class_type - > parent - > default_static_members_count & &
p = = & class_type - > parent - > default_static_members_table [ i ] & &
Z_TYPE ( CE_STATIC_MEMBERS ( class_type - > parent ) [ i ] ) ! = IS_UNDEF
) {
zval * q = & CE_STATIC_MEMBERS ( class_type - > parent ) [ i ] ;
ZVAL_NEW_REF ( q , q ) ;
ZVAL_COPY_VALUE ( & CE_STATIC_MEMBERS ( class_type ) [ i ] , q ) ;
Z_ADDREF_P ( q ) ;
} else {
ZVAL_COPY_OR_DUP ( & CE_STATIC_MEMBERS ( class_type ) [ i ] , Z_REFVAL_P ( p ) ) ;
}
2015-05-21 09:13:10 +08:00
} else {
2017-10-31 04:13:10 +08:00
ZVAL_COPY_OR_DUP ( & CE_STATIC_MEMBERS ( class_type ) [ i ] , p ) ;
2015-05-21 09:13:10 +08:00
}
2015-04-02 07:05:25 +08:00
}
2015-05-21 09:13:10 +08:00
} else {
zend_class_entry * ce ;
2015-12-08 17:40:42 +08:00
zend_class_constant * c ;
2015-05-21 09:13:10 +08:00
zval * val ;
zend_property_info * prop_info ;
2005-09-01 18:05:32 +08:00
2015-12-08 17:40:42 +08:00
ZEND_HASH_FOREACH_PTR ( & class_type - > constants_table , c ) {
val = & c - > value ;
2017-10-10 15:11:05 +08:00
if ( Z_TYPE_P ( val ) = = IS_CONSTANT_AST ) {
2017-03-16 02:06:34 +08:00
if ( UNEXPECTED ( zval_update_constant_ex ( val , c - > ce ) ! = SUCCESS ) ) {
2015-05-21 09:13:10 +08:00
return FAILURE ;
}
2015-04-02 07:05:25 +08:00
}
2015-05-21 09:13:10 +08:00
} ZEND_HASH_FOREACH_END ( ) ;
2010-05-24 22:11:39 +08:00
2015-05-21 09:13:10 +08:00
ce = class_type ;
while ( ce ) {
ZEND_HASH_FOREACH_PTR ( & ce - > properties_info , prop_info ) {
if ( prop_info - > ce = = ce ) {
if ( prop_info - > flags & ZEND_ACC_STATIC ) {
val = CE_STATIC_MEMBERS ( class_type ) + prop_info - > offset ;
} else {
val = ( zval * ) ( ( char * ) class_type - > default_properties_table + prop_info - > offset - OBJ_PROP_TO_OFFSET ( 0 ) ) ;
}
ZVAL_DEREF ( val ) ;
2017-10-10 15:11:05 +08:00
if ( Z_TYPE_P ( val ) = = IS_CONSTANT_AST ) {
2016-04-28 09:13:34 +08:00
if ( UNEXPECTED ( zval_update_constant_ex ( val , ce ) ! = SUCCESS ) ) {
2015-05-21 09:13:10 +08:00
return FAILURE ;
}
}
}
} ZEND_HASH_FOREACH_END ( ) ;
ce = ce - > parent ;
2015-04-02 07:05:25 +08:00
}
2015-05-21 09:13:10 +08:00
}
2017-05-27 12:11:53 +08:00
class_type - > ce_flags | = ZEND_ACC_CONSTANTS_UPDATED ;
2005-01-22 20:23:01 +08:00
}
2017-05-27 12:06:43 +08:00
2015-04-02 07:05:25 +08:00
return SUCCESS ;
2005-01-22 20:23:01 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-01-22 20:23:01 +08:00
2010-05-24 22:11:39 +08:00
ZEND_API void object_properties_init ( zend_object * object , zend_class_entry * class_type ) /* { { { */
{
if ( class_type - > default_properties_count ) {
2015-04-29 00:11:45 +08:00
zval * src = class_type - > default_properties_table ;
zval * dst = object - > properties_table ;
zval * end = src + class_type - > default_properties_count ;
2017-10-31 04:13:10 +08:00
if ( UNEXPECTED ( class_type - > type = = ZEND_INTERNAL_CLASS ) ) {
do {
ZVAL_COPY_OR_DUP ( dst , src ) ;
src + + ;
dst + + ;
} while ( src ! = end ) ;
} else {
do {
ZVAL_COPY ( dst , src ) ;
src + + ;
dst + + ;
} while ( src ! = end ) ;
}
2010-05-24 22:11:39 +08:00
object - > properties = NULL ;
}
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API void object_properties_init_ex ( zend_object * object , HashTable * properties ) /* { { { */
2014-03-26 22:07:31 +08:00
{
object - > properties = properties ;
if ( object - > ce - > default_properties_count ) {
2016-05-24 17:37:20 +08:00
zval * prop ;
zend_string * key ;
zend_property_info * property_info ;
2014-03-26 22:07:31 +08:00
2016-05-24 17:37:20 +08:00
ZEND_HASH_FOREACH_STR_KEY_VAL ( properties , key , prop ) {
2014-12-14 06:06:14 +08:00
property_info = zend_get_property_info ( object - > ce , key , 1 ) ;
2014-10-17 23:10:05 +08:00
if ( property_info ! = ZEND_WRONG_PROPERTY_INFO & &
property_info & &
( property_info - > flags & ZEND_ACC_STATIC ) = = 0 ) {
2014-11-06 19:50:03 +08:00
zval * slot = OBJ_PROP ( object , property_info - > offset ) ;
ZVAL_COPY_VALUE ( slot , prop ) ;
ZVAL_INDIRECT ( prop , slot ) ;
2014-03-26 22:07:31 +08:00
}
2014-04-18 23:18:11 +08:00
} ZEND_HASH_FOREACH_END ( ) ;
2014-03-26 22:07:31 +08:00
}
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API void object_properties_load ( zend_object * object , HashTable * properties ) /* { { { */
2014-03-26 22:07:31 +08:00
{
zval * prop , tmp ;
zend_string * key ;
2015-09-02 03:40:10 +08:00
zend_long h ;
2014-03-26 22:07:31 +08:00
zend_property_info * property_info ;
2015-09-02 03:40:10 +08:00
ZEND_HASH_FOREACH_KEY_VAL ( properties , h , key , prop ) {
2015-11-23 23:15:33 +08:00
if ( key ) {
if ( ZSTR_VAL ( key ) [ 0 ] = = ' \0 ' ) {
const char * class_name , * prop_name ;
size_t prop_name_len ;
if ( zend_unmangle_property_name_ex ( key , & class_name , & prop_name , & prop_name_len ) = = SUCCESS ) {
zend_string * pname = zend_string_init ( prop_name , prop_name_len , 0 ) ;
2016-04-28 09:13:34 +08:00
zend_class_entry * prev_scope = EG ( fake_scope ) ;
2016-02-21 19:59:57 +08:00
if ( class_name & & class_name [ 0 ] ! = ' * ' ) {
zend_string * cname = zend_string_init ( class_name , strlen ( class_name ) , 0 ) ;
2016-04-28 09:13:34 +08:00
EG ( fake_scope ) = zend_lookup_class ( cname ) ;
2016-02-21 19:59:57 +08:00
zend_string_release ( cname ) ;
}
2015-11-23 23:15:33 +08:00
property_info = zend_get_property_info ( object - > ce , pname , 1 ) ;
zend_string_release ( pname ) ;
2016-04-28 09:13:34 +08:00
EG ( fake_scope ) = prev_scope ;
2015-11-23 23:15:33 +08:00
} else {
property_info = ZEND_WRONG_PROPERTY_INFO ;
}
} else {
property_info = zend_get_property_info ( object - > ce , key , 1 ) ;
}
2015-09-02 03:40:10 +08:00
if ( property_info ! = ZEND_WRONG_PROPERTY_INFO & &
property_info & &
( property_info - > flags & ZEND_ACC_STATIC ) = = 0 ) {
zval * slot = OBJ_PROP ( object , property_info - > offset ) ;
zval_ptr_dtor ( slot ) ;
ZVAL_COPY_VALUE ( slot , prop ) ;
zval_add_ref ( slot ) ;
if ( object - > properties ) {
ZVAL_INDIRECT ( & tmp , slot ) ;
zend_hash_update ( object - > properties , key , & tmp ) ;
}
} else {
if ( ! object - > properties ) {
rebuild_object_properties ( object ) ;
}
prop = zend_hash_update ( object - > properties , key , prop ) ;
zval_add_ref ( prop ) ;
2014-03-26 22:07:31 +08:00
}
} else {
if ( ! object - > properties ) {
rebuild_object_properties ( object ) ;
}
2015-09-02 03:40:10 +08:00
prop = zend_hash_index_update ( object - > properties , h , prop ) ;
2014-03-26 22:07:31 +08:00
zval_add_ref ( prop ) ;
}
2015-01-03 17:22:58 +08:00
} ZEND_HASH_FOREACH_END ( ) ;
2014-03-26 22:07:31 +08:00
}
/* }}} */
2003-08-30 07:27:22 +08:00
/* This function requires 'properties' to contain all props declared in the
2006-05-10 07:53:23 +08:00
* class and all props being public . If only a subset is given or the class
2013-06-11 05:20:18 +08:00
* has protected members then you need to merge the properties separately by
2003-08-30 07:27:22 +08:00
* calling zend_merge_properties ( ) . */
2014-12-14 06:06:14 +08:00
ZEND_API int _object_and_properties_init ( zval * arg , zend_class_entry * class_type , HashTable * properties ZEND_FILE_LINE_DC ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2015-04-02 08:56:42 +08:00
if ( UNEXPECTED ( class_type - > ce_flags & ( ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS ) ) ) {
2015-02-13 06:19:14 +08:00
if ( class_type - > ce_flags & ZEND_ACC_INTERFACE ) {
2015-07-08 01:10:22 +08:00
zend_throw_error ( NULL , " Cannot instantiate interface %s " , ZSTR_VAL ( class_type - > name ) ) ;
2015-02-13 06:19:14 +08:00
} else if ( class_type - > ce_flags & ZEND_ACC_TRAIT ) {
2015-07-08 01:10:22 +08:00
zend_throw_error ( NULL , " Cannot instantiate trait %s " , ZSTR_VAL ( class_type - > name ) ) ;
2015-02-13 06:19:14 +08:00
} else {
2015-07-08 01:10:22 +08:00
zend_throw_error ( NULL , " Cannot instantiate abstract class %s " , ZSTR_VAL ( class_type - > name ) ) ;
2015-02-13 06:19:14 +08:00
}
2015-04-02 07:05:25 +08:00
ZVAL_NULL ( arg ) ;
Z_OBJ_P ( arg ) = NULL ;
return FAILURE ;
2004-06-05 22:59:21 +08:00
}
2015-05-21 09:13:10 +08:00
if ( UNEXPECTED ( ! ( class_type - > ce_flags & ZEND_ACC_CONSTANTS_UPDATED ) ) ) {
if ( UNEXPECTED ( zend_update_class_constants ( class_type ) ! = SUCCESS ) ) {
ZVAL_NULL ( arg ) ;
Z_OBJ_P ( arg ) = NULL ;
return FAILURE ;
}
2015-04-02 07:05:25 +08:00
}
2006-05-10 07:53:23 +08:00
2002-09-15 15:45:26 +08:00
if ( class_type - > create_object = = NULL ) {
2014-12-14 06:06:14 +08:00
ZVAL_OBJ ( arg , zend_objects_new ( class_type ) ) ;
2002-02-07 22:08:43 +08:00
if ( properties ) {
2014-12-14 06:06:14 +08:00
object_properties_init_ex ( Z_OBJ_P ( arg ) , properties ) ;
2002-02-07 22:08:43 +08:00
} else {
2014-02-10 14:04:30 +08:00
object_properties_init ( Z_OBJ_P ( arg ) , class_type ) ;
2002-02-07 22:08:43 +08:00
}
2001-08-12 02:26:47 +08:00
} else {
2014-12-14 06:06:14 +08:00
ZVAL_OBJ ( arg , class_type - > create_object ( class_type ) ) ;
2002-02-07 22:08:43 +08:00
}
1999-04-08 02:10:10 +08:00
return SUCCESS ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int _object_init_ex ( zval * arg , zend_class_entry * class_type ZEND_FILE_LINE_DC ) /* { { { */
2001-08-12 02:26:47 +08:00
{
2014-12-14 06:06:14 +08:00
return _object_and_properties_init ( arg , class_type , 0 ZEND_FILE_LINE_RELAY_CC ) ;
2001-08-12 02:26:47 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int _object_init ( zval * arg ZEND_FILE_LINE_DC ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-12-14 06:06:14 +08:00
return _object_init_ex ( arg , zend_standard_class_def ZEND_FILE_LINE_RELAY_CC ) ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-10-23 14:52:59 +08:00
ZEND_API int add_assoc_long_ex ( zval * arg , const char * key , size_t key_len , zend_long n ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval * ret , tmp ;
2015-01-03 17:22:58 +08:00
2014-08-26 01:24:55 +08:00
ZVAL_LONG ( & tmp , n ) ;
2014-02-10 14:04:30 +08:00
ret = zend_symtable_str_update ( Z_ARRVAL_P ( arg ) , key , key_len , & tmp ) ;
return ret ? SUCCESS : FAILURE ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-10-23 14:52:59 +08:00
ZEND_API int add_assoc_null_ex ( zval * arg , const char * key , size_t key_len ) /* { { { */
1999-12-31 21:56:59 +08:00
{
2014-02-10 14:04:30 +08:00
zval * ret , tmp ;
2015-01-03 17:22:58 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_NULL ( & tmp ) ;
ret = zend_symtable_str_update ( Z_ARRVAL_P ( arg ) , key , key_len , & tmp ) ;
return ret ? SUCCESS : FAILURE ;
1999-12-31 21:56:59 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-12-31 21:56:59 +08:00
2014-10-23 14:52:59 +08:00
ZEND_API int add_assoc_bool_ex ( zval * arg , const char * key , size_t key_len , int b ) /* { { { */
1999-10-04 19:42:46 +08:00
{
2014-02-10 14:04:30 +08:00
zval * ret , tmp ;
2015-01-03 17:22:58 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_BOOL ( & tmp , b ) ;
ret = zend_symtable_str_update ( Z_ARRVAL_P ( arg ) , key , key_len , & tmp ) ;
return ret ? SUCCESS : FAILURE ;
1999-10-04 19:42:46 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-10-04 19:42:46 +08:00
2014-10-23 14:52:59 +08:00
ZEND_API int add_assoc_resource_ex ( zval * arg , const char * key , size_t key_len , zend_resource * r ) /* { { { */
1999-10-04 19:42:46 +08:00
{
2014-02-10 14:04:30 +08:00
zval * ret , tmp ;
2015-01-03 17:22:58 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_RES ( & tmp , r ) ;
ret = zend_symtable_str_update ( Z_ARRVAL_P ( arg ) , key , key_len , & tmp ) ;
return ret ? SUCCESS : FAILURE ;
1999-10-04 19:42:46 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-10-04 19:42:46 +08:00
2014-10-23 14:52:59 +08:00
ZEND_API int add_assoc_double_ex ( zval * arg , const char * key , size_t key_len , double d ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval * ret , tmp ;
2015-01-03 17:22:58 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_DOUBLE ( & tmp , d ) ;
ret = zend_symtable_str_update ( Z_ARRVAL_P ( arg ) , key , key_len , & tmp ) ;
return ret ? SUCCESS : FAILURE ;
}
/* }}} */
2006-05-10 07:53:23 +08:00
2014-10-23 14:52:59 +08:00
ZEND_API int add_assoc_str_ex ( zval * arg , const char * key , size_t key_len , zend_string * str ) /* { { { */
2014-02-10 14:04:30 +08:00
{
zval * ret , tmp ;
1999-04-08 02:10:10 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_STR ( & tmp , str ) ;
ret = zend_symtable_str_update ( Z_ARRVAL_P ( arg ) , key , key_len , & tmp ) ;
return ret ? SUCCESS : FAILURE ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2017-06-05 02:29:19 +08:00
ZEND_API int add_assoc_string_ex ( zval * arg , const char * key , size_t key_len , const char * str ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval * ret , tmp ;
2015-01-03 17:22:58 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_STRING ( & tmp , str ) ;
ret = zend_symtable_str_update ( Z_ARRVAL_P ( arg ) , key , key_len , & tmp ) ;
return ret ? SUCCESS : FAILURE ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2017-06-05 02:29:19 +08:00
ZEND_API int add_assoc_stringl_ex ( zval * arg , const char * key , size_t key_len , const char * str , size_t length ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval * ret , tmp ;
2015-01-03 17:22:58 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_STRINGL ( & tmp , str , length ) ;
ret = zend_symtable_str_update ( Z_ARRVAL_P ( arg ) , key , key_len , & tmp ) ;
return ret ? SUCCESS : FAILURE ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-10-23 14:52:59 +08:00
ZEND_API int add_assoc_zval_ex ( zval * arg , const char * key , size_t key_len , zval * value ) /* { { { */
2001-01-19 16:40:49 +08:00
{
2014-02-10 14:04:30 +08:00
zval * ret ;
2015-01-03 17:22:58 +08:00
2014-02-10 14:04:30 +08:00
ret = zend_symtable_str_update ( Z_ARRVAL_P ( arg ) , key , key_len , value ) ;
return ret ? SUCCESS : FAILURE ;
2001-01-19 16:40:49 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2001-01-19 16:40:49 +08:00
2014-08-26 01:24:55 +08:00
ZEND_API int add_index_long ( zval * arg , zend_ulong index , zend_long n ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
1999-10-04 19:42:46 +08:00
2014-08-26 01:24:55 +08:00
ZVAL_LONG ( & tmp , n ) ;
2014-02-10 14:04:30 +08:00
return zend_hash_index_update ( Z_ARRVAL_P ( arg ) , index , & tmp ) ? SUCCESS : FAILURE ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-08-26 01:24:55 +08:00
ZEND_API int add_index_null ( zval * arg , zend_ulong index ) /* { { { */
1999-12-31 21:56:59 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
1999-12-31 21:56:59 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_NULL ( & tmp ) ;
return zend_hash_index_update ( Z_ARRVAL_P ( arg ) , index , & tmp ) ? SUCCESS : FAILURE ;
2001-01-21 03:16:38 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-12-31 21:56:59 +08:00
2014-08-26 01:24:55 +08:00
ZEND_API int add_index_bool ( zval * arg , zend_ulong index , int b ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_BOOL ( & tmp , b ) ;
return zend_hash_index_update ( Z_ARRVAL_P ( arg ) , index , & tmp ) ? SUCCESS : FAILURE ;
1999-10-04 19:42:46 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-10-04 19:42:46 +08:00
2014-08-26 01:24:55 +08:00
ZEND_API int add_index_resource ( zval * arg , zend_ulong index , zend_resource * r ) /* { { { */
1999-10-04 19:42:46 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_RES ( & tmp , r ) ;
return zend_hash_index_update ( Z_ARRVAL_P ( arg ) , index , & tmp ) ? SUCCESS : FAILURE ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-08-26 01:24:55 +08:00
ZEND_API int add_index_double ( zval * arg , zend_ulong index , double d ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_DOUBLE ( & tmp , d ) ;
return zend_hash_index_update ( Z_ARRVAL_P ( arg ) , index , & tmp ) ? SUCCESS : FAILURE ;
2014-02-14 18:55:48 +08:00
}
/* }}} */
2014-08-26 01:24:55 +08:00
ZEND_API int add_index_str ( zval * arg , zend_ulong index , zend_string * str ) /* { { { */
2014-02-14 18:55:48 +08:00
{
zval tmp ;
ZVAL_STR ( & tmp , str ) ;
return zend_hash_index_update ( Z_ARRVAL_P ( arg ) , index , & tmp ) ? SUCCESS : FAILURE ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-08-26 01:24:55 +08:00
ZEND_API int add_index_string ( zval * arg , zend_ulong index , const char * str ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_STRING ( & tmp , str ) ;
return zend_hash_index_update ( Z_ARRVAL_P ( arg ) , index , & tmp ) ? SUCCESS : FAILURE ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-08-29 01:17:47 +08:00
ZEND_API int add_index_stringl ( zval * arg , zend_ulong index , const char * str , size_t length ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_STRINGL ( & tmp , str , length ) ;
return zend_hash_index_update ( Z_ARRVAL_P ( arg ) , index , & tmp ) ? SUCCESS : FAILURE ;
2001-01-21 03:16:38 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-08-26 01:24:55 +08:00
ZEND_API int add_index_zval ( zval * arg , zend_ulong index , zval * value ) /* { { { */
2001-01-21 03:16:38 +08:00
{
2014-02-10 14:04:30 +08:00
return zend_hash_index_update ( Z_ARRVAL_P ( arg ) , index , value ) ? SUCCESS : FAILURE ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-08-26 01:24:55 +08:00
ZEND_API int add_next_index_long ( zval * arg , zend_long n ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-08-26 01:24:55 +08:00
ZVAL_LONG ( & tmp , n ) ;
2014-02-10 14:04:30 +08:00
return zend_hash_next_index_insert ( Z_ARRVAL_P ( arg ) , & tmp ) ? SUCCESS : FAILURE ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2007-11-03 03:40:39 +08:00
ZEND_API int add_next_index_null ( zval * arg ) /* { { { */
1999-12-31 21:56:59 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_NULL ( & tmp ) ;
return zend_hash_next_index_insert ( Z_ARRVAL_P ( arg ) , & tmp ) ? SUCCESS : FAILURE ;
1999-12-31 21:56:59 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-12-31 21:56:59 +08:00
2007-11-03 03:40:39 +08:00
ZEND_API int add_next_index_bool ( zval * arg , int b ) /* { { { */
1999-10-04 19:42:46 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_BOOL ( & tmp , b ) ;
return zend_hash_next_index_insert ( Z_ARRVAL_P ( arg ) , & tmp ) ? SUCCESS : FAILURE ;
1999-10-04 19:42:46 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-10-04 19:42:46 +08:00
2014-02-10 14:04:30 +08:00
ZEND_API int add_next_index_resource ( zval * arg , zend_resource * r ) /* { { { */
1999-10-04 19:42:46 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_RES ( & tmp , r ) ;
return zend_hash_next_index_insert ( Z_ARRVAL_P ( arg ) , & tmp ) ? SUCCESS : FAILURE ;
1999-10-04 19:42:46 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-10-04 19:42:46 +08:00
2007-11-03 03:40:39 +08:00
ZEND_API int add_next_index_double ( zval * arg , double d ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_DOUBLE ( & tmp , d ) ;
return zend_hash_next_index_insert ( Z_ARRVAL_P ( arg ) , & tmp ) ? SUCCESS : FAILURE ;
}
/* }}} */
ZEND_API int add_next_index_str ( zval * arg , zend_string * str ) /* { { { */
{
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-25 15:47:24 +08:00
ZVAL_STR ( & tmp , str ) ;
2014-02-10 14:04:30 +08:00
return zend_hash_next_index_insert ( Z_ARRVAL_P ( arg ) , & tmp ) ? SUCCESS : FAILURE ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-04-15 19:40:40 +08:00
ZEND_API int add_next_index_string ( zval * arg , const char * str ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2001-01-21 03:16:38 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_STRING ( & tmp , str ) ;
return zend_hash_next_index_insert ( Z_ARRVAL_P ( arg ) , & tmp ) ? SUCCESS : FAILURE ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-08-29 01:17:47 +08:00
ZEND_API int add_next_index_stringl ( zval * arg , const char * str , size_t length ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2001-01-21 03:16:38 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_STRINGL ( & tmp , str , length ) ;
return zend_hash_next_index_insert ( Z_ARRVAL_P ( arg ) , & tmp ) ? SUCCESS : FAILURE ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2007-11-03 03:40:39 +08:00
ZEND_API int add_next_index_zval ( zval * arg , zval * value ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
return zend_hash_next_index_insert ( Z_ARRVAL_P ( arg ) , value ) ? SUCCESS : FAILURE ;
2001-01-21 03:16:38 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2016-11-26 22:18:42 +08:00
ZEND_API zval * add_get_assoc_string_ex ( zval * arg , const char * key , uint32_t key_len , const char * str ) /* { { { */
2001-01-21 03:16:38 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp , * ret ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_STRING ( & tmp , str ) ;
ret = zend_symtable_str_update ( Z_ARRVAL_P ( arg ) , key , key_len , & tmp ) ;
return ret ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2016-11-26 22:18:42 +08:00
ZEND_API zval * add_get_assoc_stringl_ex ( zval * arg , const char * key , uint32_t key_len , const char * str , size_t length ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp , * ret ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_STRINGL ( & tmp , str , length ) ;
ret = zend_symtable_str_update ( Z_ARRVAL_P ( arg ) , key , key_len , & tmp ) ;
return ret ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-08-26 01:24:55 +08:00
ZEND_API zval * add_get_index_long ( zval * arg , zend_ulong index , zend_long l ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-08-26 01:24:55 +08:00
ZVAL_LONG ( & tmp , l ) ;
2014-02-10 14:04:30 +08:00
return zend_hash_index_update ( Z_ARRVAL_P ( arg ) , index , & tmp ) ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-08-26 01:24:55 +08:00
ZEND_API zval * add_get_index_double ( zval * arg , zend_ulong index , double d ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_DOUBLE ( & tmp , d ) ;
return zend_hash_index_update ( Z_ARRVAL_P ( arg ) , index , & tmp ) ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-08-26 01:24:55 +08:00
ZEND_API zval * add_get_index_str ( zval * arg , zend_ulong index , zend_string * str ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2007-11-03 03:40:39 +08:00
2014-02-25 15:47:24 +08:00
ZVAL_STR ( & tmp , str ) ;
2014-02-10 14:04:30 +08:00
return zend_hash_index_update ( Z_ARRVAL_P ( arg ) , index , & tmp ) ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-08-26 01:24:55 +08:00
ZEND_API zval * add_get_index_string ( zval * arg , zend_ulong index , const char * str ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2007-11-03 03:40:39 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_STRING ( & tmp , str ) ;
return zend_hash_index_update ( Z_ARRVAL_P ( arg ) , index , & tmp ) ;
}
/* }}} */
2014-08-29 01:17:47 +08:00
ZEND_API zval * add_get_index_stringl ( zval * arg , zend_ulong index , const char * str , size_t length ) /* { { { */
2014-02-10 14:04:30 +08:00
{
zval tmp ;
2007-11-03 03:40:39 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_STRINGL ( & tmp , str , length ) ;
return zend_hash_index_update ( Z_ARRVAL_P ( arg ) , index , & tmp ) ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int array_set_zval_key ( HashTable * ht , zval * key , zval * value ) /* { { { */
2013-02-17 02:13:36 +08:00
{
2014-02-10 14:04:30 +08:00
zval * result ;
2013-02-17 02:13:36 +08:00
switch ( Z_TYPE_P ( key ) ) {
case IS_STRING :
2014-02-10 14:04:30 +08:00
result = zend_symtable_update ( ht , Z_STR_P ( key ) , value ) ;
2013-02-17 02:13:36 +08:00
break ;
case IS_NULL :
2015-06-29 21:44:54 +08:00
result = zend_symtable_update ( ht , ZSTR_EMPTY_ALLOC ( ) , value ) ;
2013-02-17 02:13:36 +08:00
break ;
case IS_RESOURCE :
2016-02-14 21:02:19 +08:00
zend_error ( E_NOTICE , " Resource ID#%d used as offset, casting to integer (%d) " , Z_RES_HANDLE_P ( key ) , Z_RES_HANDLE_P ( key ) ) ;
2014-02-24 17:12:53 +08:00
result = zend_hash_index_update ( ht , Z_RES_HANDLE_P ( key ) , value ) ;
break ;
2014-04-30 22:32:42 +08:00
case IS_FALSE :
result = zend_hash_index_update ( ht , 0 , value ) ;
break ;
case IS_TRUE :
result = zend_hash_index_update ( ht , 1 , value ) ;
break ;
2014-08-26 01:24:55 +08:00
case IS_LONG :
result = zend_hash_index_update ( ht , Z_LVAL_P ( key ) , value ) ;
2013-02-17 02:13:36 +08:00
break ;
case IS_DOUBLE :
2014-08-26 01:24:55 +08:00
result = zend_hash_index_update ( ht , zend_dval_to_lval ( Z_DVAL_P ( key ) ) , value ) ;
2013-02-17 02:13:36 +08:00
break ;
default :
zend_error ( E_WARNING , " Illegal offset type " ) ;
2014-02-10 14:04:30 +08:00
result = NULL ;
2013-02-17 02:13:36 +08:00
}
2014-02-10 14:04:30 +08:00
if ( result ) {
2014-02-28 22:44:50 +08:00
if ( Z_REFCOUNTED_P ( result ) ) {
Z_ADDREF_P ( result ) ;
}
2014-02-10 14:04:30 +08:00
return SUCCESS ;
} else {
return FAILURE ;
2013-02-17 02:13:36 +08:00
}
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API int add_property_long_ex ( zval * arg , const char * key , size_t key_len , zend_long n ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
zval z_key ;
2007-11-03 03:40:39 +08:00
2014-08-26 01:24:55 +08:00
ZVAL_LONG ( & tmp , n ) ;
2014-03-01 03:05:22 +08:00
ZVAL_STRINGL ( & z_key , key , key_len ) ;
2014-12-14 06:06:14 +08:00
Z_OBJ_HANDLER_P ( arg , write_property ) ( arg , & z_key , & tmp , NULL ) ;
2003-01-14 23:12:35 +08:00
zval_ptr_dtor ( & tmp ) ; /* write_property will add 1 to refcount */
2005-11-23 19:15:11 +08:00
zval_ptr_dtor ( & z_key ) ;
2003-01-14 20:15:09 +08:00
return SUCCESS ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int add_property_bool_ex ( zval * arg , const char * key , size_t key_len , zend_long b ) /* { { { */
2000-02-02 07:12:48 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
zval z_key ;
2003-01-14 20:15:09 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_BOOL ( & tmp , b ) ;
2014-03-01 03:05:22 +08:00
ZVAL_STRINGL ( & z_key , key , key_len ) ;
2014-12-14 06:06:14 +08:00
Z_OBJ_HANDLER_P ( arg , write_property ) ( arg , & z_key , & tmp , NULL ) ;
2003-01-14 23:12:35 +08:00
zval_ptr_dtor ( & tmp ) ; /* write_property will add 1 to refcount */
2005-11-23 19:15:11 +08:00
zval_ptr_dtor ( & z_key ) ;
2003-01-14 20:15:09 +08:00
return SUCCESS ;
2000-02-02 07:12:48 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2000-02-02 07:12:48 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int add_property_null_ex ( zval * arg , const char * key , size_t key_len ) /* { { { */
2000-02-02 07:12:48 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
zval z_key ;
2007-11-03 03:40:39 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_NULL ( & tmp ) ;
2014-03-01 03:05:22 +08:00
ZVAL_STRINGL ( & z_key , key , key_len ) ;
2014-12-14 06:06:14 +08:00
Z_OBJ_HANDLER_P ( arg , write_property ) ( arg , & z_key , & tmp , NULL ) ;
2003-01-14 23:12:35 +08:00
zval_ptr_dtor ( & tmp ) ; /* write_property will add 1 to refcount */
2005-11-23 19:15:11 +08:00
zval_ptr_dtor ( & z_key ) ;
2003-01-14 20:15:09 +08:00
return SUCCESS ;
2000-02-02 07:12:48 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2000-02-02 07:12:48 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int add_property_resource_ex ( zval * arg , const char * key , size_t key_len , zend_resource * r ) /* { { { */
1999-09-29 23:25:06 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
zval z_key ;
2005-11-23 19:15:11 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_RES ( & tmp , r ) ;
2014-03-01 03:05:22 +08:00
ZVAL_STRINGL ( & z_key , key , key_len ) ;
2014-12-14 06:06:14 +08:00
Z_OBJ_HANDLER_P ( arg , write_property ) ( arg , & z_key , & tmp , NULL ) ;
2003-01-14 23:12:35 +08:00
zval_ptr_dtor ( & tmp ) ; /* write_property will add 1 to refcount */
2005-11-23 19:15:11 +08:00
zval_ptr_dtor ( & z_key ) ;
2003-01-14 20:15:09 +08:00
return SUCCESS ;
1999-09-29 23:25:06 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-09-29 23:25:06 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int add_property_double_ex ( zval * arg , const char * key , size_t key_len , double d ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
zval z_key ;
2003-01-01 20:38:55 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_DOUBLE ( & tmp , d ) ;
2014-03-01 03:05:22 +08:00
ZVAL_STRINGL ( & z_key , key , key_len ) ;
2014-12-14 06:06:14 +08:00
Z_OBJ_HANDLER_P ( arg , write_property ) ( arg , & z_key , & tmp , NULL ) ;
2003-01-14 23:12:35 +08:00
zval_ptr_dtor ( & tmp ) ; /* write_property will add 1 to refcount */
2005-11-23 19:15:11 +08:00
zval_ptr_dtor ( & z_key ) ;
2003-01-14 20:15:09 +08:00
return SUCCESS ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int add_property_str_ex ( zval * arg , const char * key , size_t key_len , zend_string * str ) /* { { { */
2014-05-15 06:44:47 +08:00
{
zval tmp ;
zval z_key ;
ZVAL_STR ( & tmp , str ) ;
ZVAL_STRINGL ( & z_key , key , key_len ) ;
2014-12-14 06:06:14 +08:00
Z_OBJ_HANDLER_P ( arg , write_property ) ( arg , & z_key , & tmp , NULL ) ;
2014-05-15 20:18:19 +08:00
zval_ptr_dtor ( & tmp ) ; /* write_property will add 1 to refcount */
2014-05-15 06:44:47 +08:00
zval_ptr_dtor ( & z_key ) ;
return SUCCESS ;
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API int add_property_string_ex ( zval * arg , const char * key , size_t key_len , const char * str ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
zval z_key ;
1999-04-08 02:10:10 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_STRING ( & tmp , str ) ;
2014-03-01 03:05:22 +08:00
ZVAL_STRINGL ( & z_key , key , key_len ) ;
2014-12-14 06:06:14 +08:00
Z_OBJ_HANDLER_P ( arg , write_property ) ( arg , & z_key , & tmp , NULL ) ;
2003-01-14 23:12:35 +08:00
zval_ptr_dtor ( & tmp ) ; /* write_property will add 1 to refcount */
2005-11-23 19:15:11 +08:00
zval_ptr_dtor ( & z_key ) ;
2003-01-14 20:15:09 +08:00
return SUCCESS ;
2001-01-21 03:16:38 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int add_property_stringl_ex ( zval * arg , const char * key , size_t key_len , const char * str , size_t length ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
zval z_key ;
2001-01-21 03:16:38 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_STRINGL ( & tmp , str , length ) ;
2014-03-01 03:05:22 +08:00
ZVAL_STRINGL ( & z_key , key , key_len ) ;
2014-12-14 06:06:14 +08:00
Z_OBJ_HANDLER_P ( arg , write_property ) ( arg , & z_key , & tmp , NULL ) ;
2003-01-14 23:12:35 +08:00
zval_ptr_dtor ( & tmp ) ; /* write_property will add 1 to refcount */
2005-11-23 19:15:11 +08:00
zval_ptr_dtor ( & z_key ) ;
2003-01-14 20:15:09 +08:00
return SUCCESS ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int add_property_zval_ex ( zval * arg , const char * key , size_t key_len , zval * value ) /* { { { */
2001-01-21 03:16:38 +08:00
{
2014-02-10 14:04:30 +08:00
zval z_key ;
2003-01-14 20:15:09 +08:00
2014-03-01 03:05:22 +08:00
ZVAL_STRINGL ( & z_key , key , key_len ) ;
2014-12-14 06:06:14 +08:00
Z_OBJ_HANDLER_P ( arg , write_property ) ( arg , & z_key , value , NULL ) ;
2005-11-23 19:15:11 +08:00
zval_ptr_dtor ( & z_key ) ;
2003-01-14 20:15:09 +08:00
return SUCCESS ;
2001-01-21 03:16:38 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_startup_module_ex ( zend_module_entry * module ) /* { { { */
2005-06-17 17:36:26 +08:00
{
2014-10-24 19:20:55 +08:00
size_t name_len ;
2014-02-10 14:04:30 +08:00
zend_string * lcname ;
2005-06-17 17:36:26 +08:00
if ( module - > module_started ) {
return SUCCESS ;
}
module - > module_started = 1 ;
/* Check module dependencies */
if ( module - > deps ) {
2007-09-28 02:00:48 +08:00
const zend_module_dep * dep = module - > deps ;
2005-06-17 17:36:26 +08:00
while ( dep - > name ) {
if ( dep - > type = = MODULE_DEP_REQUIRED ) {
zend_module_entry * req_mod ;
name_len = strlen ( dep - > name ) ;
2014-08-26 01:24:55 +08:00
lcname = zend_string_alloc ( name_len , 0 ) ;
2015-06-30 18:59:27 +08:00
zend_str_tolower_copy ( ZSTR_VAL ( lcname ) , dep - > name , name_len ) ;
2005-06-17 17:36:26 +08:00
2014-02-10 14:04:30 +08:00
if ( ( req_mod = zend_hash_find_ptr ( & module_registry , lcname ) ) = = NULL | | ! req_mod - > module_started ) {
2014-08-26 01:24:55 +08:00
zend_string_free ( lcname ) ;
2005-06-17 17:36:26 +08:00
/* TODO: Check version relationship */
2005-08-08 22:25:05 +08:00
zend_error ( E_CORE_WARNING , " Cannot load module '%s' because required module '%s' is not loaded " , module - > name , dep - > name ) ;
2005-06-17 17:36:26 +08:00
module - > module_started = 0 ;
return FAILURE ;
2006-05-10 07:53:23 +08:00
}
2014-08-26 01:24:55 +08:00
zend_string_free ( lcname ) ;
2005-06-17 17:36:26 +08:00
}
+ + dep ;
}
}
2006-06-15 22:03:21 +08:00
/* Initialize module globals */
if ( module - > globals_size ) {
# ifdef ZTS
ts_allocate_id ( module - > globals_id_ptr , module - > globals_size , ( ts_allocate_ctor ) module - > globals_ctor , ( ts_allocate_dtor ) module - > globals_dtor ) ;
# else
if ( module - > globals_ctor ) {
2014-12-14 06:06:14 +08:00
module - > globals_ctor ( module - > globals_ptr ) ;
2006-06-15 22:03:21 +08:00
}
# endif
}
2005-06-17 17:36:26 +08:00
if ( module - > module_startup_func ) {
EG ( current_module ) = module ;
2014-12-14 06:06:14 +08:00
if ( module - > module_startup_func ( module - > type , module - > module_number ) = = FAILURE ) {
2015-04-01 18:32:23 +08:00
zend_error_noreturn ( E_CORE_ERROR , " Unable to start %s module " , module - > name ) ;
2005-06-17 17:36:26 +08:00
EG ( current_module ) = NULL ;
return FAILURE ;
}
EG ( current_module ) = NULL ;
}
return SUCCESS ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-06-17 17:36:26 +08:00
2014-12-14 06:06:14 +08:00
static int zend_startup_module_zval ( zval * zv ) /* { { { */
2014-02-17 15:50:32 +08:00
{
zend_module_entry * module = Z_PTR_P ( zv ) ;
2016-09-20 17:34:40 +08:00
return ( zend_startup_module_ex ( module ) = = SUCCESS ) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_REMOVE ;
2014-02-17 15:50:32 +08:00
}
/* }}} */
2015-01-14 17:22:58 +08:00
static void zend_sort_modules ( void * base , size_t count , size_t siz , compare_func_t compare , swap_func_t swp ) /* { { { */
2005-06-17 17:36:26 +08:00
{
2014-02-10 14:04:30 +08:00
Bucket * b1 = base ;
Bucket * b2 ;
Bucket * end = b1 + count ;
Bucket tmp ;
2005-06-17 17:36:26 +08:00
zend_module_entry * m , * r ;
while ( b1 < end ) {
try_again :
2014-02-10 14:04:30 +08:00
m = ( zend_module_entry * ) Z_PTR ( b1 - > val ) ;
2005-06-17 17:36:26 +08:00
if ( ! m - > module_started & & m - > deps ) {
2007-09-28 02:00:48 +08:00
const zend_module_dep * dep = m - > deps ;
2005-06-17 17:36:26 +08:00
while ( dep - > name ) {
if ( dep - > type = = MODULE_DEP_REQUIRED | | dep - > type = = MODULE_DEP_OPTIONAL ) {
b2 = b1 + 1 ;
while ( b2 < end ) {
2014-02-10 14:04:30 +08:00
r = ( zend_module_entry * ) Z_PTR ( b2 - > val ) ;
2007-07-06 20:17:58 +08:00
if ( strcasecmp ( dep - > name , r - > name ) = = 0 ) {
2007-11-03 03:40:39 +08:00
tmp = * b1 ;
2007-07-06 20:17:58 +08:00
* b1 = * b2 ;
* b2 = tmp ;
goto try_again ;
}
b2 + + ;
}
}
dep + + ;
2006-05-10 07:53:23 +08:00
}
2005-06-17 17:36:26 +08:00
}
b1 + + ;
}
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-06-17 17:36:26 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API void zend_collect_module_handlers ( void ) /* { { { */
2010-07-06 19:40:17 +08:00
{
zend_module_entry * module ;
int startup_count = 0 ;
int shutdown_count = 0 ;
int post_deactivate_count = 0 ;
2014-02-17 15:50:32 +08:00
zend_class_entry * ce ;
2010-07-06 19:40:17 +08:00
int class_count = 0 ;
/* Collect extensions with request startup/shutdown handlers */
2014-04-18 23:18:11 +08:00
ZEND_HASH_FOREACH_PTR ( & module_registry , module ) {
2010-07-06 19:40:17 +08:00
if ( module - > request_startup_func ) {
startup_count + + ;
}
if ( module - > request_shutdown_func ) {
shutdown_count + + ;
}
if ( module - > post_deactivate_func ) {
post_deactivate_count + + ;
}
2014-04-18 23:18:11 +08:00
} ZEND_HASH_FOREACH_END ( ) ;
2010-07-06 19:40:17 +08:00
module_request_startup_handlers = ( zend_module_entry * * ) malloc (
sizeof ( zend_module_entry * ) *
( startup_count + 1 +
shutdown_count + 1 +
post_deactivate_count + 1 ) ) ;
module_request_startup_handlers [ startup_count ] = NULL ;
module_request_shutdown_handlers = module_request_startup_handlers + startup_count + 1 ;
module_request_shutdown_handlers [ shutdown_count ] = NULL ;
module_post_deactivate_handlers = module_request_shutdown_handlers + shutdown_count + 1 ;
module_post_deactivate_handlers [ post_deactivate_count ] = NULL ;
startup_count = 0 ;
2015-01-03 17:22:58 +08:00
2014-04-18 23:18:11 +08:00
ZEND_HASH_FOREACH_PTR ( & module_registry , module ) {
2010-07-06 19:40:17 +08:00
if ( module - > request_startup_func ) {
module_request_startup_handlers [ startup_count + + ] = module ;
}
if ( module - > request_shutdown_func ) {
module_request_shutdown_handlers [ - - shutdown_count ] = module ;
}
if ( module - > post_deactivate_func ) {
module_post_deactivate_handlers [ - - post_deactivate_count ] = module ;
}
2014-04-18 23:18:11 +08:00
} ZEND_HASH_FOREACH_END ( ) ;
2010-07-06 19:40:17 +08:00
/* Collect internal classes with static members */
2014-04-18 23:18:11 +08:00
ZEND_HASH_FOREACH_PTR ( CG ( class_table ) , ce ) {
2014-02-17 15:50:32 +08:00
if ( ce - > type = = ZEND_INTERNAL_CLASS & &
ce - > default_static_members_count > 0 ) {
2010-07-06 19:40:17 +08:00
class_count + + ;
}
2014-04-18 23:18:11 +08:00
} ZEND_HASH_FOREACH_END ( ) ;
2010-07-06 19:40:17 +08:00
class_cleanup_handlers = ( zend_class_entry * * ) malloc (
sizeof ( zend_class_entry * ) *
( class_count + 1 ) ) ;
class_cleanup_handlers [ class_count ] = NULL ;
if ( class_count ) {
2014-04-18 23:18:11 +08:00
ZEND_HASH_FOREACH_PTR ( CG ( class_table ) , ce ) {
2014-02-17 15:50:32 +08:00
if ( ce - > type = = ZEND_INTERNAL_CLASS & &
ce - > default_static_members_count > 0 ) {
class_cleanup_handlers [ - - class_count ] = ce ;
2010-07-06 19:40:17 +08:00
}
2014-04-18 23:18:11 +08:00
} ZEND_HASH_FOREACH_END ( ) ;
2010-07-06 19:40:17 +08:00
}
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API int zend_startup_modules ( void ) /* { { { */
2005-06-17 17:36:26 +08:00
{
2015-01-14 17:22:58 +08:00
zend_hash_sort_ex ( & module_registry , zend_sort_modules , NULL , 0 ) ;
2014-12-14 06:06:14 +08:00
zend_hash_apply ( & module_registry , zend_startup_module_zval ) ;
2005-06-17 17:36:26 +08:00
return SUCCESS ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-06-17 17:36:26 +08:00
2010-07-06 19:40:17 +08:00
ZEND_API void zend_destroy_modules ( void ) /* { { { */
{
free ( class_cleanup_handlers ) ;
free ( module_request_startup_handlers ) ;
zend_hash_graceful_reverse_destroy ( & module_registry ) ;
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API zend_module_entry * zend_register_module_ex ( zend_module_entry * module ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-10-24 19:20:55 +08:00
size_t name_len ;
2014-02-10 14:04:30 +08:00
zend_string * lcname ;
2014-02-12 22:08:11 +08:00
zend_module_entry * module_ptr ;
2006-05-10 07:53:23 +08:00
2004-05-13 07:05:28 +08:00
if ( ! module ) {
2005-07-19 00:20:08 +08:00
return NULL ;
2004-05-13 07:05:28 +08:00
}
2004-05-13 07:03:38 +08:00
2004-05-13 07:05:28 +08:00
#if 0
2007-11-03 03:40:39 +08:00
zend_printf ( " %s: Registering module %d \n " , module - > name , module - > module_number ) ;
2004-05-13 07:05:28 +08:00
# endif
2005-06-17 17:36:26 +08:00
/* Check module dependencies */
if ( module - > deps ) {
2007-09-28 02:00:48 +08:00
const zend_module_dep * dep = module - > deps ;
2005-06-17 17:36:26 +08:00
while ( dep - > name ) {
if ( dep - > type = = MODULE_DEP_CONFLICTS ) {
name_len = strlen ( dep - > name ) ;
2014-08-26 01:24:55 +08:00
lcname = zend_string_alloc ( name_len , 0 ) ;
2015-06-30 18:59:27 +08:00
zend_str_tolower_copy ( ZSTR_VAL ( lcname ) , dep - > name , name_len ) ;
2005-06-17 17:36:26 +08:00
2015-12-13 21:06:08 +08:00
if ( zend_hash_exists ( & module_registry , lcname ) | | zend_get_extension ( dep - > name ) ) {
2014-08-26 01:24:55 +08:00
zend_string_free ( lcname ) ;
2005-06-17 17:36:26 +08:00
/* TODO: Check version relationship */
zend_error ( E_CORE_WARNING , " Cannot load module '%s' because conflicting module '%s' is already loaded " , module - > name , dep - > name ) ;
2005-07-19 00:20:08 +08:00
return NULL ;
2006-05-10 07:53:23 +08:00
}
2014-08-26 01:24:55 +08:00
zend_string_free ( lcname ) ;
2005-06-17 17:36:26 +08:00
}
+ + dep ;
}
}
2004-05-13 07:05:28 +08:00
name_len = strlen ( module - > name ) ;
2014-08-26 01:24:55 +08:00
lcname = zend_string_alloc ( name_len , 1 ) ;
2015-06-30 18:59:27 +08:00
zend_str_tolower_copy ( ZSTR_VAL ( lcname ) , module - > name , name_len ) ;
2004-05-13 07:05:28 +08:00
2017-03-04 17:39:13 +08:00
lcname = zend_new_interned_string ( lcname ) ;
2014-02-12 22:08:11 +08:00
if ( ( module_ptr = zend_hash_add_mem ( & module_registry , lcname , module , sizeof ( zend_module_entry ) ) ) = = NULL ) {
2004-05-13 07:05:28 +08:00
zend_error ( E_CORE_WARNING , " Module '%s' already loaded " , module - > name ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( lcname ) ;
2005-07-19 00:20:08 +08:00
return NULL ;
2004-05-13 07:05:28 +08:00
}
2014-02-12 22:08:11 +08:00
module = module_ptr ;
2006-05-10 07:53:23 +08:00
EG ( current_module ) = module ;
2004-05-13 07:05:28 +08:00
2014-12-14 06:06:14 +08:00
if ( module - > functions & & zend_register_functions ( NULL , module - > functions , NULL , module - > type ) = = FAILURE ) {
2017-06-30 02:22:21 +08:00
zend_hash_del ( & module_registry , lcname ) ;
zend_string_release ( lcname ) ;
2006-05-10 07:53:23 +08:00
EG ( current_module ) = NULL ;
2007-11-03 03:40:39 +08:00
zend_error ( E_CORE_WARNING , " %s: Unable to register functions, unable to load " , module - > name ) ;
2005-07-19 00:20:08 +08:00
return NULL ;
2004-05-13 07:05:28 +08:00
}
2006-05-10 07:53:23 +08:00
EG ( current_module ) = NULL ;
2017-06-30 02:22:21 +08:00
zend_string_release ( lcname ) ;
2005-07-19 00:20:08 +08:00
return module ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API zend_module_entry * zend_register_internal_module ( zend_module_entry * module ) /* { { { */
2004-05-13 07:05:28 +08:00
{
module - > module_number = zend_next_free_module ( ) ;
module - > type = MODULE_PERSISTENT ;
2014-12-14 06:06:14 +08:00
return zend_register_module_ex ( module ) ;
2004-05-13 07:05:28 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2004-05-13 07:05:28 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API void zend_check_magic_method_implementation ( const zend_class_entry * ce , const zend_function * fptr , int error_type ) /* { { { */
2004-09-10 00:51:45 +08:00
{
char lcname [ 16 ] ;
2014-10-24 19:20:55 +08:00
size_t name_len ;
2004-09-10 00:51:45 +08:00
2007-11-03 03:40:39 +08:00
/* we don't care if the function name is longer, in fact lowercasing only
2004-09-10 00:51:45 +08:00
* the beginning of the name speeds up the check process */
2015-06-30 18:59:27 +08:00
name_len = ZSTR_LEN ( fptr - > common . function_name ) ;
zend_str_tolower_copy ( lcname , ZSTR_VAL ( fptr - > common . function_name ) , MIN ( name_len , sizeof ( lcname ) - 1 ) ) ;
2004-09-10 00:51:45 +08:00
lcname [ sizeof ( lcname ) - 1 ] = ' \0 ' ; /* zend_str_tolower_copy won't necessarily set the zero byte */
2013-12-17 15:09:52 +08:00
if ( name_len = = sizeof ( ZEND_DESTRUCTOR_FUNC_NAME ) - 1 & & ! memcmp ( lcname , ZEND_DESTRUCTOR_FUNC_NAME , sizeof ( ZEND_DESTRUCTOR_FUNC_NAME ) - 1 ) & & fptr - > common . num_args ! = 0 ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Destructor %s::%s() cannot take arguments " , ZSTR_VAL ( ce - > name ) , ZEND_DESTRUCTOR_FUNC_NAME ) ;
2013-12-17 15:09:52 +08:00
} else if ( name_len = = sizeof ( ZEND_CLONE_FUNC_NAME ) - 1 & & ! memcmp ( lcname , ZEND_CLONE_FUNC_NAME , sizeof ( ZEND_CLONE_FUNC_NAME ) - 1 ) & & fptr - > common . num_args ! = 0 ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() cannot accept any arguments " , ZSTR_VAL ( ce - > name ) , ZEND_CLONE_FUNC_NAME ) ;
2013-12-17 15:09:52 +08:00
} else if ( name_len = = sizeof ( ZEND_GET_FUNC_NAME ) - 1 & & ! memcmp ( lcname , ZEND_GET_FUNC_NAME , sizeof ( ZEND_GET_FUNC_NAME ) - 1 ) ) {
2007-08-31 20:36:14 +08:00
if ( fptr - > common . num_args ! = 1 ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() must take exactly 1 argument " , ZSTR_VAL ( ce - > name ) , ZEND_GET_FUNC_NAME ) ;
2007-08-31 20:36:14 +08:00
} else if ( ARG_SHOULD_BE_SENT_BY_REF ( fptr , 1 ) ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() cannot take arguments by reference " , ZSTR_VAL ( ce - > name ) , ZEND_GET_FUNC_NAME ) ;
2007-08-31 20:36:14 +08:00
}
2013-12-17 15:09:52 +08:00
} else if ( name_len = = sizeof ( ZEND_SET_FUNC_NAME ) - 1 & & ! memcmp ( lcname , ZEND_SET_FUNC_NAME , sizeof ( ZEND_SET_FUNC_NAME ) - 1 ) ) {
2007-08-31 20:36:14 +08:00
if ( fptr - > common . num_args ! = 2 ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() must take exactly 2 arguments " , ZSTR_VAL ( ce - > name ) , ZEND_SET_FUNC_NAME ) ;
2007-08-31 20:36:14 +08:00
} else if ( ARG_SHOULD_BE_SENT_BY_REF ( fptr , 1 ) | | ARG_SHOULD_BE_SENT_BY_REF ( fptr , 2 ) ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() cannot take arguments by reference " , ZSTR_VAL ( ce - > name ) , ZEND_SET_FUNC_NAME ) ;
2007-08-31 20:36:14 +08:00
}
2013-12-17 15:09:52 +08:00
} else if ( name_len = = sizeof ( ZEND_UNSET_FUNC_NAME ) - 1 & & ! memcmp ( lcname , ZEND_UNSET_FUNC_NAME , sizeof ( ZEND_UNSET_FUNC_NAME ) - 1 ) ) {
2007-08-31 20:36:14 +08:00
if ( fptr - > common . num_args ! = 1 ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() must take exactly 1 argument " , ZSTR_VAL ( ce - > name ) , ZEND_UNSET_FUNC_NAME ) ;
2007-08-31 20:36:14 +08:00
} else if ( ARG_SHOULD_BE_SENT_BY_REF ( fptr , 1 ) ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() cannot take arguments by reference " , ZSTR_VAL ( ce - > name ) , ZEND_UNSET_FUNC_NAME ) ;
2007-08-31 20:36:14 +08:00
}
2013-12-17 15:09:52 +08:00
} else if ( name_len = = sizeof ( ZEND_ISSET_FUNC_NAME ) - 1 & & ! memcmp ( lcname , ZEND_ISSET_FUNC_NAME , sizeof ( ZEND_ISSET_FUNC_NAME ) - 1 ) ) {
2007-08-31 20:36:14 +08:00
if ( fptr - > common . num_args ! = 1 ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() must take exactly 1 argument " , ZSTR_VAL ( ce - > name ) , ZEND_ISSET_FUNC_NAME ) ;
2007-08-31 20:36:14 +08:00
} else if ( ARG_SHOULD_BE_SENT_BY_REF ( fptr , 1 ) ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() cannot take arguments by reference " , ZSTR_VAL ( ce - > name ) , ZEND_ISSET_FUNC_NAME ) ;
2007-08-31 20:36:14 +08:00
}
2013-12-17 15:09:52 +08:00
} else if ( name_len = = sizeof ( ZEND_CALL_FUNC_NAME ) - 1 & & ! memcmp ( lcname , ZEND_CALL_FUNC_NAME , sizeof ( ZEND_CALL_FUNC_NAME ) - 1 ) ) {
2007-08-31 20:36:14 +08:00
if ( fptr - > common . num_args ! = 2 ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() must take exactly 2 arguments " , ZSTR_VAL ( ce - > name ) , ZEND_CALL_FUNC_NAME ) ;
2007-08-31 20:36:14 +08:00
} else if ( ARG_SHOULD_BE_SENT_BY_REF ( fptr , 1 ) | | ARG_SHOULD_BE_SENT_BY_REF ( fptr , 2 ) ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() cannot take arguments by reference " , ZSTR_VAL ( ce - > name ) , ZEND_CALL_FUNC_NAME ) ;
2007-08-31 20:36:14 +08:00
}
2007-09-29 16:52:40 +08:00
} else if ( name_len = = sizeof ( ZEND_CALLSTATIC_FUNC_NAME ) - 1 & &
2007-11-03 03:40:39 +08:00
! memcmp ( lcname , ZEND_CALLSTATIC_FUNC_NAME , sizeof ( ZEND_CALLSTATIC_FUNC_NAME ) - 1 )
) {
2007-09-29 16:52:40 +08:00
if ( fptr - > common . num_args ! = 2 ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::__callStatic() must take exactly 2 arguments " , ZSTR_VAL ( ce - > name ) ) ;
2007-09-29 16:52:40 +08:00
} else if ( ARG_SHOULD_BE_SENT_BY_REF ( fptr , 1 ) | | ARG_SHOULD_BE_SENT_BY_REF ( fptr , 2 ) ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::__callStatic() cannot take arguments by reference " , ZSTR_VAL ( ce - > name ) ) ;
2007-09-29 16:52:40 +08:00
}
} else if ( name_len = = sizeof ( ZEND_TOSTRING_FUNC_NAME ) - 1 & &
2007-11-03 03:40:39 +08:00
! memcmp ( lcname , ZEND_TOSTRING_FUNC_NAME , sizeof ( ZEND_TOSTRING_FUNC_NAME ) - 1 ) & & fptr - > common . num_args ! = 0
) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() cannot take arguments " , ZSTR_VAL ( ce - > name ) , ZEND_TOSTRING_FUNC_NAME ) ;
2014-02-18 11:13:00 +08:00
} else if ( name_len = = sizeof ( ZEND_DEBUGINFO_FUNC_NAME ) - 1 & &
! memcmp ( lcname , ZEND_DEBUGINFO_FUNC_NAME , sizeof ( ZEND_DEBUGINFO_FUNC_NAME ) - 1 ) & & fptr - > common . num_args ! = 0 ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() cannot take arguments " , ZSTR_VAL ( ce - > name ) , ZEND_DEBUGINFO_FUNC_NAME ) ;
2004-09-10 00:51:45 +08:00
}
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
/* registers all functions in *library_functions in the function hash */
2014-12-14 06:06:14 +08:00
ZEND_API int zend_register_functions ( zend_class_entry * scope , const zend_function_entry * functions , HashTable * function_table , int type ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2007-09-28 02:00:48 +08:00
const zend_function_entry * ptr = functions ;
2003-01-10 22:41:53 +08:00
zend_function function , * reg_function ;
1999-12-28 03:17:40 +08:00
zend_internal_function * internal_function = ( zend_internal_function * ) & function ;
2013-09-14 00:45:02 +08:00
int count = 0 , unload = 0 ;
1999-05-28 20:06:59 +08:00
HashTable * target_function_table = function_table ;
2000-06-13 04:22:17 +08:00
int error_type ;
2014-02-18 11:13:00 +08:00
zend_function * ctor = NULL , * dtor = NULL , * clone = NULL , * __get = NULL , * __set = NULL , * __unset = NULL , * __isset = NULL , * __call = NULL , * __callstatic = NULL , * __tostring = NULL , * __debugInfo = NULL ;
2014-02-10 14:04:30 +08:00
zend_string * lowercase_name ;
2014-10-24 19:20:55 +08:00
size_t fname_len ;
2010-10-15 05:33:10 +08:00
const char * lc_class_name = NULL ;
2014-10-24 19:20:55 +08:00
size_t class_name_len = 0 ;
1999-04-08 02:10:10 +08:00
2000-06-13 04:22:17 +08:00
if ( type = = MODULE_PERSISTENT ) {
error_type = E_CORE_WARNING ;
} else {
error_type = E_WARNING ;
}
1999-05-28 20:06:59 +08:00
if ( ! target_function_table ) {
target_function_table = CG ( function_table ) ;
}
1999-12-28 01:29:35 +08:00
internal_function - > type = ZEND_INTERNAL_FUNCTION ;
2007-05-30 18:17:43 +08:00
internal_function - > module = EG ( current_module ) ;
2015-09-29 18:31:47 +08:00
memset ( internal_function - > reserved , 0 , ZEND_MAX_RESERVED_RESOURCES * sizeof ( void * ) ) ;
2007-11-03 03:40:39 +08:00
2004-09-10 00:51:45 +08:00
if ( scope ) {
2015-06-30 18:59:27 +08:00
class_name_len = ZSTR_LEN ( scope - > name ) ;
if ( ( lc_class_name = zend_memrchr ( ZSTR_VAL ( scope - > name ) , ' \\ ' , class_name_len ) ) ) {
2008-11-04 23:58:55 +08:00
+ + lc_class_name ;
2015-06-30 18:59:27 +08:00
class_name_len - = ( lc_class_name - ZSTR_VAL ( scope - > name ) ) ;
2008-05-05 17:44:39 +08:00
lc_class_name = zend_str_tolower_dup ( lc_class_name , class_name_len ) ;
} else {
2015-06-30 18:59:27 +08:00
lc_class_name = zend_str_tolower_dup ( ZSTR_VAL ( scope - > name ) , class_name_len ) ;
2008-05-05 17:44:39 +08:00
}
2004-09-10 00:51:45 +08:00
}
2003-04-04 20:25:47 +08:00
1999-04-08 02:10:10 +08:00
while ( ptr - > fname ) {
2014-02-10 14:04:30 +08:00
fname_len = strlen ( ptr - > fname ) ;
1999-12-28 01:29:35 +08:00
internal_function - > handler = ptr - > handler ;
2017-10-19 05:02:56 +08:00
internal_function - > function_name = zend_string_init_interned ( ptr - > fname , fname_len , 1 ) ;
2002-11-24 04:44:12 +08:00
internal_function - > scope = scope ;
2003-03-29 19:19:38 +08:00
internal_function - > prototype = NULL ;
2003-08-04 05:04:39 +08:00
if ( ptr - > flags ) {
2003-08-04 05:06:23 +08:00
if ( ! ( ptr - > flags & ZEND_ACC_PPP_MASK ) ) {
2016-09-22 03:36:09 +08:00
if ( ptr - > flags ! = ZEND_ACC_DEPRECATED & & scope ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Invalid access level for %s%s%s() - access must be exactly one of public, protected or private " , scope ? ZSTR_VAL ( scope - > name ) : " " , scope ? " :: " : " " , ptr - > fname ) ;
2006-02-26 02:25:45 +08:00
}
2006-02-19 18:39:31 +08:00
internal_function - > fn_flags = ZEND_ACC_PUBLIC | ptr - > flags ;
2003-08-24 19:07:30 +08:00
} else {
internal_function - > fn_flags = ptr - > flags ;
2003-08-04 05:06:23 +08:00
}
2003-08-04 05:04:39 +08:00
} else {
internal_function - > fn_flags = ZEND_ACC_PUBLIC ;
}
2010-09-15 15:38:52 +08:00
if ( ptr - > arg_info ) {
zend_internal_function_info * info = ( zend_internal_function_info * ) ptr - > arg_info ;
2015-01-03 17:22:58 +08:00
2014-12-03 21:56:09 +08:00
internal_function - > arg_info = ( zend_internal_arg_info * ) ptr - > arg_info + 1 ;
2010-09-15 15:38:52 +08:00
internal_function - > num_args = ptr - > num_args ;
/* Currently you cannot denote that the function can accept less arguments than num_args */
2014-12-13 02:57:34 +08:00
if ( info - > required_num_args = = ( zend_uintptr_t ) - 1 ) {
2010-09-15 15:38:52 +08:00
internal_function - > required_num_args = ptr - > num_args ;
} else {
internal_function - > required_num_args = info - > required_num_args ;
}
if ( info - > return_reference ) {
internal_function - > fn_flags | = ZEND_ACC_RETURN_REFERENCE ;
}
2013-09-27 00:39:17 +08:00
if ( ptr - > arg_info [ ptr - > num_args ] . is_variadic ) {
internal_function - > fn_flags | = ZEND_ACC_VARIADIC ;
2014-12-22 21:44:39 +08:00
/* Don't count the variadic argument */
internal_function - > num_args - - ;
2013-09-27 00:39:17 +08:00
}
2017-01-13 16:37:46 +08:00
if ( ZEND_TYPE_IS_SET ( info - > type ) ) {
if ( ZEND_TYPE_IS_CLASS ( info - > type ) ) {
const char * type_name = ( const char * ) info - > type ;
if ( type_name [ 0 ] = = ' ? ' ) {
type_name + + ;
}
if ( ! scope & & ( ! strcasecmp ( type_name , " self " ) | | ! strcasecmp ( type_name , " parent " ) ) ) {
zend_error_noreturn ( E_CORE_ERROR , " Cannot declare a return type of %s outside of a class scope " , type_name ) ;
2015-02-05 11:22:11 +08:00
}
2015-02-05 01:04:54 +08:00
}
2015-01-09 04:40:36 +08:00
internal_function - > fn_flags | = ZEND_ACC_HAS_RETURN_TYPE ;
}
2010-09-15 15:38:52 +08:00
} else {
internal_function - > arg_info = NULL ;
internal_function - > num_args = 0 ;
internal_function - > required_num_args = 0 ;
}
2015-04-23 02:46:13 +08:00
zend_set_function_arg_flags ( ( zend_function * ) internal_function ) ;
2004-02-27 17:14:55 +08:00
if ( ptr - > flags & ZEND_ACC_ABSTRACT ) {
2003-08-17 08:57:35 +08:00
if ( scope ) {
2004-02-28 02:20:53 +08:00
/* This is a class that must be abstract itself. Here we set the check info. */
2004-03-10 00:38:37 +08:00
scope - > ce_flags | = ZEND_ACC_IMPLICIT_ABSTRACT_CLASS ;
2004-02-27 17:14:55 +08:00
if ( ! ( scope - > ce_flags & ZEND_ACC_INTERFACE ) ) {
2004-02-28 02:20:53 +08:00
/* Since the class is not an interface it needs to be declared as a abstract class. */
2004-03-10 00:38:37 +08:00
/* Since here we are handling internal functions only we can add the keyword flag. */
2008-02-19 14:52:43 +08:00
/* This time we set the flag for the keyword 'abstract'. */
2004-03-10 00:38:37 +08:00
scope - > ce_flags | = ZEND_ACC_EXPLICIT_ABSTRACT_CLASS ;
2004-02-27 17:14:55 +08:00
}
2003-08-17 08:57:35 +08:00
}
2006-06-04 18:27:28 +08:00
if ( ptr - > flags & ZEND_ACC_STATIC & & ( ! scope | | ! ( scope - > ce_flags & ZEND_ACC_INTERFACE ) ) ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Static function %s%s%s() cannot be abstract " , scope ? ZSTR_VAL ( scope - > name ) : " " , scope ? " :: " : " " , ptr - > fname ) ;
2006-06-04 18:27:28 +08:00
}
2003-08-17 08:57:35 +08:00
} else {
2004-02-27 17:14:55 +08:00
if ( scope & & ( scope - > ce_flags & ZEND_ACC_INTERFACE ) ) {
2011-09-13 21:29:35 +08:00
efree ( ( char * ) lc_class_name ) ;
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Interface %s cannot contain non abstract method %s() " , ZSTR_VAL ( scope - > name ) , ptr - > fname ) ;
2003-09-18 18:21:38 +08:00
return FAILURE ;
}
2003-08-17 08:57:35 +08:00
if ( ! internal_function - > handler ) {
2005-10-27 22:07:30 +08:00
if ( scope ) {
2011-09-13 21:29:35 +08:00
efree ( ( char * ) lc_class_name ) ;
2005-10-27 22:07:30 +08:00
}
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s%s%s() cannot be a NULL function " , scope ? ZSTR_VAL ( scope - > name ) : " " , scope ? " :: " : " " , ptr - > fname ) ;
2014-12-14 06:06:14 +08:00
zend_unregister_functions ( functions , count , target_function_table ) ;
2003-08-17 08:57:35 +08:00
return FAILURE ;
}
1999-04-08 02:10:10 +08:00
}
2014-08-26 01:24:55 +08:00
lowercase_name = zend_string_alloc ( fname_len , 1 ) ;
2015-06-30 18:59:27 +08:00
zend_str_tolower_copy ( ZSTR_VAL ( lowercase_name ) , ptr - > fname , fname_len ) ;
2014-12-14 06:06:14 +08:00
lowercase_name = zend_new_interned_string ( lowercase_name ) ;
2014-02-17 21:59:18 +08:00
reg_function = malloc ( sizeof ( zend_internal_function ) ) ;
memcpy ( reg_function , & function , sizeof ( zend_internal_function ) ) ;
if ( zend_hash_add_ptr ( target_function_table , lowercase_name , reg_function ) = = NULL ) {
2011-07-10 20:37:42 +08:00
unload = 1 ;
2014-02-17 21:59:18 +08:00
free ( reg_function ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( lowercase_name ) ;
2011-07-10 20:37:42 +08:00
break ;
1999-04-08 02:10:10 +08:00
}
2013-11-28 15:44:14 +08:00
/* If types of arguments have to be checked */
if ( reg_function - > common . arg_info & & reg_function - > common . num_args ) {
2014-09-15 17:40:18 +08:00
uint32_t i ;
2013-11-28 15:44:14 +08:00
for ( i = 0 ; i < reg_function - > common . num_args ; i + + ) {
2017-01-13 16:37:46 +08:00
if ( ZEND_TYPE_IS_SET ( reg_function - > common . arg_info [ i ] . type ) ) {
2013-11-28 15:44:14 +08:00
reg_function - > common . fn_flags | = ZEND_ACC_HAS_TYPE_HINTS ;
break ;
}
}
}
2017-01-13 16:37:46 +08:00
if ( reg_function - > common . arg_info & &
( reg_function - > common . fn_flags & ( ZEND_ACC_HAS_RETURN_TYPE | ZEND_ACC_HAS_TYPE_HINTS ) ) ) {
/* convert "const char*" class type names into "zend_string*" */
uint32_t i ;
uint32_t num_args = reg_function - > common . num_args + 1 ;
zend_arg_info * arg_info = reg_function - > common . arg_info - 1 ;
zend_arg_info * new_arg_info ;
if ( reg_function - > common . fn_flags & ZEND_ACC_VARIADIC ) {
num_args + + ;
}
new_arg_info = malloc ( sizeof ( zend_arg_info ) * num_args ) ;
memcpy ( new_arg_info , arg_info , sizeof ( zend_arg_info ) * num_args ) ;
reg_function - > common . arg_info = new_arg_info + 1 ;
for ( i = 0 ; i < num_args ; i + + ) {
if ( ZEND_TYPE_IS_CLASS ( new_arg_info [ i ] . type ) ) {
const char * class_name = ( const char * ) new_arg_info [ i ] . type ;
zend_bool allow_null = 0 ;
zend_string * str ;
if ( class_name [ 0 ] = = ' ? ' ) {
class_name + + ;
allow_null = 1 ;
}
2017-10-19 05:02:56 +08:00
str = zend_string_init_interned ( class_name , strlen ( class_name ) , 1 ) ;
2017-01-13 16:37:46 +08:00
new_arg_info [ i ] . type = ZEND_TYPE_ENCODE_CLASS ( str , allow_null ) ;
}
}
}
2003-01-10 22:41:53 +08:00
if ( scope ) {
2003-06-02 20:13:11 +08:00
/* Look for ctor, dtor, clone
* If it ' s an old - style constructor , store it only if we don ' t have
* a constructor already .
*/
2015-06-30 18:59:27 +08:00
if ( ( fname_len = = class_name_len ) & & ! ctor & & ! memcmp ( ZSTR_VAL ( lowercase_name ) , lc_class_name , class_name_len + 1 ) ) {
2003-06-02 20:13:11 +08:00
ctor = reg_function ;
2014-08-26 04:40:58 +08:00
} else if ( zend_string_equals_literal ( lowercase_name , ZEND_CONSTRUCTOR_FUNC_NAME ) ) {
2003-06-02 20:13:11 +08:00
ctor = reg_function ;
2014-08-26 04:40:58 +08:00
} else if ( zend_string_equals_literal ( lowercase_name , ZEND_DESTRUCTOR_FUNC_NAME ) ) {
2003-06-02 20:13:11 +08:00
dtor = reg_function ;
2004-03-27 04:05:35 +08:00
if ( internal_function - > num_args ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Destructor %s::%s() cannot take arguments " , ZSTR_VAL ( scope - > name ) , ptr - > fname ) ;
2004-03-27 04:05:35 +08:00
}
2014-08-26 04:40:58 +08:00
} else if ( zend_string_equals_literal ( lowercase_name , ZEND_CLONE_FUNC_NAME ) ) {
2003-06-02 20:13:11 +08:00
clone = reg_function ;
2014-08-26 04:40:58 +08:00
} else if ( zend_string_equals_literal ( lowercase_name , ZEND_CALL_FUNC_NAME ) ) {
2004-09-10 00:51:45 +08:00
__call = reg_function ;
2014-08-26 04:40:58 +08:00
} else if ( zend_string_equals_literal ( lowercase_name , ZEND_CALLSTATIC_FUNC_NAME ) ) {
2007-09-29 16:52:40 +08:00
__callstatic = reg_function ;
2014-08-26 04:40:58 +08:00
} else if ( zend_string_equals_literal ( lowercase_name , ZEND_TOSTRING_FUNC_NAME ) ) {
2006-05-10 07:53:23 +08:00
__tostring = reg_function ;
2014-08-26 04:40:58 +08:00
} else if ( zend_string_equals_literal ( lowercase_name , ZEND_GET_FUNC_NAME ) ) {
2004-09-10 00:51:45 +08:00
__get = reg_function ;
2015-02-04 20:24:13 +08:00
scope - > ce_flags | = ZEND_ACC_USE_GUARDS ;
2014-08-26 04:40:58 +08:00
} else if ( zend_string_equals_literal ( lowercase_name , ZEND_SET_FUNC_NAME ) ) {
2004-09-10 00:51:45 +08:00
__set = reg_function ;
2015-02-04 20:24:13 +08:00
scope - > ce_flags | = ZEND_ACC_USE_GUARDS ;
2014-08-26 04:40:58 +08:00
} else if ( zend_string_equals_literal ( lowercase_name , ZEND_UNSET_FUNC_NAME ) ) {
2005-07-08 00:07:09 +08:00
__unset = reg_function ;
2015-02-04 20:24:13 +08:00
scope - > ce_flags | = ZEND_ACC_USE_GUARDS ;
2014-08-26 04:40:58 +08:00
} else if ( zend_string_equals_literal ( lowercase_name , ZEND_ISSET_FUNC_NAME ) ) {
2005-07-08 00:07:09 +08:00
__isset = reg_function ;
2015-02-04 20:24:13 +08:00
scope - > ce_flags | = ZEND_ACC_USE_GUARDS ;
2014-08-26 04:40:58 +08:00
} else if ( zend_string_equals_literal ( lowercase_name , ZEND_DEBUGINFO_FUNC_NAME ) ) {
2014-02-18 11:13:00 +08:00
__debugInfo = reg_function ;
2004-09-10 00:51:45 +08:00
} else {
reg_function = NULL ;
}
if ( reg_function ) {
2014-12-14 06:06:14 +08:00
zend_check_magic_method_implementation ( scope , reg_function , error_type ) ;
2003-01-10 22:41:53 +08:00
}
}
1999-04-08 02:10:10 +08:00
ptr + + ;
count + + ;
2014-08-26 01:24:55 +08:00
zend_string_release ( lowercase_name ) ;
1999-04-08 02:10:10 +08:00
}
if ( unload ) { /* before unloading, display all remaining bad function in the module */
2004-09-10 00:51:45 +08:00
if ( scope ) {
2011-09-13 21:29:35 +08:00
efree ( ( char * ) lc_class_name ) ;
2004-09-10 00:51:45 +08:00
}
1999-04-08 02:10:10 +08:00
while ( ptr - > fname ) {
2008-08-22 22:51:30 +08:00
fname_len = strlen ( ptr - > fname ) ;
2014-08-26 01:24:55 +08:00
lowercase_name = zend_string_alloc ( fname_len , 0 ) ;
2015-06-30 18:59:27 +08:00
zend_str_tolower_copy ( ZSTR_VAL ( lowercase_name ) , ptr - > fname , fname_len ) ;
2014-02-10 14:04:30 +08:00
if ( zend_hash_exists ( target_function_table , lowercase_name ) ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Function registration failed - duplicate name - %s%s%s " , scope ? ZSTR_VAL ( scope - > name ) : " " , scope ? " :: " : " " , ptr - > fname ) ;
1999-04-08 02:10:10 +08:00
}
2014-08-26 01:24:55 +08:00
zend_string_free ( lowercase_name ) ;
1999-04-08 02:10:10 +08:00
ptr + + ;
}
2014-12-14 06:06:14 +08:00
zend_unregister_functions ( functions , count , target_function_table ) ;
1999-04-08 02:10:10 +08:00
return FAILURE ;
}
2003-01-10 22:41:53 +08:00
if ( scope ) {
scope - > constructor = ctor ;
scope - > destructor = dtor ;
scope - > clone = clone ;
2004-09-10 00:51:45 +08:00
scope - > __call = __call ;
2007-09-29 16:52:40 +08:00
scope - > __callstatic = __callstatic ;
2006-05-10 07:53:23 +08:00
scope - > __tostring = __tostring ;
2004-09-10 00:51:45 +08:00
scope - > __get = __get ;
scope - > __set = __set ;
2005-07-08 00:07:09 +08:00
scope - > __unset = __unset ;
scope - > __isset = __isset ;
2014-02-18 11:13:00 +08:00
scope - > __debugInfo = __debugInfo ;
2003-08-23 23:38:58 +08:00
if ( ctor ) {
2004-01-25 00:59:24 +08:00
ctor - > common . fn_flags | = ZEND_ACC_CTOR ;
2003-09-02 21:26:25 +08:00
if ( ctor - > common . fn_flags & ZEND_ACC_STATIC ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Constructor %s::%s() cannot be static " , ZSTR_VAL ( scope - > name ) , ZSTR_VAL ( ctor - > common . function_name ) ) ;
2003-09-02 21:26:25 +08:00
}
2004-01-25 00:59:24 +08:00
ctor - > common . fn_flags & = ~ ZEND_ACC_ALLOW_STATIC ;
2003-08-23 23:38:58 +08:00
}
if ( dtor ) {
2004-01-25 00:59:24 +08:00
dtor - > common . fn_flags | = ZEND_ACC_DTOR ;
2003-09-02 21:26:25 +08:00
if ( dtor - > common . fn_flags & ZEND_ACC_STATIC ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Destructor %s::%s() cannot be static " , ZSTR_VAL ( scope - > name ) , ZSTR_VAL ( dtor - > common . function_name ) ) ;
2003-09-02 21:26:25 +08:00
}
2004-01-25 00:59:24 +08:00
dtor - > common . fn_flags & = ~ ZEND_ACC_ALLOW_STATIC ;
2003-08-23 23:38:58 +08:00
}
2004-01-24 04:52:39 +08:00
if ( clone ) {
if ( clone - > common . fn_flags & ZEND_ACC_STATIC ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Constructor %s::%s() cannot be static " , ZSTR_VAL ( scope - > name ) , ZSTR_VAL ( clone - > common . function_name ) ) ;
2004-01-24 04:52:39 +08:00
}
2004-01-25 00:59:24 +08:00
clone - > common . fn_flags & = ~ ZEND_ACC_ALLOW_STATIC ;
2004-01-24 04:52:39 +08:00
}
2004-09-10 00:51:45 +08:00
if ( __call ) {
if ( __call - > common . fn_flags & ZEND_ACC_STATIC ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() cannot be static " , ZSTR_VAL ( scope - > name ) , ZSTR_VAL ( __call - > common . function_name ) ) ;
2004-09-10 00:51:45 +08:00
}
__call - > common . fn_flags & = ~ ZEND_ACC_ALLOW_STATIC ;
}
2007-09-29 16:52:40 +08:00
if ( __callstatic ) {
if ( ! ( __callstatic - > common . fn_flags & ZEND_ACC_STATIC ) ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() must be static " , ZSTR_VAL ( scope - > name ) , ZSTR_VAL ( __callstatic - > common . function_name ) ) ;
2007-09-29 16:52:40 +08:00
}
__callstatic - > common . fn_flags | = ZEND_ACC_STATIC ;
}
2006-05-10 07:53:23 +08:00
if ( __tostring ) {
if ( __tostring - > common . fn_flags & ZEND_ACC_STATIC ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() cannot be static " , ZSTR_VAL ( scope - > name ) , ZSTR_VAL ( __tostring - > common . function_name ) ) ;
2006-05-10 07:53:23 +08:00
}
__tostring - > common . fn_flags & = ~ ZEND_ACC_ALLOW_STATIC ;
}
2004-09-10 00:51:45 +08:00
if ( __get ) {
if ( __get - > common . fn_flags & ZEND_ACC_STATIC ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() cannot be static " , ZSTR_VAL ( scope - > name ) , ZSTR_VAL ( __get - > common . function_name ) ) ;
2004-09-10 00:51:45 +08:00
}
__get - > common . fn_flags & = ~ ZEND_ACC_ALLOW_STATIC ;
}
if ( __set ) {
if ( __set - > common . fn_flags & ZEND_ACC_STATIC ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() cannot be static " , ZSTR_VAL ( scope - > name ) , ZSTR_VAL ( __set - > common . function_name ) ) ;
2004-09-10 00:51:45 +08:00
}
__set - > common . fn_flags & = ~ ZEND_ACC_ALLOW_STATIC ;
}
2005-07-08 00:07:09 +08:00
if ( __unset ) {
if ( __unset - > common . fn_flags & ZEND_ACC_STATIC ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() cannot be static " , ZSTR_VAL ( scope - > name ) , ZSTR_VAL ( __unset - > common . function_name ) ) ;
2005-07-08 00:07:09 +08:00
}
__unset - > common . fn_flags & = ~ ZEND_ACC_ALLOW_STATIC ;
}
if ( __isset ) {
if ( __isset - > common . fn_flags & ZEND_ACC_STATIC ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() cannot be static " , ZSTR_VAL ( scope - > name ) , ZSTR_VAL ( __isset - > common . function_name ) ) ;
2005-07-08 00:07:09 +08:00
}
__isset - > common . fn_flags & = ~ ZEND_ACC_ALLOW_STATIC ;
}
2014-02-18 11:13:00 +08:00
if ( __debugInfo ) {
if ( __debugInfo - > common . fn_flags & ZEND_ACC_STATIC ) {
2015-06-30 18:59:27 +08:00
zend_error ( error_type , " Method %s::%s() cannot be static " , ZSTR_VAL ( scope - > name ) , ZSTR_VAL ( __debugInfo - > common . function_name ) ) ;
2014-02-18 11:13:00 +08:00
}
}
2015-02-05 11:22:11 +08:00
if ( ctor & & ctor - > common . fn_flags & ZEND_ACC_HAS_RETURN_TYPE & & ctor - > common . fn_flags & ZEND_ACC_CTOR ) {
2015-06-30 18:59:27 +08:00
zend_error_noreturn ( E_CORE_ERROR , " Constructor %s::%s() cannot declare a return type " , ZSTR_VAL ( scope - > name ) , ZSTR_VAL ( ctor - > common . function_name ) ) ;
2015-02-05 11:22:11 +08:00
}
if ( dtor & & dtor - > common . fn_flags & ZEND_ACC_HAS_RETURN_TYPE & & dtor - > common . fn_flags & ZEND_ACC_DTOR ) {
2015-06-30 18:59:27 +08:00
zend_error_noreturn ( E_CORE_ERROR , " Destructor %s::%s() cannot declare a return type " , ZSTR_VAL ( scope - > name ) , ZSTR_VAL ( dtor - > common . function_name ) ) ;
2015-02-05 11:22:11 +08:00
}
if ( clone & & clone - > common . fn_flags & ZEND_ACC_HAS_RETURN_TYPE & & dtor - > common . fn_flags & ZEND_ACC_DTOR ) {
2015-06-30 18:59:27 +08:00
zend_error_noreturn ( E_CORE_ERROR , " %s::%s() cannot declare a return type " , ZSTR_VAL ( scope - > name ) , ZSTR_VAL ( clone - > common . function_name ) ) ;
2015-02-05 11:22:11 +08:00
}
2011-09-13 21:29:35 +08:00
efree ( ( char * ) lc_class_name ) ;
2003-01-10 22:41:53 +08:00
}
1999-04-08 02:10:10 +08:00
return SUCCESS ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2006-05-10 07:53:23 +08:00
/* count=-1 means erase all functions, otherwise,
1999-04-08 02:10:10 +08:00
* erase the first count functions
*/
2014-12-14 06:06:14 +08:00
ZEND_API void zend_unregister_functions ( const zend_function_entry * functions , int count , HashTable * function_table ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2007-09-28 02:00:48 +08:00
const zend_function_entry * ptr = functions ;
1999-04-08 02:10:10 +08:00
int i = 0 ;
1999-05-28 20:06:59 +08:00
HashTable * target_function_table = function_table ;
2014-02-10 14:04:30 +08:00
zend_string * lowercase_name ;
2014-10-24 19:20:55 +08:00
size_t fname_len ;
1999-04-08 02:10:10 +08:00
1999-05-28 20:06:59 +08:00
if ( ! target_function_table ) {
target_function_table = CG ( function_table ) ;
}
1999-04-08 02:10:10 +08:00
while ( ptr - > fname ) {
if ( count ! = - 1 & & i > = count ) {
break ;
}
2014-02-10 14:04:30 +08:00
fname_len = strlen ( ptr - > fname ) ;
2014-08-26 01:24:55 +08:00
lowercase_name = zend_string_alloc ( fname_len , 0 ) ;
2015-06-30 18:59:27 +08:00
zend_str_tolower_copy ( ZSTR_VAL ( lowercase_name ) , ptr - > fname , fname_len ) ;
2014-02-10 14:04:30 +08:00
zend_hash_del ( target_function_table , lowercase_name ) ;
2014-08-26 01:24:55 +08:00
zend_string_free ( lowercase_name ) ;
1999-04-08 02:10:10 +08:00
ptr + + ;
i + + ;
}
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_startup_module ( zend_module_entry * module ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-12-14 06:06:14 +08:00
if ( ( module = zend_register_internal_module ( module ) ) ! = NULL & & zend_startup_module_ex ( module ) = = SUCCESS ) {
2005-06-17 17:36:26 +08:00
return SUCCESS ;
}
return FAILURE ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2008-08-13 01:20:25 +08:00
ZEND_API int zend_get_module_started ( const char * module_name ) /* { { { */
2004-01-19 08:39:29 +08:00
{
zend_module_entry * module ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
module = zend_hash_str_find_ptr ( & module_registry , module_name , strlen ( module_name ) ) ;
return ( module & & module - > module_started ) ? SUCCESS : FAILURE ;
2004-01-19 08:39:29 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2004-01-19 08:39:29 +08:00
2014-12-14 06:06:14 +08:00
static int clean_module_class ( zval * el , void * arg ) /* { { { */
2011-03-31 19:59:34 +08:00
{
2014-05-25 19:56:51 +08:00
zend_class_entry * ce = ( zend_class_entry * ) Z_PTR_P ( el ) ;
int module_number = * ( int * ) arg ;
if ( ce - > type = = ZEND_INTERNAL_CLASS & & ce - > info . internal . module - > module_number = = module_number ) {
2011-03-31 19:59:34 +08:00
return ZEND_HASH_APPLY_REMOVE ;
} else {
return ZEND_HASH_APPLY_KEEP ;
}
}
/* }}} */
2014-12-14 06:06:14 +08:00
static void clean_module_classes ( int module_number ) /* { { { */
2011-03-31 19:59:34 +08:00
{
2014-12-14 06:06:14 +08:00
zend_hash_apply_with_argument ( EG ( class_table ) , clean_module_class , ( void * ) & module_number ) ;
2011-03-31 19:59:34 +08:00
}
/* }}} */
2007-11-03 03:40:39 +08:00
void module_destructor ( zend_module_entry * module ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2001-07-30 09:48:22 +08:00
1999-04-08 02:10:10 +08:00
if ( module - > type = = MODULE_TEMPORARY ) {
2014-12-14 06:06:14 +08:00
zend_clean_module_rsrc_dtors ( module - > module_number ) ;
clean_module_constants ( module - > module_number ) ;
clean_module_classes ( module - > module_number ) ;
1999-04-08 02:10:10 +08:00
}
if ( module - > module_started & & module - > module_shutdown_func ) {
#if 0
2007-11-03 03:40:39 +08:00
zend_printf ( " %s: Module shutdown \n " , module - > name ) ;
1999-04-08 02:10:10 +08:00
# endif
2014-12-14 06:06:14 +08:00
module - > module_shutdown_func ( module - > type , module - > module_number ) ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
2006-06-15 22:03:21 +08:00
/* Deinitilaise module globals */
if ( module - > globals_size ) {
# ifdef ZTS
2012-09-15 11:50:16 +08:00
if ( * module - > globals_id_ptr ) {
ts_free_id ( * module - > globals_id_ptr ) ;
}
2006-06-15 22:03:21 +08:00
# else
if ( module - > globals_dtor ) {
2014-12-14 06:06:14 +08:00
module - > globals_dtor ( module - > globals_ptr ) ;
2006-06-15 22:03:21 +08:00
}
# endif
}
1999-04-08 02:10:10 +08:00
module - > module_started = 0 ;
1999-05-09 20:24:21 +08:00
if ( module - > functions ) {
2014-12-14 06:06:14 +08:00
zend_unregister_functions ( module - > functions , - 1 , NULL ) ;
1999-05-09 20:24:21 +08:00
}
1999-04-08 02:10:10 +08:00
2009-08-06 09:33:54 +08:00
# if HAVE_LIBDL
2011-07-14 20:21:15 +08:00
if ( module - > handle & & ! getenv ( " ZEND_DONT_UNLOAD_MODULES " ) ) {
2009-11-30 20:27:18 +08:00
DL_UNLOAD ( module - > handle ) ;
2006-05-10 07:53:23 +08:00
}
2004-09-22 22:31:21 +08:00
# endif
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API void zend_activate_modules ( void ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2010-07-06 19:40:17 +08:00
zend_module_entry * * p = module_request_startup_handlers ;
while ( * p ) {
zend_module_entry * module = * p ;
2014-12-14 06:06:14 +08:00
if ( module - > request_startup_func ( module - > type , module - > module_number ) = = FAILURE ) {
1999-11-26 21:53:18 +08:00
zend_error ( E_WARNING , " request_startup() for %s module failed " , module - > name ) ;
exit ( 1 ) ;
}
2010-07-06 19:40:17 +08:00
p + + ;
1999-04-08 02:10:10 +08:00
}
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2005-03-16 07:46:29 +08:00
/* call request shutdown for all modules */
2014-12-14 06:06:14 +08:00
static int module_registry_cleanup ( zval * zv ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-02-17 21:59:18 +08:00
zend_module_entry * module = Z_PTR_P ( zv ) ;
2005-03-16 07:46:29 +08:00
if ( module - > request_shutdown_func ) {
2000-04-25 00:04:13 +08:00
#if 0
2007-11-03 03:40:39 +08:00
zend_printf ( " %s: Request shutdown \n " , module - > name ) ;
2000-04-25 00:04:13 +08:00
# endif
2014-12-14 06:06:14 +08:00
module - > request_shutdown_func ( module - > type , module - > module_number ) ;
2005-03-16 07:46:29 +08:00
}
return 0 ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-03-16 07:46:29 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API void zend_deactivate_modules ( void ) /* { { { */
2010-07-06 19:40:17 +08:00
{
2014-07-03 03:29:53 +08:00
EG ( current_execute_data ) = NULL ; /* we're no longer executing anything */
2010-07-06 19:40:17 +08:00
zend_try {
if ( EG ( full_tables_cleanup ) ) {
2014-12-14 06:06:14 +08:00
zend_hash_reverse_apply ( & module_registry , module_registry_cleanup ) ;
2010-07-06 19:40:17 +08:00
} else {
zend_module_entry * * p = module_request_shutdown_handlers ;
while ( * p ) {
zend_module_entry * module = * p ;
2014-12-14 06:06:14 +08:00
module - > request_shutdown_func ( module - > type , module - > module_number ) ;
2010-07-06 19:40:17 +08:00
p + + ;
}
}
} zend_end_try ( ) ;
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API void zend_cleanup_internal_classes ( void ) /* { { { */
2010-07-06 19:40:17 +08:00
{
zend_class_entry * * p = class_cleanup_handlers ;
while ( * p ) {
2014-12-14 06:06:14 +08:00
zend_cleanup_internal_class_data ( * p ) ;
2010-07-06 19:40:17 +08:00
p + + ;
}
}
/* }}} */
2014-12-14 06:06:14 +08:00
int module_registry_unload_temp ( const zend_module_entry * module ) /* { { { */
2005-03-16 07:46:29 +08:00
{
2006-03-17 16:34:16 +08:00
return ( module - > type = = MODULE_TEMPORARY ) ? ZEND_HASH_APPLY_REMOVE : ZEND_HASH_APPLY_STOP ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-12-14 06:06:14 +08:00
static int module_registry_unload_temp_wrapper ( zval * el ) /* { { { */
2010-07-06 19:40:17 +08:00
{
2014-05-25 18:32:35 +08:00
zend_module_entry * module = ( zend_module_entry * ) Z_PTR_P ( el ) ;
2014-12-14 06:06:14 +08:00
return module_registry_unload_temp ( ( const zend_module_entry * ) module ) ;
2014-05-25 18:32:35 +08:00
}
/* }}} */
2014-12-14 06:06:14 +08:00
static int exec_done_cb ( zval * el ) /* { { { */
2014-05-25 18:32:35 +08:00
{
zend_module_entry * module = ( zend_module_entry * ) Z_PTR_P ( el ) ;
2010-07-06 19:40:17 +08:00
if ( module - > post_deactivate_func ) {
module - > post_deactivate_func ( ) ;
}
return 0 ;
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API void zend_post_deactivate_modules ( void ) /* { { { */
2010-07-06 19:40:17 +08:00
{
if ( EG ( full_tables_cleanup ) ) {
2014-12-14 06:06:14 +08:00
zend_hash_apply ( & module_registry , exec_done_cb ) ;
zend_hash_reverse_apply ( & module_registry , module_registry_unload_temp_wrapper ) ;
2010-07-06 19:40:17 +08:00
} else {
zend_module_entry * * p = module_post_deactivate_handlers ;
while ( * p ) {
zend_module_entry * module = * p ;
module - > post_deactivate_func ( ) ;
p + + ;
}
}
}
/* }}} */
1999-04-08 02:10:10 +08:00
/* return the next free module number */
2014-10-13 01:22:03 +08:00
ZEND_API int zend_next_free_module ( void ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2012-03-05 20:47:25 +08:00
return zend_hash_num_elements ( & module_registry ) + 1 ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-12-14 06:06:14 +08:00
static zend_class_entry * do_register_internal_class ( zend_class_entry * orig_class_entry , uint32_t ce_flags ) /* { { { */
2003-10-23 03:59:58 +08:00
{
zend_class_entry * class_entry = malloc ( sizeof ( zend_class_entry ) ) ;
2015-06-30 18:59:27 +08:00
zend_string * lowercase_name = zend_string_alloc ( ZSTR_LEN ( orig_class_entry - > name ) , 1 ) ;
2003-10-23 03:59:58 +08:00
* class_entry = * orig_class_entry ;
class_entry - > type = ZEND_INTERNAL_CLASS ;
2014-12-14 06:06:14 +08:00
zend_initialize_class_data ( class_entry , 0 ) ;
2014-06-17 03:32:58 +08:00
class_entry - > ce_flags = ce_flags | ZEND_ACC_CONSTANTS_UPDATED ;
2010-09-15 15:38:52 +08:00
class_entry - > info . internal . module = EG ( current_module ) ;
2003-10-23 03:59:58 +08:00
2010-09-15 15:38:52 +08:00
if ( class_entry - > info . internal . builtin_functions ) {
2014-12-14 06:06:14 +08:00
zend_register_functions ( class_entry , class_entry - > info . internal . builtin_functions , & class_entry - > function_table , MODULE_PERSISTENT ) ;
2003-10-23 03:59:58 +08:00
}
2015-06-30 18:59:27 +08:00
zend_str_tolower_copy ( ZSTR_VAL ( lowercase_name ) , ZSTR_VAL ( orig_class_entry - > name ) , ZSTR_LEN ( class_entry - > name ) ) ;
2014-12-14 06:06:14 +08:00
lowercase_name = zend_new_interned_string ( lowercase_name ) ;
2014-02-10 14:04:30 +08:00
zend_hash_update_ptr ( CG ( class_table ) , lowercase_name , class_entry ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( lowercase_name ) ;
2003-10-23 03:59:58 +08:00
return class_entry ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-10-23 03:59:58 +08:00
2000-06-09 22:40:14 +08:00
/* If parent_ce is not NULL then it inherits from parent_ce
* If parent_ce is NULL and parent_name isn ' t then it looks for the parent and inherits from it
* If both parent_ce and parent_name are NULL it does a regular class registration
* If parent_name is specified but not found NULL is returned
*/
2014-12-14 06:06:14 +08:00
ZEND_API zend_class_entry * zend_register_internal_class_ex ( zend_class_entry * class_entry , zend_class_entry * parent_ce ) /* { { { */
2000-06-09 22:40:14 +08:00
{
zend_class_entry * register_class ;
2014-12-14 06:06:14 +08:00
register_class = zend_register_internal_class ( class_entry ) ;
2000-06-09 22:40:14 +08:00
if ( parent_ce ) {
2014-12-14 06:06:14 +08:00
zend_do_inheritance ( register_class , parent_ce ) ;
2000-06-09 22:40:14 +08:00
}
return register_class ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-04-08 02:10:10 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API void zend_class_implements ( zend_class_entry * class_entry , int num_interfaces , . . . ) /* { { { */
2003-10-15 14:24:17 +08:00
{
zend_class_entry * interface_entry ;
va_list interface_list ;
2005-02-18 04:15:40 +08:00
va_start ( interface_list , num_interfaces ) ;
2003-10-15 14:24:17 +08:00
while ( num_interfaces - - ) {
interface_entry = va_arg ( interface_list , zend_class_entry * ) ;
2014-12-14 06:06:14 +08:00
zend_do_implement_interface ( class_entry , interface_entry ) ;
2003-10-15 14:24:17 +08:00
}
2007-11-03 03:40:39 +08:00
2003-10-15 14:24:17 +08:00
va_end ( interface_list ) ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-10-15 14:24:17 +08:00
2003-10-23 03:59:58 +08:00
/* A class that contains at least one abstract method automatically becomes an abstract class.
*/
2014-12-14 06:06:14 +08:00
ZEND_API zend_class_entry * zend_register_internal_class ( zend_class_entry * orig_class_entry ) /* { { { */
1999-04-08 02:10:10 +08:00
{
2014-12-14 06:06:14 +08:00
return do_register_internal_class ( orig_class_entry , 0 ) ;
2003-10-23 03:59:58 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2000-02-03 06:23:37 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API zend_class_entry * zend_register_internal_interface ( zend_class_entry * orig_class_entry ) /* { { { */
2003-10-23 03:59:58 +08:00
{
2014-12-14 06:06:14 +08:00
return do_register_internal_class ( orig_class_entry , ZEND_ACC_INTERFACE ) ;
1999-04-08 02:10:10 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
1999-05-09 20:24:21 +08:00
2017-10-27 19:44:21 +08:00
ZEND_API int zend_register_class_alias_ex ( const char * name , size_t name_len , zend_class_entry * ce , int persistent ) /* { { { */
2008-05-12 15:11:55 +08:00
{
2014-02-10 14:04:30 +08:00
zend_string * lcname ;
2008-05-12 15:11:55 +08:00
2014-02-10 14:04:30 +08:00
if ( name [ 0 ] = = ' \\ ' ) {
2017-10-27 19:44:21 +08:00
lcname = zend_string_alloc ( name_len - 1 , persistent ) ;
2015-06-30 18:59:27 +08:00
zend_str_tolower_copy ( ZSTR_VAL ( lcname ) , name + 1 , name_len - 1 ) ;
2013-08-29 15:16:56 +08:00
} else {
2017-10-27 19:44:21 +08:00
lcname = zend_string_alloc ( name_len , persistent ) ;
2015-06-30 18:59:27 +08:00
zend_str_tolower_copy ( ZSTR_VAL ( lcname ) , name , name_len ) ;
2013-08-29 15:16:56 +08:00
}
2015-01-06 11:03:05 +08:00
zend_assert_valid_class_name ( lcname ) ;
2014-02-21 22:19:46 +08:00
ce = zend_hash_add_ptr ( CG ( class_table ) , lcname , ce ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( lcname ) ;
2014-02-10 14:04:30 +08:00
if ( ce ) {
2008-05-12 15:11:55 +08:00
ce - > refcount + + ;
2014-02-10 14:04:30 +08:00
return SUCCESS ;
2008-05-12 15:11:55 +08:00
}
2014-02-10 14:04:30 +08:00
return FAILURE ;
2008-05-12 15:11:55 +08:00
}
/* }}} */
2008-08-13 01:20:25 +08:00
ZEND_API int zend_set_hash_symbol ( zval * symbol , const char * name , int name_length , zend_bool is_ref , int num_symbol_tables , . . . ) /* { { { */
1999-12-05 00:50:18 +08:00
{
2007-11-03 03:40:39 +08:00
HashTable * symbol_table ;
va_list symbol_table_list ;
1999-12-05 00:50:18 +08:00
2006-05-10 07:53:23 +08:00
if ( num_symbol_tables < = 0 ) return FAILURE ;
1999-12-05 00:50:18 +08:00
2014-06-05 20:04:11 +08:00
if ( is_ref ) {
ZVAL_MAKE_REF ( symbol ) ;
2014-02-10 14:04:30 +08:00
}
1999-12-05 00:50:18 +08:00
2006-05-10 07:53:23 +08:00
va_start ( symbol_table_list , num_symbol_tables ) ;
while ( num_symbol_tables - - > 0 ) {
symbol_table = va_arg ( symbol_table_list , HashTable * ) ;
2014-02-10 14:04:30 +08:00
zend_hash_str_update ( symbol_table , name , name_length , symbol ) ;
2014-03-28 18:46:25 +08:00
if ( Z_REFCOUNTED_P ( symbol ) ) {
Z_ADDREF_P ( symbol ) ;
}
2006-05-10 07:53:23 +08:00
}
va_end ( symbol_table_list ) ;
return SUCCESS ;
1999-12-05 00:50:18 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2000-05-30 01:16:52 +08:00
/* Disabled functions support */
2007-11-03 03:40:39 +08:00
/* {{{ proto void display_disabled_function(void)
Dummy function which displays an error when a disabled function is called . */
2002-09-16 09:36:48 +08:00
ZEND_API ZEND_FUNCTION ( display_disabled_function )
2000-05-30 01:16:52 +08:00
{
2014-12-14 06:06:14 +08:00
zend_error ( E_WARNING , " %s() has been disabled for security reasons " , get_active_function_name ( ) ) ;
2000-05-30 01:16:52 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2000-05-30 01:16:52 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_disable_function ( char * function_name , size_t function_name_length ) /* { { { */
2000-05-30 01:16:52 +08:00
{
2014-10-31 17:32:23 +08:00
zend_internal_function * func ;
2014-10-31 17:37:56 +08:00
if ( ( func = zend_hash_str_find_ptr ( CG ( function_table ) , function_name , function_name_length ) ) ) {
2014-12-24 20:34:52 +08:00
func - > fn_flags & = ~ ( ZEND_ACC_VARIADIC | ZEND_ACC_HAS_TYPE_HINTS ) ;
func - > num_args = 0 ;
2014-10-31 17:32:23 +08:00
func - > arg_info = NULL ;
func - > handler = ZEND_FN ( display_disabled_function ) ;
return SUCCESS ;
2000-05-30 01:16:52 +08:00
}
2014-10-31 17:32:23 +08:00
return FAILURE ;
2000-06-06 10:47:43 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2001-02-01 13:01:26 +08:00
2012-08-22 17:43:12 +08:00
# ifdef ZEND_WIN32
# pragma optimize("", off)
# endif
2014-12-14 06:06:14 +08:00
static zend_object * display_disabled_class ( zend_class_entry * class_type ) /* { { { */
2003-03-03 09:22:43 +08:00
{
zend_object * intern ;
2014-02-10 14:04:30 +08:00
2014-12-14 06:06:14 +08:00
intern = zend_objects_new ( class_type ) ;
2015-06-30 18:59:27 +08:00
zend_error ( E_WARNING , " %s() has been disabled for security reasons " , ZSTR_VAL ( class_type - > name ) ) ;
2014-02-10 14:04:30 +08:00
return intern ;
2003-03-03 09:22:43 +08:00
}
2012-08-22 17:43:12 +08:00
# ifdef ZEND_WIN32
# pragma optimize("", on)
# endif
2007-11-03 03:40:39 +08:00
/* }}} */
2003-03-03 09:22:43 +08:00
2007-11-03 03:40:39 +08:00
static const zend_function_entry disabled_class_new [ ] = {
2011-08-06 09:22:27 +08:00
ZEND_FE_END
2003-03-03 09:22:43 +08:00
} ;
2014-12-14 06:06:14 +08:00
ZEND_API int zend_disable_class ( char * class_name , size_t class_name_length ) /* { { { */
2003-03-03 09:22:43 +08:00
{
2014-02-10 14:04:30 +08:00
zend_class_entry * disabled_class ;
zend_string * key ;
2006-05-10 07:53:23 +08:00
2014-08-26 01:24:55 +08:00
key = zend_string_alloc ( class_name_length , 0 ) ;
2015-06-30 18:59:27 +08:00
zend_str_tolower_copy ( ZSTR_VAL ( key ) , class_name , class_name_length ) ;
2014-02-10 14:04:30 +08:00
disabled_class = zend_hash_find_ptr ( CG ( class_table ) , key ) ;
if ( ! disabled_class ) {
2003-03-03 09:22:43 +08:00
return FAILURE ;
}
2014-02-10 14:04:30 +08:00
INIT_CLASS_ENTRY_INIT_METHODS ( ( * disabled_class ) , disabled_class_new , NULL , NULL , NULL , NULL , NULL ) ;
disabled_class - > create_object = display_disabled_class ;
zend_hash_clean ( & disabled_class - > function_table ) ;
2006-12-21 07:01:31 +08:00
return SUCCESS ;
2003-03-03 09:22:43 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-03-03 09:22:43 +08:00
2016-04-28 09:13:34 +08:00
static int zend_is_callable_check_class ( zend_string * name , zend_class_entry * scope , zend_fcall_info_cache * fcc , int * strict_class , char * * error ) /* { { { */
2001-02-01 13:01:26 +08:00
{
2008-07-24 17:42:18 +08:00
int ret = 0 ;
2014-02-10 14:04:30 +08:00
zend_class_entry * ce ;
2015-06-30 18:59:27 +08:00
size_t name_len = ZSTR_LEN ( name ) ;
2014-02-10 14:04:30 +08:00
zend_string * lcname ;
2014-06-26 17:56:55 +08:00
ALLOCA_FLAG ( use_heap ) ;
2014-08-17 19:31:39 +08:00
2015-06-29 21:44:54 +08:00
ZSTR_ALLOCA_ALLOC ( lcname , name_len , use_heap ) ;
2015-06-30 18:59:27 +08:00
zend_str_tolower_copy ( ZSTR_VAL ( lcname ) , ZSTR_VAL ( name ) , name_len ) ;
2008-07-24 17:42:18 +08:00
2009-11-30 19:39:53 +08:00
* strict_class = 0 ;
2014-08-26 04:40:58 +08:00
if ( zend_string_equals_literal ( lcname , " self " ) ) {
2016-04-28 09:13:34 +08:00
if ( ! scope ) {
2008-07-24 17:42:18 +08:00
if ( error ) * error = estrdup ( " cannot access self:: when no class scope is active " ) ;
} else {
2015-04-23 17:16:37 +08:00
fcc - > called_scope = zend_get_called_scope ( EG ( current_execute_data ) ) ;
2016-04-28 09:13:34 +08:00
fcc - > calling_scope = scope ;
2015-04-23 17:16:37 +08:00
if ( ! fcc - > object ) {
fcc - > object = zend_get_this_object ( EG ( current_execute_data ) ) ;
2008-07-26 21:14:04 +08:00
}
2008-07-24 17:42:18 +08:00
ret = 1 ;
}
2014-08-26 04:40:58 +08:00
} else if ( zend_string_equals_literal ( lcname , " parent " ) ) {
2016-04-28 09:13:34 +08:00
if ( ! scope ) {
2008-07-24 17:42:18 +08:00
if ( error ) * error = estrdup ( " cannot access parent:: when no class scope is active " ) ;
2016-04-28 09:13:34 +08:00
} else if ( ! scope - > parent ) {
2008-07-24 17:42:18 +08:00
if ( error ) * error = estrdup ( " cannot access parent:: when current class scope has no parent " ) ;
} else {
2015-04-23 17:16:37 +08:00
fcc - > called_scope = zend_get_called_scope ( EG ( current_execute_data ) ) ;
2016-04-28 09:13:34 +08:00
fcc - > calling_scope = scope - > parent ;
2015-04-23 17:16:37 +08:00
if ( ! fcc - > object ) {
fcc - > object = zend_get_this_object ( EG ( current_execute_data ) ) ;
2008-07-26 21:14:04 +08:00
}
2009-11-30 19:39:53 +08:00
* strict_class = 1 ;
2008-07-24 17:42:18 +08:00
ret = 1 ;
}
2014-08-26 04:40:58 +08:00
} else if ( zend_string_equals_literal ( lcname , " static " ) ) {
2015-04-23 17:16:37 +08:00
zend_class_entry * called_scope = zend_get_called_scope ( EG ( current_execute_data ) ) ;
if ( ! called_scope ) {
2008-07-24 17:42:18 +08:00
if ( error ) * error = estrdup ( " cannot access static:: when no class scope is active " ) ;
} else {
2015-04-23 17:16:37 +08:00
fcc - > called_scope = called_scope ;
fcc - > calling_scope = called_scope ;
if ( ! fcc - > object ) {
fcc - > object = zend_get_this_object ( EG ( current_execute_data ) ) ;
2008-07-26 21:14:04 +08:00
}
2009-11-30 19:39:53 +08:00
* strict_class = 1 ;
2008-07-24 17:42:18 +08:00
ret = 1 ;
}
2014-12-14 06:06:14 +08:00
} else if ( ( ce = zend_lookup_class_ex ( name , NULL , 1 ) ) ! = NULL ) {
2014-07-03 02:03:21 +08:00
zend_class_entry * scope ;
zend_execute_data * ex = EG ( current_execute_data ) ;
2008-07-26 21:14:04 +08:00
2014-07-03 02:03:21 +08:00
while ( ex & & ( ! ex - > func | | ! ZEND_USER_CODE ( ex - > func - > type ) ) ) {
ex = ex - > prev_execute_data ;
}
scope = ex ? ex - > func - > common . scope : NULL ;
2014-02-10 14:04:30 +08:00
fcc - > calling_scope = ce ;
2015-04-23 17:16:37 +08:00
if ( scope & & ! fcc - > object ) {
zend_object * object = zend_get_this_object ( EG ( current_execute_data ) ) ;
if ( object & &
instanceof_function ( object - > ce , scope ) & &
instanceof_function ( scope , fcc - > calling_scope ) ) {
fcc - > object = object ;
fcc - > called_scope = object - > ce ;
} else {
fcc - > called_scope = fcc - > calling_scope ;
}
2008-07-26 21:14:04 +08:00
} else {
2014-10-09 20:17:30 +08:00
fcc - > called_scope = fcc - > object ? fcc - > object - > ce : fcc - > calling_scope ;
2008-07-26 21:14:04 +08:00
}
2009-11-30 19:39:53 +08:00
* strict_class = 1 ;
2008-07-24 17:42:18 +08:00
ret = 1 ;
} else {
2016-06-21 21:55:17 +08:00
if ( error ) zend_spprintf ( error , 0 , " class '%.*s' not found " , ( int ) name_len , ZSTR_VAL ( name ) ) ;
2008-07-24 17:42:18 +08:00
}
2015-06-29 21:44:54 +08:00
ZSTR_ALLOCA_FREE ( lcname , use_heap ) ;
2008-07-24 17:42:18 +08:00
return ret ;
}
/* }}} */
2014-12-14 06:06:14 +08:00
static int zend_is_callable_check_func ( int check_flags , zval * callable , zend_fcall_info_cache * fcc , int strict_class , char * * error ) /* { { { */
2008-07-24 17:42:18 +08:00
{
zend_class_entry * ce_org = fcc - > calling_scope ;
2008-07-26 21:14:04 +08:00
int retval = 0 ;
2014-02-22 03:51:08 +08:00
zend_string * mname , * cname ;
2014-02-10 14:04:30 +08:00
zend_string * lmname ;
2010-10-15 05:33:10 +08:00
const char * colon ;
2016-09-01 22:31:15 +08:00
size_t clen ;
2005-12-17 06:15:41 +08:00
HashTable * ftable ;
2008-07-24 17:42:18 +08:00
int call_via_handler = 0 ;
2016-04-28 09:13:34 +08:00
zend_class_entry * scope ;
2014-04-21 19:18:19 +08:00
ALLOCA_FLAG ( use_heap )
2006-05-10 07:53:23 +08:00
2008-02-03 06:29:41 +08:00
if ( error ) {
* error = NULL ;
}
2008-07-24 17:42:18 +08:00
fcc - > calling_scope = NULL ;
fcc - > function_handler = NULL ;
2005-12-17 06:15:41 +08:00
2007-09-29 03:52:53 +08:00
if ( ! ce_org ) {
2014-06-26 18:10:18 +08:00
zend_string * lmname ;
2014-04-21 19:18:19 +08:00
2008-11-04 23:58:55 +08:00
/* Skip leading \ */
2014-06-26 18:09:04 +08:00
if ( UNEXPECTED ( Z_STRVAL_P ( callable ) [ 0 ] = = ' \\ ' ) ) {
2015-06-29 21:44:54 +08:00
ZSTR_ALLOCA_INIT ( lmname , Z_STRVAL_P ( callable ) + 1 , Z_STRLEN_P ( callable ) - 1 , use_heap ) ;
2007-09-29 03:52:53 +08:00
} else {
2014-06-26 18:09:04 +08:00
lmname = Z_STR_P ( callable ) ;
2007-09-29 03:52:53 +08:00
}
/* Check if function with given name exists.
2007-11-03 03:40:39 +08:00
* This may be a compound name that includes namespace name */
2014-06-26 18:09:04 +08:00
if ( EXPECTED ( ( fcc - > function_handler = zend_hash_find_ptr ( EG ( function_table ) , lmname ) ) ! = NULL ) ) {
if ( lmname ! = Z_STR_P ( callable ) ) {
2015-06-29 21:44:54 +08:00
ZSTR_ALLOCA_FREE ( lmname , use_heap ) ;
2014-06-26 18:09:04 +08:00
}
2015-09-01 08:15:50 +08:00
fcc - > initialized = 1 ;
2007-09-29 03:52:53 +08:00
return 1 ;
2014-06-26 17:56:55 +08:00
} else {
2014-06-26 18:09:04 +08:00
if ( lmname = = Z_STR_P ( callable ) ) {
2015-06-29 21:44:54 +08:00
ZSTR_ALLOCA_INIT ( lmname , Z_STRVAL_P ( callable ) , Z_STRLEN_P ( callable ) , use_heap ) ;
2014-06-26 18:09:04 +08:00
} else {
2014-08-26 01:24:55 +08:00
zend_string_forget_hash_val ( lmname ) ;
2014-06-26 18:09:04 +08:00
}
2015-06-30 18:59:27 +08:00
zend_str_tolower ( ZSTR_VAL ( lmname ) , ZSTR_LEN ( lmname ) ) ;
2014-06-26 17:56:55 +08:00
if ( ( fcc - > function_handler = zend_hash_find_ptr ( EG ( function_table ) , lmname ) ) ! = NULL ) {
2015-06-29 21:44:54 +08:00
ZSTR_ALLOCA_FREE ( lmname , use_heap ) ;
2015-09-01 08:15:50 +08:00
fcc - > initialized = 1 ;
2014-06-26 17:56:55 +08:00
return 1 ;
}
2007-09-29 03:52:53 +08:00
}
2014-06-26 18:09:04 +08:00
if ( lmname ! = Z_STR_P ( callable ) ) {
2015-06-29 21:44:54 +08:00
ZSTR_ALLOCA_FREE ( lmname , use_heap ) ;
2007-09-29 03:52:53 +08:00
}
}
/* Split name into class/namespace and method/function names */
2014-08-26 01:24:55 +08:00
if ( ( colon = zend_memrchr ( Z_STRVAL_P ( callable ) , ' : ' , Z_STRLEN_P ( callable ) ) ) ! = NULL & &
2007-11-03 03:40:39 +08:00
colon > Z_STRVAL_P ( callable ) & &
* ( colon - 1 ) = = ' : '
) {
2016-09-01 22:31:15 +08:00
size_t mlen ;
2007-09-29 03:52:53 +08:00
colon - - ;
2005-12-17 06:15:41 +08:00
clen = colon - Z_STRVAL_P ( callable ) ;
2014-08-26 01:24:55 +08:00
mlen = Z_STRLEN_P ( callable ) - clen - 2 ;
2007-12-21 09:21:52 +08:00
2007-12-25 18:58:30 +08:00
if ( colon = = Z_STRVAL_P ( callable ) ) {
2008-02-02 05:27:55 +08:00
if ( error ) zend_spprintf ( error , 0 , " invalid function name " ) ;
2007-12-25 18:58:30 +08:00
return 0 ;
}
2007-09-29 03:52:53 +08:00
/* This is a compound name.
2007-11-03 03:40:39 +08:00
* Try to fetch class and then find static method . */
2008-02-07 04:40:19 +08:00
if ( ce_org ) {
2016-04-28 09:13:34 +08:00
scope = ce_org ;
} else {
scope = zend_get_executed_scope ( ) ;
2008-02-07 04:40:19 +08:00
}
2008-07-24 17:42:18 +08:00
2014-08-26 01:24:55 +08:00
cname = zend_string_init ( Z_STRVAL_P ( callable ) , clen , 0 ) ;
2016-04-28 09:13:34 +08:00
if ( ! zend_is_callable_check_class ( cname , scope , fcc , & strict_class , error ) ) {
2014-08-26 01:24:55 +08:00
zend_string_release ( cname ) ;
2005-12-17 06:15:41 +08:00
return 0 ;
}
2014-08-26 01:24:55 +08:00
zend_string_release ( cname ) ;
2008-07-24 17:42:18 +08:00
ftable = & fcc - > calling_scope - > function_table ;
2014-12-14 06:06:14 +08:00
if ( ce_org & & ! instanceof_function ( ce_org , fcc - > calling_scope ) ) {
2015-06-30 18:59:27 +08:00
if ( error ) zend_spprintf ( error , 0 , " class '%s' is not a subclass of '%s' " , ZSTR_VAL ( ce_org - > name ) , ZSTR_VAL ( fcc - > calling_scope - > name ) ) ;
2005-12-17 06:15:41 +08:00
return 0 ;
}
2014-08-26 01:24:55 +08:00
mname = zend_string_init ( Z_STRVAL_P ( callable ) + clen + 2 , mlen , 0 ) ;
2007-09-29 03:52:53 +08:00
} else if ( ce_org ) {
/* Try to fetch find static method of given class. */
2014-02-10 14:04:30 +08:00
mname = Z_STR_P ( callable ) ;
2014-08-26 01:24:55 +08:00
zend_string_addref ( mname ) ;
2007-09-29 03:52:53 +08:00
ftable = & ce_org - > function_table ;
2008-07-24 17:42:18 +08:00
fcc - > calling_scope = ce_org ;
2007-09-29 03:52:53 +08:00
} else {
/* We already checked for plain function before. */
2008-07-26 21:14:04 +08:00
if ( error & & ! ( check_flags & IS_CALLABLE_CHECK_SILENT ) ) {
zend_spprintf ( error , 0 , " function '%s' not found or invalid function name " , Z_STRVAL_P ( callable ) ) ;
}
2007-09-29 03:52:53 +08:00
return 0 ;
2005-12-17 06:15:41 +08:00
}
2014-12-24 20:04:51 +08:00
lmname = zend_string_tolower ( mname ) ;
2009-11-30 19:39:53 +08:00
if ( strict_class & &
fcc - > calling_scope & &
2014-08-26 04:40:58 +08:00
zend_string_equals_literal ( lmname , ZEND_CONSTRUCTOR_FUNC_NAME ) ) {
2009-11-30 19:39:53 +08:00
fcc - > function_handler = fcc - > calling_scope - > constructor ;
if ( fcc - > function_handler ) {
retval = 1 ;
}
2014-02-10 14:04:30 +08:00
} else if ( ( fcc - > function_handler = zend_hash_find_ptr ( ftable , lmname ) ) ! = NULL ) {
2008-07-26 21:14:04 +08:00
retval = 1 ;
2008-10-10 23:19:35 +08:00
if ( ( fcc - > function_handler - > op_array . fn_flags & ZEND_ACC_CHANGED ) & &
2016-04-28 09:13:34 +08:00
! strict_class ) {
scope = zend_get_executed_scope ( ) ;
if ( scope & &
instanceof_function ( fcc - > function_handler - > common . scope , scope ) ) {
zend_function * priv_fbc ;
if ( ( priv_fbc = zend_hash_find_ptr ( & scope - > function_table , lmname ) ) ! = NULL
& & priv_fbc - > common . fn_flags & ZEND_ACC_PRIVATE
& & priv_fbc - > common . scope = = scope ) {
fcc - > function_handler = priv_fbc ;
}
2008-10-10 23:19:35 +08:00
}
}
2009-01-14 19:56:08 +08:00
if ( ( check_flags & IS_CALLABLE_CHECK_NO_ACCESS ) = = 0 & &
( fcc - > calling_scope & &
2014-03-28 06:11:22 +08:00
( ( fcc - > object & & fcc - > calling_scope - > __call ) | |
( ! fcc - > object & & fcc - > calling_scope - > __callstatic ) ) ) ) {
2009-01-14 19:56:08 +08:00
if ( fcc - > function_handler - > op_array . fn_flags & ZEND_ACC_PRIVATE ) {
2016-04-28 09:13:34 +08:00
scope = zend_get_executed_scope ( ) ;
if ( ! zend_check_private ( fcc - > function_handler , fcc - > object ? fcc - > object - > ce : scope , lmname ) ) {
2009-01-14 19:56:08 +08:00
retval = 0 ;
fcc - > function_handler = NULL ;
goto get_function_via_handler ;
}
} else if ( fcc - > function_handler - > common . fn_flags & ZEND_ACC_PROTECTED ) {
2016-04-28 09:13:34 +08:00
scope = zend_get_executed_scope ( ) ;
if ( ! zend_check_protected ( fcc - > function_handler - > common . scope , scope ) ) {
2009-01-14 19:56:08 +08:00
retval = 0 ;
fcc - > function_handler = NULL ;
goto get_function_via_handler ;
}
}
}
} else {
get_function_via_handler :
2014-03-28 06:11:22 +08:00
if ( fcc - > object & & fcc - > calling_scope = = ce_org ) {
2009-11-30 19:39:53 +08:00
if ( strict_class & & ce_org - > __call ) {
2015-04-11 04:01:00 +08:00
fcc - > function_handler = zend_get_call_trampoline_func ( ce_org , mname , 0 ) ;
2009-11-30 19:39:53 +08:00
call_via_handler = 1 ;
retval = 1 ;
2014-03-28 06:11:22 +08:00
} else if ( fcc - > object - > handlers - > get_method ) {
2014-12-14 06:06:14 +08:00
fcc - > function_handler = fcc - > object - > handlers - > get_method ( & fcc - > object , mname , NULL ) ;
2009-01-14 19:56:08 +08:00
if ( fcc - > function_handler ) {
2009-11-30 19:39:53 +08:00
if ( strict_class & &
( ! fcc - > function_handler - > common . scope | |
2014-12-14 06:06:14 +08:00
! instanceof_function ( ce_org , fcc - > function_handler - > common . scope ) ) ) {
2015-04-11 04:01:00 +08:00
if ( fcc - > function_handler - > common . fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE ) {
2017-09-18 16:19:47 +08:00
if ( fcc - > function_handler - > type ! = ZEND_OVERLOADED_FUNCTION & &
fcc - > function_handler - > common . function_name ) {
2014-08-26 01:24:55 +08:00
zend_string_release ( fcc - > function_handler - > common . function_name ) ;
2009-11-30 19:39:53 +08:00
}
2015-04-11 04:01:00 +08:00
zend_free_trampoline ( fcc - > function_handler ) ;
2009-11-30 19:39:53 +08:00
}
} else {
retval = 1 ;
2015-04-11 04:01:00 +08:00
call_via_handler = ( fcc - > function_handler - > common . fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE ) ! = 0 ;
2009-11-30 19:39:53 +08:00
}
2009-01-14 19:56:08 +08:00
}
}
} else if ( fcc - > calling_scope ) {
if ( fcc - > calling_scope - > get_static_method ) {
2014-12-14 06:06:14 +08:00
fcc - > function_handler = fcc - > calling_scope - > get_static_method ( fcc - > calling_scope , mname ) ;
2009-01-14 19:56:08 +08:00
} else {
2014-12-14 06:06:14 +08:00
fcc - > function_handler = zend_std_get_static_method ( fcc - > calling_scope , mname , NULL ) ;
2009-01-14 19:56:08 +08:00
}
if ( fcc - > function_handler ) {
retval = 1 ;
2015-04-11 04:01:00 +08:00
call_via_handler = ( fcc - > function_handler - > common . fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE ) ! = 0 ;
2015-04-23 17:16:37 +08:00
if ( call_via_handler & & ! fcc - > object ) {
zend_object * object = zend_get_this_object ( EG ( current_execute_data ) ) ;
if ( object & &
instanceof_function ( object - > ce , fcc - > calling_scope ) ) {
fcc - > object = object ;
}
2011-05-31 19:36:57 +08:00
}
2009-01-14 19:56:08 +08:00
}
2005-12-17 06:15:41 +08:00
}
2008-07-26 21:14:04 +08:00
}
if ( retval ) {
if ( fcc - > calling_scope & & ! call_via_handler ) {
2016-07-15 03:38:10 +08:00
if ( fcc - > function_handler - > common . fn_flags & ZEND_ACC_ABSTRACT ) {
2012-09-21 17:07:14 +08:00
if ( error ) {
2015-06-30 18:59:27 +08:00
zend_spprintf ( error , 0 , " cannot call abstract method %s::%s() " , ZSTR_VAL ( fcc - > calling_scope - > name ) , ZSTR_VAL ( fcc - > function_handler - > common . function_name ) ) ;
2012-09-21 17:07:14 +08:00
retval = 0 ;
} else {
2015-07-08 01:10:22 +08:00
zend_throw_error ( NULL , " Cannot call abstract method %s::%s() " , ZSTR_VAL ( fcc - > calling_scope - > name ) , ZSTR_VAL ( fcc - > function_handler - > common . function_name ) ) ;
2016-07-14 23:36:56 +08:00
retval = 0 ;
2012-09-21 17:07:14 +08:00
}
2014-03-28 06:11:22 +08:00
} else if ( ! fcc - > object & & ! ( fcc - > function_handler - > common . fn_flags & ZEND_ACC_STATIC ) ) {
2008-02-02 21:56:59 +08:00
int severity ;
char * verb ;
2008-07-24 17:42:18 +08:00
if ( fcc - > function_handler - > common . fn_flags & ZEND_ACC_ALLOW_STATIC ) {
2015-03-15 16:47:25 +08:00
severity = E_DEPRECATED ;
2008-02-02 21:56:59 +08:00
verb = " should not " ;
} else {
2008-02-02 23:48:04 +08:00
/* An internal function assumes $this is present and won't check that. So PHP would crash by allowing the call. */
2015-07-04 05:04:33 +08:00
severity = E_ERROR ;
2008-02-02 21:56:59 +08:00
verb = " cannot " ;
}
2005-12-17 06:15:41 +08:00
if ( ( check_flags & IS_CALLABLE_CHECK_IS_STATIC ) ! = 0 ) {
retval = 0 ;
2008-02-02 05:27:55 +08:00
}
2015-04-01 17:42:05 +08:00
if ( error ) {
2015-06-30 18:59:27 +08:00
zend_spprintf ( error , 0 , " non-static method %s::%s() %s be called statically " , ZSTR_VAL ( fcc - > calling_scope - > name ) , ZSTR_VAL ( fcc - > function_handler - > common . function_name ) , verb ) ;
2015-04-02 19:19:52 +08:00
if ( severity ! = E_DEPRECATED ) {
2015-04-01 17:42:05 +08:00
retval = 0 ;
2006-01-14 23:22:40 +08:00
}
2015-04-01 17:42:05 +08:00
} else if ( retval ) {
2015-07-04 05:04:33 +08:00
if ( severity = = E_ERROR ) {
2015-07-08 01:10:22 +08:00
zend_throw_error ( NULL , " Non-static method %s::%s() %s be called statically " , ZSTR_VAL ( fcc - > calling_scope - > name ) , ZSTR_VAL ( fcc - > function_handler - > common . function_name ) , verb ) ;
2015-07-04 05:04:33 +08:00
} else {
zend_error ( severity , " Non-static method %s::%s() %s be called statically " , ZSTR_VAL ( fcc - > calling_scope - > name ) , ZSTR_VAL ( fcc - > function_handler - > common . function_name ) , verb ) ;
}
2005-12-17 06:15:41 +08:00
}
}
if ( retval & & ( check_flags & IS_CALLABLE_CHECK_NO_ACCESS ) = = 0 ) {
2008-07-24 17:42:18 +08:00
if ( fcc - > function_handler - > op_array . fn_flags & ZEND_ACC_PRIVATE ) {
2016-04-28 09:13:34 +08:00
scope = zend_get_executed_scope ( ) ;
if ( ! zend_check_private ( fcc - > function_handler , fcc - > object ? fcc - > object - > ce : scope , lmname ) ) {
2008-02-03 06:29:41 +08:00
if ( error ) {
if ( * error ) {
efree ( * error ) ;
}
2015-06-30 18:59:27 +08:00
zend_spprintf ( error , 0 , " cannot access private method %s::%s() " , ZSTR_VAL ( fcc - > calling_scope - > name ) , ZSTR_VAL ( fcc - > function_handler - > common . function_name ) ) ;
2008-02-03 06:29:41 +08:00
}
2005-12-17 06:15:41 +08:00
retval = 0 ;
}
2008-07-24 17:42:18 +08:00
} else if ( ( fcc - > function_handler - > common . fn_flags & ZEND_ACC_PROTECTED ) ) {
2016-04-28 09:13:34 +08:00
scope = zend_get_executed_scope ( ) ;
if ( ! zend_check_protected ( fcc - > function_handler - > common . scope , scope ) ) {
2008-02-03 06:29:41 +08:00
if ( error ) {
if ( * error ) {
efree ( * error ) ;
}
2015-06-30 18:59:27 +08:00
zend_spprintf ( error , 0 , " cannot access protected method %s::%s() " , ZSTR_VAL ( fcc - > calling_scope - > name ) , ZSTR_VAL ( fcc - > function_handler - > common . function_name ) ) ;
2008-02-03 06:29:41 +08:00
}
2005-12-17 06:15:41 +08:00
retval = 0 ;
}
}
}
}
2008-07-26 21:14:04 +08:00
} else if ( error & & ! ( check_flags & IS_CALLABLE_CHECK_SILENT ) ) {
if ( fcc - > calling_scope ) {
2015-06-30 18:59:27 +08:00
if ( error ) zend_spprintf ( error , 0 , " class '%s' does not have a method '%s' " , ZSTR_VAL ( fcc - > calling_scope - > name ) , ZSTR_VAL ( mname ) ) ;
2008-07-26 21:14:04 +08:00
} else {
2015-06-30 18:59:27 +08:00
if ( error ) zend_spprintf ( error , 0 , " function '%s' does not exist " , ZSTR_VAL ( mname ) ) ;
2008-07-26 21:14:04 +08:00
}
2005-12-17 06:15:41 +08:00
}
2014-12-24 20:04:51 +08:00
zend_string_release ( lmname ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( mname ) ;
2008-08-07 20:04:14 +08:00
2014-03-28 06:11:22 +08:00
if ( fcc - > object ) {
2014-10-09 20:17:30 +08:00
fcc - > called_scope = fcc - > object - > ce ;
2008-07-24 17:42:18 +08:00
}
2008-07-26 21:14:04 +08:00
if ( retval ) {
2008-07-24 17:42:18 +08:00
fcc - > initialized = 1 ;
}
2005-12-17 06:15:41 +08:00
return retval ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-12-17 06:15:41 +08:00
2017-06-25 23:55:56 +08:00
static zend_string * zend_create_method_string ( zend_string * class_name , zend_string * method_name ) {
zend_string * callable_name = zend_string_alloc (
ZSTR_LEN ( class_name ) + ZSTR_LEN ( method_name ) + sizeof ( " :: " ) - 1 , 0 ) ;
char * ptr = ZSTR_VAL ( callable_name ) ;
memcpy ( ptr , ZSTR_VAL ( class_name ) , ZSTR_LEN ( class_name ) ) ;
ptr + = ZSTR_LEN ( class_name ) ;
memcpy ( ptr , " :: " , sizeof ( " :: " ) - 1 ) ;
ptr + = sizeof ( " :: " ) - 1 ;
memcpy ( ptr , ZSTR_VAL ( method_name ) , ZSTR_LEN ( method_name ) + 1 ) ;
return callable_name ;
}
ZEND_API zend_string * zend_get_callable_name_ex ( zval * callable , zend_object * object ) /* { { { */
{
try_again :
switch ( Z_TYPE_P ( callable ) ) {
case IS_STRING :
if ( object ) {
return zend_create_method_string ( object - > ce - > name , Z_STR_P ( callable ) ) ;
}
return zend_string_copy ( Z_STR_P ( callable ) ) ;
case IS_ARRAY :
{
zval * method = NULL ;
zval * obj = NULL ;
if ( zend_hash_num_elements ( Z_ARRVAL_P ( callable ) ) = = 2 ) {
obj = zend_hash_index_find_deref ( Z_ARRVAL_P ( callable ) , 0 ) ;
method = zend_hash_index_find_deref ( Z_ARRVAL_P ( callable ) , 1 ) ;
}
if ( obj = = NULL | | method = = NULL | | Z_TYPE_P ( method ) ! = IS_STRING ) {
return zend_string_init ( " Array " , sizeof ( " Array " ) - 1 , 0 ) ;
}
if ( Z_TYPE_P ( obj ) = = IS_STRING ) {
return zend_create_method_string ( Z_STR_P ( obj ) , Z_STR_P ( method ) ) ;
} else if ( Z_TYPE_P ( obj ) = = IS_OBJECT ) {
return zend_create_method_string ( Z_OBJCE_P ( obj ) - > name , Z_STR_P ( method ) ) ;
} else {
return zend_string_init ( " Array " , sizeof ( " Array " ) - 1 , 0 ) ;
}
}
case IS_OBJECT :
{
zend_class_entry * calling_scope ;
zend_function * fptr ;
zend_object * object ;
if ( Z_OBJ_HANDLER_P ( callable , get_closure )
& & Z_OBJ_HANDLER_P ( callable , get_closure ) ( callable , & calling_scope , & fptr , & object ) = = SUCCESS ) {
zend_class_entry * ce = Z_OBJCE_P ( callable ) ;
zend_string * callable_name = zend_string_alloc (
ZSTR_LEN ( ce - > name ) + sizeof ( " ::__invoke " ) - 1 , 0 ) ;
memcpy ( ZSTR_VAL ( callable_name ) , ZSTR_VAL ( ce - > name ) , ZSTR_LEN ( ce - > name ) ) ;
memcpy ( ZSTR_VAL ( callable_name ) + ZSTR_LEN ( ce - > name ) , " ::__invoke " , sizeof ( " ::__invoke " ) ) ;
return callable_name ;
}
return zval_get_string ( callable ) ;
}
case IS_REFERENCE :
callable = Z_REFVAL_P ( callable ) ;
goto try_again ;
default :
return zval_get_string ( callable ) ;
}
}
/* }}} */
ZEND_API zend_string * zend_get_callable_name ( zval * callable ) /* { { { */
{
return zend_get_callable_name_ex ( callable , NULL ) ;
}
/* }}} */
static zend_bool zend_is_callable_impl ( zval * callable , zend_object * object , uint32_t check_flags , zend_fcall_info_cache * fcc , char * * error ) /* { { { */
2005-12-17 06:15:41 +08:00
{
2008-07-26 21:14:04 +08:00
zend_bool ret ;
2008-07-24 17:42:18 +08:00
zend_fcall_info_cache fcc_local ;
2005-07-29 04:55:50 +08:00
2008-07-24 17:42:18 +08:00
if ( fcc = = NULL ) {
fcc = & fcc_local ;
2005-07-29 04:55:50 +08:00
}
2008-02-02 05:27:55 +08:00
if ( error ) {
* error = NULL ;
}
2015-01-03 17:22:58 +08:00
2008-07-24 17:42:18 +08:00
fcc - > initialized = 0 ;
fcc - > calling_scope = NULL ;
fcc - > called_scope = NULL ;
fcc - > function_handler = NULL ;
2014-03-28 06:11:22 +08:00
fcc - > object = NULL ;
2001-02-01 13:01:26 +08:00
2015-03-03 17:34:45 +08:00
again :
2001-03-12 11:08:28 +08:00
switch ( Z_TYPE_P ( callable ) ) {
2001-02-01 13:01:26 +08:00
case IS_STRING :
2014-03-28 06:11:22 +08:00
if ( object ) {
fcc - > object = object ;
2014-10-09 20:17:30 +08:00
fcc - > calling_scope = object - > ce ;
2003-12-29 00:20:06 +08:00
}
2017-06-25 23:55:56 +08:00
2005-04-27 23:45:36 +08:00
if ( check_flags & IS_CALLABLE_CHECK_SYNTAX_ONLY ) {
2008-07-26 21:14:04 +08:00
fcc - > called_scope = fcc - > calling_scope ;
2001-03-12 11:08:28 +08:00
return 1 ;
2003-12-29 00:20:06 +08:00
}
2007-11-03 03:40:39 +08:00
2014-12-14 06:06:14 +08:00
ret = zend_is_callable_check_func ( check_flags , callable , fcc , 0 , error ) ;
2008-07-26 21:14:04 +08:00
if ( fcc = = & fcc_local & &
fcc - > function_handler & &
2015-04-11 04:01:00 +08:00
( ( fcc - > function_handler - > common . fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE ) | |
2008-07-26 21:14:04 +08:00
fcc - > function_handler - > type = = ZEND_OVERLOADED_FUNCTION_TEMPORARY | |
fcc - > function_handler - > type = = ZEND_OVERLOADED_FUNCTION ) ) {
2017-09-18 16:19:47 +08:00
if ( fcc - > function_handler - > type ! = ZEND_OVERLOADED_FUNCTION & &
fcc - > function_handler - > common . function_name ) {
2014-08-26 01:24:55 +08:00
zend_string_release ( fcc - > function_handler - > common . function_name ) ;
2008-07-26 21:14:04 +08:00
}
2015-04-11 04:01:00 +08:00
zend_free_trampoline ( fcc - > function_handler ) ;
2008-07-26 21:14:04 +08:00
}
return ret ;
2001-02-01 13:01:26 +08:00
case IS_ARRAY :
{
2014-02-10 14:04:30 +08:00
zval * method = NULL ;
zval * obj = NULL ;
2009-11-30 19:39:53 +08:00
int strict_class = 0 ;
2006-05-10 07:53:23 +08:00
2008-02-02 05:27:55 +08:00
if ( zend_hash_num_elements ( Z_ARRVAL_P ( callable ) ) = = 2 ) {
2014-02-10 14:04:30 +08:00
obj = zend_hash_index_find ( Z_ARRVAL_P ( callable ) , 0 ) ;
method = zend_hash_index_find ( Z_ARRVAL_P ( callable ) , 1 ) ;
2008-02-02 05:27:55 +08:00
}
2001-03-12 11:08:28 +08:00
2014-03-07 17:08:14 +08:00
do {
if ( obj = = NULL | | method = = NULL ) {
break ;
2014-03-05 17:29:29 +08:00
}
2014-03-07 17:08:14 +08:00
2014-03-27 17:39:09 +08:00
ZVAL_DEREF ( method ) ;
2014-03-07 17:08:14 +08:00
if ( Z_TYPE_P ( method ) ! = IS_STRING ) {
break ;
}
2014-03-27 17:39:09 +08:00
ZVAL_DEREF ( obj ) ;
2014-02-10 14:04:30 +08:00
if ( Z_TYPE_P ( obj ) = = IS_STRING ) {
2005-10-26 07:19:59 +08:00
if ( check_flags & IS_CALLABLE_CHECK_SYNTAX_ONLY ) {
2001-05-10 04:07:49 +08:00
return 1 ;
2005-10-26 07:19:59 +08:00
}
2001-05-10 04:07:49 +08:00
2016-04-28 09:13:34 +08:00
if ( ! zend_is_callable_check_class ( Z_STR_P ( obj ) , zend_get_executed_scope ( ) , fcc , & strict_class , error ) ) {
2008-07-24 17:42:18 +08:00
return 0 ;
2002-03-12 18:08:47 +08:00
}
2008-07-24 17:42:18 +08:00
2014-03-07 17:08:14 +08:00
} else if ( Z_TYPE_P ( obj ) = = IS_OBJECT ) {
2008-07-27 02:32:20 +08:00
2014-02-10 14:04:30 +08:00
fcc - > calling_scope = Z_OBJCE_P ( obj ) ; /* TBFixed: what if it's overloaded? */
2006-05-10 07:53:23 +08:00
2014-03-28 06:11:22 +08:00
fcc - > object = Z_OBJ_P ( obj ) ;
2001-05-10 04:07:49 +08:00
2005-10-26 07:19:59 +08:00
if ( check_flags & IS_CALLABLE_CHECK_SYNTAX_ONLY ) {
2008-07-24 17:42:18 +08:00
fcc - > called_scope = fcc - > calling_scope ;
2001-05-10 04:07:49 +08:00
return 1 ;
2005-10-26 07:19:59 +08:00
}
2014-03-07 17:08:14 +08:00
} else {
break ;
2001-03-13 00:27:26 +08:00
}
2001-05-10 04:07:49 +08:00
2014-12-14 06:06:14 +08:00
ret = zend_is_callable_check_func ( check_flags , method , fcc , strict_class , error ) ;
2008-07-26 21:14:04 +08:00
if ( fcc = = & fcc_local & &
fcc - > function_handler & &
2015-04-11 04:01:00 +08:00
( ( fcc - > function_handler - > common . fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE ) | |
2008-07-26 21:14:04 +08:00
fcc - > function_handler - > type = = ZEND_OVERLOADED_FUNCTION_TEMPORARY | |
fcc - > function_handler - > type = = ZEND_OVERLOADED_FUNCTION ) ) {
2017-09-18 16:19:47 +08:00
if ( fcc - > function_handler - > type ! = ZEND_OVERLOADED_FUNCTION & &
fcc - > function_handler - > common . function_name ) {
2014-08-26 01:24:55 +08:00
zend_string_release ( fcc - > function_handler - > common . function_name ) ;
2008-07-26 21:14:04 +08:00
}
2015-04-11 04:01:00 +08:00
zend_free_trampoline ( fcc - > function_handler ) ;
2008-07-26 21:14:04 +08:00
}
return ret ;
2014-03-07 17:08:14 +08:00
} while ( 0 ) ;
if ( zend_hash_num_elements ( Z_ARRVAL_P ( callable ) ) = = 2 ) {
if ( ! obj | | ( ! Z_ISREF_P ( obj ) ?
( Z_TYPE_P ( obj ) ! = IS_STRING & & Z_TYPE_P ( obj ) ! = IS_OBJECT ) :
( Z_TYPE_P ( Z_REFVAL_P ( obj ) ) ! = IS_STRING & & Z_TYPE_P ( Z_REFVAL_P ( obj ) ) ! = IS_OBJECT ) ) ) {
if ( error ) zend_spprintf ( error , 0 , " first array member is not a valid class name or object " ) ;
2008-02-02 05:27:55 +08:00
} else {
2014-03-07 17:08:14 +08:00
if ( error ) zend_spprintf ( error , 0 , " second array member is not a valid method " ) ;
2001-03-12 11:08:28 +08:00
}
2014-03-07 17:08:14 +08:00
} else {
if ( error ) zend_spprintf ( error , 0 , " array must have exactly two members " ) ;
}
2001-02-01 13:01:26 +08:00
}
2007-11-03 03:40:39 +08:00
return 0 ;
2008-07-14 17:49:03 +08:00
case IS_OBJECT :
2014-12-14 06:06:14 +08:00
if ( Z_OBJ_HANDLER_P ( callable , get_closure ) & & Z_OBJ_HANDLER_P ( callable , get_closure ) ( callable , & fcc - > calling_scope , & fcc - > function_handler , & fcc - > object ) = = SUCCESS ) {
2008-07-24 17:42:18 +08:00
fcc - > called_scope = fcc - > calling_scope ;
2016-05-03 08:07:06 +08:00
fcc - > initialized = 1 ;
2008-07-14 17:49:03 +08:00
return 1 ;
}
2015-03-03 17:34:45 +08:00
if ( error ) zend_spprintf ( error , 0 , " no array or string given " ) ;
return 0 ;
case IS_REFERENCE :
callable = Z_REFVAL_P ( callable ) ;
goto again ;
2001-02-01 13:01:26 +08:00
default :
2008-02-02 05:27:55 +08:00
if ( error ) zend_spprintf ( error , 0 , " no array or string given " ) ;
2007-11-03 03:40:39 +08:00
return 0 ;
2001-02-01 13:01:26 +08:00
}
}
2007-11-03 03:40:39 +08:00
/* }}} */
2001-10-13 02:40:30 +08:00
2017-06-25 23:55:56 +08:00
ZEND_API zend_bool zend_is_callable_ex ( zval * callable , zend_object * object , uint32_t check_flags , zend_string * * callable_name , zend_fcall_info_cache * fcc , char * * error ) /* { { { */
{
zend_bool ret = zend_is_callable_impl ( callable , object , check_flags , fcc , error ) ;
if ( callable_name ) {
* callable_name = zend_get_callable_name_ex ( callable , object ) ;
}
return ret ;
}
2016-11-26 22:18:42 +08:00
ZEND_API zend_bool zend_is_callable ( zval * callable , uint32_t check_flags , zend_string * * callable_name ) /* { { { */
2005-07-29 04:55:50 +08:00
{
2014-12-14 06:06:14 +08:00
return zend_is_callable_ex ( callable , NULL , check_flags , callable_name , NULL , NULL ) ;
2005-07-29 04:55:50 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-07-29 04:55:50 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API zend_bool zend_make_callable ( zval * callable , zend_string * * callable_name ) /* { { { */
2003-10-26 06:58:06 +08:00
{
2008-07-24 17:42:18 +08:00
zend_fcall_info_cache fcc ;
2005-11-04 07:45:18 +08:00
2014-12-14 06:06:14 +08:00
if ( zend_is_callable_ex ( callable , NULL , IS_CALLABLE_STRICT , callable_name , & fcc , NULL ) ) {
2008-07-24 17:42:18 +08:00
if ( Z_TYPE_P ( callable ) = = IS_STRING & & fcc . calling_scope ) {
2016-05-06 14:23:37 +08:00
zval_dtor ( callable ) ;
2005-11-04 07:45:18 +08:00
array_init ( callable ) ;
2014-08-26 01:24:55 +08:00
add_next_index_str ( callable , zend_string_copy ( fcc . calling_scope - > name ) ) ;
add_next_index_str ( callable , zend_string_copy ( fcc . function_handler - > common . function_name ) ) ;
2005-11-04 07:45:18 +08:00
}
2008-07-26 21:14:04 +08:00
if ( fcc . function_handler & &
2015-04-11 04:01:00 +08:00
( ( fcc . function_handler - > common . fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE ) | |
2008-07-26 21:14:04 +08:00
fcc . function_handler - > type = = ZEND_OVERLOADED_FUNCTION_TEMPORARY | |
fcc . function_handler - > type = = ZEND_OVERLOADED_FUNCTION ) ) {
if ( fcc . function_handler - > type ! = ZEND_OVERLOADED_FUNCTION ) {
2014-08-26 01:24:55 +08:00
zend_string_release ( fcc . function_handler - > common . function_name ) ;
2008-07-26 21:14:04 +08:00
}
2015-04-11 04:01:00 +08:00
zend_free_trampoline ( fcc . function_handler ) ;
2008-07-26 21:14:04 +08:00
}
2003-10-26 06:58:06 +08:00
return 1 ;
}
2005-11-04 07:45:18 +08:00
return 0 ;
2003-10-26 06:58:06 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-10-26 06:58:06 +08:00
2016-11-26 22:18:42 +08:00
ZEND_API int zend_fcall_info_init ( zval * callable , uint32_t check_flags , zend_fcall_info * fci , zend_fcall_info_cache * fcc , zend_string * * callable_name , char * * error ) /* { { { */
2006-06-07 17:43:54 +08:00
{
2014-12-14 06:06:14 +08:00
if ( ! zend_is_callable_ex ( callable , NULL , check_flags , callable_name , fcc , error ) ) {
2006-06-07 17:43:54 +08:00
return FAILURE ;
}
fci - > size = sizeof ( * fci ) ;
2014-03-28 06:11:22 +08:00
fci - > object = fcc - > object ;
2014-02-10 14:04:30 +08:00
ZVAL_COPY_VALUE ( & fci - > function_name , callable ) ;
fci - > retval = NULL ;
2006-06-07 17:43:54 +08:00
fci - > param_count = 0 ;
fci - > params = NULL ;
fci - > no_separation = 1 ;
return SUCCESS ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2006-06-07 17:43:54 +08:00
2007-11-03 03:40:39 +08:00
ZEND_API void zend_fcall_info_args_clear ( zend_fcall_info * fci , int free_mem ) /* { { { */
2006-06-07 17:43:54 +08:00
{
if ( fci - > params ) {
2015-04-29 00:11:45 +08:00
zval * p = fci - > params ;
zval * end = p + fci - > param_count ;
2014-03-12 02:33:28 +08:00
2015-04-29 00:11:45 +08:00
while ( p ! = end ) {
i_zval_ptr_dtor ( p ZEND_FILE_LINE_CC ) ;
p + + ;
2014-03-12 02:33:28 +08:00
}
2007-04-06 03:49:42 +08:00
if ( free_mem ) {
efree ( fci - > params ) ;
fci - > params = NULL ;
}
2006-06-07 17:43:54 +08:00
}
fci - > param_count = 0 ;
2007-04-06 03:49:42 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2007-04-06 03:49:42 +08:00
2014-02-10 14:04:30 +08:00
ZEND_API void zend_fcall_info_args_save ( zend_fcall_info * fci , int * param_count , zval * * params ) /* { { { */
2007-04-06 03:49:42 +08:00
{
* param_count = fci - > param_count ;
* params = fci - > params ;
fci - > param_count = 0 ;
fci - > params = NULL ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2007-04-06 03:49:42 +08:00
2014-02-10 14:04:30 +08:00
ZEND_API void zend_fcall_info_args_restore ( zend_fcall_info * fci , int param_count , zval * params ) /* { { { */
2007-04-06 03:49:42 +08:00
{
zend_fcall_info_args_clear ( fci , 1 ) ;
fci - > param_count = param_count ;
fci - > params = params ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2007-04-06 03:49:42 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_fcall_info_args_ex ( zend_fcall_info * fci , zend_function * func , zval * args ) /* { { { */
2007-04-06 03:49:42 +08:00
{
2014-02-10 14:04:30 +08:00
zval * arg , * params ;
2014-09-15 17:40:18 +08:00
uint32_t n = 1 ;
2007-04-06 03:49:42 +08:00
zend_fcall_info_args_clear ( fci , ! args ) ;
2006-06-07 17:43:54 +08:00
if ( ! args ) {
return SUCCESS ;
}
if ( Z_TYPE_P ( args ) ! = IS_ARRAY ) {
return FAILURE ;
}
fci - > param_count = zend_hash_num_elements ( Z_ARRVAL_P ( args ) ) ;
2014-02-10 14:04:30 +08:00
fci - > params = params = ( zval * ) erealloc ( fci - > params , fci - > param_count * sizeof ( zval ) ) ;
2006-06-07 17:43:54 +08:00
2014-04-18 23:18:11 +08:00
ZEND_HASH_FOREACH_VAL ( Z_ARRVAL_P ( args ) , arg ) {
2014-08-21 03:28:32 +08:00
if ( func & & ! Z_ISREF_P ( arg ) & & ARG_SHOULD_BE_SENT_BY_REF ( func , n ) ) {
ZVAL_NEW_REF ( params , arg ) ;
if ( Z_REFCOUNTED_P ( arg ) ) {
Z_ADDREF_P ( arg ) ;
}
} else {
ZVAL_COPY ( params , arg ) ;
}
2014-02-10 14:04:30 +08:00
params + + ;
2014-08-21 03:28:32 +08:00
n + + ;
2014-04-18 23:18:11 +08:00
} ZEND_HASH_FOREACH_END ( ) ;
2007-11-03 03:40:39 +08:00
return SUCCESS ;
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API int zend_fcall_info_args ( zend_fcall_info * fci , zval * args ) /* { { { */
2014-08-21 03:28:32 +08:00
{
2014-12-14 06:06:14 +08:00
return zend_fcall_info_args_ex ( fci , NULL , args ) ;
2014-08-21 03:28:32 +08:00
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API int zend_fcall_info_argp ( zend_fcall_info * fci , int argc , zval * argv ) /* { { { */
2007-11-03 03:40:39 +08:00
{
int i ;
if ( argc < 0 ) {
return FAILURE ;
}
zend_fcall_info_args_clear ( fci , ! argc ) ;
if ( argc ) {
fci - > param_count = argc ;
2014-02-10 14:04:30 +08:00
fci - > params = ( zval * ) erealloc ( fci - > params , fci - > param_count * sizeof ( zval ) ) ;
2007-11-03 03:40:39 +08:00
for ( i = 0 ; i < argc ; + + i ) {
2014-12-04 20:02:30 +08:00
ZVAL_COPY ( & fci - > params [ i ] , & argv [ i ] ) ;
2007-11-03 03:40:39 +08:00
}
}
return SUCCESS ;
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API int zend_fcall_info_argv ( zend_fcall_info * fci , int argc , va_list * argv ) /* { { { */
2007-11-03 03:40:39 +08:00
{
int i ;
2014-02-10 14:04:30 +08:00
zval * arg ;
2007-11-03 03:40:39 +08:00
if ( argc < 0 ) {
return FAILURE ;
}
zend_fcall_info_args_clear ( fci , ! argc ) ;
if ( argc ) {
fci - > param_count = argc ;
2014-02-10 14:04:30 +08:00
fci - > params = ( zval * ) erealloc ( fci - > params , fci - > param_count * sizeof ( zval ) ) ;
2007-11-03 03:40:39 +08:00
for ( i = 0 ; i < argc ; + + i ) {
2014-02-10 14:04:30 +08:00
arg = va_arg ( * argv , zval * ) ;
2014-12-04 20:02:30 +08:00
ZVAL_COPY ( & fci - > params [ i ] , arg ) ;
2007-11-03 03:40:39 +08:00
}
}
2006-06-07 17:43:54 +08:00
return SUCCESS ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API int zend_fcall_info_argn ( zend_fcall_info * fci , int argc , . . . ) /* { { { */
2007-11-03 03:40:39 +08:00
{
int ret ;
va_list argv ;
2006-06-07 17:43:54 +08:00
2007-11-03 03:40:39 +08:00
va_start ( argv , argc ) ;
2014-12-14 06:06:14 +08:00
ret = zend_fcall_info_argv ( fci , argc , & argv ) ;
2007-11-03 03:40:39 +08:00
va_end ( argv ) ;
return ret ;
}
/* }}} */
2006-06-07 17:43:54 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_fcall_info_call ( zend_fcall_info * fci , zend_fcall_info_cache * fcc , zval * retval_ptr , zval * args ) /* { { { */
2006-06-07 17:43:54 +08:00
{
2014-02-10 14:04:30 +08:00
zval retval , * org_params = NULL ;
2007-11-03 03:40:39 +08:00
int result , org_count = 0 ;
2006-06-07 17:43:54 +08:00
2014-02-10 14:04:30 +08:00
fci - > retval = retval_ptr ? retval_ptr : & retval ;
2006-06-07 17:43:54 +08:00
if ( args ) {
2007-04-06 03:49:42 +08:00
zend_fcall_info_args_save ( fci , & org_count , & org_params ) ;
2014-12-14 06:06:14 +08:00
zend_fcall_info_args ( fci , args ) ;
2006-06-07 17:43:54 +08:00
}
2014-12-14 06:06:14 +08:00
result = zend_call_function ( fci , fcc ) ;
2007-11-03 03:40:39 +08:00
2014-02-10 14:04:30 +08:00
if ( ! retval_ptr & & Z_TYPE ( retval ) ! = IS_UNDEF ) {
2006-06-07 17:43:54 +08:00
zval_ptr_dtor ( & retval ) ;
}
if ( args ) {
2007-04-06 03:49:42 +08:00
zend_fcall_info_args_restore ( fci , org_count , org_params ) ;
2006-06-07 17:43:54 +08:00
}
return result ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2006-06-07 17:43:54 +08:00
2007-11-03 03:40:39 +08:00
ZEND_API const char * zend_get_module_version ( const char * module_name ) /* { { { */
2001-10-13 02:40:30 +08:00
{
2014-02-10 14:04:30 +08:00
zend_string * lname ;
2014-10-24 19:20:55 +08:00
size_t name_len = strlen ( module_name ) ;
2001-10-13 02:40:30 +08:00
zend_module_entry * module ;
2014-08-26 01:24:55 +08:00
lname = zend_string_alloc ( name_len , 0 ) ;
2015-06-30 18:59:27 +08:00
zend_str_tolower_copy ( ZSTR_VAL ( lname ) , module_name , name_len ) ;
2014-02-10 14:04:30 +08:00
module = zend_hash_find_ptr ( & module_registry , lname ) ;
2014-08-26 01:24:55 +08:00
zend_string_free ( lname ) ;
2014-02-10 14:04:30 +08:00
return module ? module - > version : NULL ;
2001-10-13 02:40:30 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-02-01 09:49:15 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_declare_property_ex ( zend_class_entry * ce , zend_string * name , zval * property , int access_type , zend_string * doc_comment ) /* { { { */
2003-07-07 03:55:20 +08:00
{
2014-06-18 06:47:01 +08:00
zend_property_info * property_info , * property_info_ptr ;
if ( ce - > type = = ZEND_INTERNAL_CLASS ) {
property_info = pemalloc ( sizeof ( zend_property_info ) , 1 ) ;
2017-10-10 15:11:05 +08:00
if ( ( access_type & ZEND_ACC_STATIC ) | | Z_TYPE_P ( property ) = = IS_CONSTANT_AST ) {
2015-05-21 09:13:10 +08:00
ce - > ce_flags & = ~ ZEND_ACC_CONSTANTS_UPDATED ;
}
2014-06-18 06:47:01 +08:00
} else {
property_info = zend_arena_alloc ( & CG ( arena ) , sizeof ( zend_property_info ) ) ;
2017-10-10 15:11:05 +08:00
if ( Z_TYPE_P ( property ) = = IS_CONSTANT_AST ) {
2015-05-21 09:13:10 +08:00
ce - > ce_flags & = ~ ZEND_ACC_CONSTANTS_UPDATED ;
}
2014-06-18 06:47:01 +08:00
}
2003-07-07 03:55:20 +08:00
if ( ! ( access_type & ZEND_ACC_PPP_MASK ) ) {
access_type | = ZEND_ACC_PUBLIC ;
}
if ( access_type & ZEND_ACC_STATIC ) {
2014-02-10 14:04:30 +08:00
if ( ( property_info_ptr = zend_hash_find_ptr ( & ce - > properties_info , name ) ) ! = NULL & &
2010-05-24 22:11:39 +08:00
( property_info_ptr - > flags & ZEND_ACC_STATIC ) ! = 0 ) {
2014-06-18 06:47:01 +08:00
property_info - > offset = property_info_ptr - > offset ;
zval_ptr_dtor ( & ce - > default_static_members_table [ property_info - > offset ] ) ;
2014-02-10 14:04:30 +08:00
zend_hash_del ( & ce - > properties_info , name ) ;
2010-05-24 22:11:39 +08:00
} else {
2014-06-18 06:47:01 +08:00
property_info - > offset = ce - > default_static_members_count + + ;
2014-02-10 14:04:30 +08:00
ce - > default_static_members_table = perealloc ( ce - > default_static_members_table , sizeof ( zval ) * ce - > default_static_members_count , ce - > type = = ZEND_INTERNAL_CLASS ) ;
2010-05-24 22:11:39 +08:00
}
2014-06-18 06:47:01 +08:00
ZVAL_COPY_VALUE ( & ce - > default_static_members_table [ property_info - > offset ] , property ) ;
2010-05-24 22:11:39 +08:00
if ( ce - > type = = ZEND_USER_CLASS ) {
ce - > static_members_table = ce - > default_static_members_table ;
}
2003-07-07 03:55:20 +08:00
} else {
2014-02-10 14:04:30 +08:00
if ( ( property_info_ptr = zend_hash_find_ptr ( & ce - > properties_info , name ) ) ! = NULL & &
2010-05-24 22:11:39 +08:00
( property_info_ptr - > flags & ZEND_ACC_STATIC ) = = 0 ) {
2014-06-18 06:47:01 +08:00
property_info - > offset = property_info_ptr - > offset ;
2014-11-06 19:50:03 +08:00
zval_ptr_dtor ( & ce - > default_properties_table [ OBJ_PROP_TO_NUM ( property_info - > offset ) ] ) ;
2014-02-10 14:04:30 +08:00
zend_hash_del ( & ce - > properties_info , name ) ;
2010-05-24 22:11:39 +08:00
} else {
2014-11-06 19:50:03 +08:00
property_info - > offset = OBJ_PROP_TO_OFFSET ( ce - > default_properties_count ) ;
ce - > default_properties_count + + ;
2014-02-10 14:04:30 +08:00
ce - > default_properties_table = perealloc ( ce - > default_properties_table , sizeof ( zval ) * ce - > default_properties_count , ce - > type = = ZEND_INTERNAL_CLASS ) ;
2010-05-24 22:11:39 +08:00
}
2014-11-06 19:50:03 +08:00
ZVAL_COPY_VALUE ( & ce - > default_properties_table [ OBJ_PROP_TO_NUM ( property_info - > offset ) ] , property ) ;
2003-07-07 03:55:20 +08:00
}
2003-08-25 06:45:59 +08:00
if ( ce - > type & ZEND_INTERNAL_CLASS ) {
switch ( Z_TYPE_P ( property ) ) {
case IS_ARRAY :
case IS_OBJECT :
case IS_RESOURCE :
2015-04-01 18:32:23 +08:00
zend_error_noreturn ( E_CORE_ERROR , " Internal zval's can't be arrays, objects or resources " ) ;
2003-08-25 06:45:59 +08:00
break ;
default :
break ;
}
2017-09-18 16:27:10 +08:00
/* Must be interned to avoid ZTS data races */
name = zend_new_interned_string ( zend_string_copy ( name ) ) ;
2003-08-25 01:32:47 +08:00
}
2017-09-18 16:27:10 +08:00
2015-06-03 18:43:05 +08:00
if ( access_type & ZEND_ACC_PUBLIC ) {
property_info - > name = zend_string_copy ( name ) ;
} else if ( access_type & ZEND_ACC_PRIVATE ) {
2015-06-30 18:59:27 +08:00
property_info - > name = zend_mangle_property_name ( ZSTR_VAL ( ce - > name ) , ZSTR_LEN ( ce - > name ) , ZSTR_VAL ( name ) , ZSTR_LEN ( name ) , ce - > type & ZEND_INTERNAL_CLASS ) ;
2015-06-03 18:43:05 +08:00
} else {
ZEND_ASSERT ( access_type & ZEND_ACC_PROTECTED ) ;
2015-06-30 18:59:27 +08:00
property_info - > name = zend_mangle_property_name ( " * " , 1 , ZSTR_VAL ( name ) , ZSTR_LEN ( name ) , ce - > type & ZEND_INTERNAL_CLASS ) ;
2003-07-07 03:55:20 +08:00
}
2010-04-20 19:05:54 +08:00
2014-12-14 06:06:14 +08:00
property_info - > name = zend_new_interned_string ( property_info - > name ) ;
2014-06-18 06:47:01 +08:00
property_info - > flags = access_type ;
property_info - > doc_comment = doc_comment ;
property_info - > ce = ce ;
zend_hash_update_ptr ( & ce - > properties_info , name , property_info ) ;
2003-07-08 00:22:56 +08:00
return SUCCESS ;
2003-07-07 03:55:20 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API int zend_declare_property ( zend_class_entry * ce , const char * name , size_t name_length , zval * property , int access_type ) /* { { { */
2007-11-03 03:40:39 +08:00
{
2014-08-26 01:24:55 +08:00
zend_string * key = zend_string_init ( name , name_length , ce - > type & ZEND_INTERNAL_CLASS ) ;
2014-12-14 06:06:14 +08:00
int ret = zend_declare_property_ex ( ce , key , property , access_type , NULL ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( key ) ;
2014-02-10 14:04:30 +08:00
return ret ;
2007-11-03 03:40:39 +08:00
}
/* }}} */
2003-08-24 03:37:39 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_declare_property_null ( zend_class_entry * ce , const char * name , size_t name_length , int access_type ) /* { { { */
2003-08-24 03:37:39 +08:00
{
2014-02-10 14:04:30 +08:00
zval property ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_NULL ( & property ) ;
2014-12-14 06:06:14 +08:00
return zend_declare_property ( ce , name , name_length , & property , access_type ) ;
2003-08-24 03:37:39 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-08-24 03:37:39 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_declare_property_bool ( zend_class_entry * ce , const char * name , size_t name_length , zend_long value , int access_type ) /* { { { */
2005-02-05 04:24:21 +08:00
{
2014-02-10 14:04:30 +08:00
zval property ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_BOOL ( & property , value ) ;
2014-12-14 06:06:14 +08:00
return zend_declare_property ( ce , name , name_length , & property , access_type ) ;
2005-02-05 04:24:21 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-02-05 04:24:21 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_declare_property_long ( zend_class_entry * ce , const char * name , size_t name_length , zend_long value , int access_type ) /* { { { */
2003-08-24 03:37:39 +08:00
{
2014-02-10 14:04:30 +08:00
zval property ;
2006-05-10 07:53:23 +08:00
2014-08-26 01:24:55 +08:00
ZVAL_LONG ( & property , value ) ;
2014-12-14 06:06:14 +08:00
return zend_declare_property ( ce , name , name_length , & property , access_type ) ;
2003-08-25 01:32:47 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-08-25 01:32:47 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_declare_property_double ( zend_class_entry * ce , const char * name , size_t name_length , double value , int access_type ) /* { { { */
2005-02-05 04:24:21 +08:00
{
2014-02-10 14:04:30 +08:00
zval property ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_DOUBLE ( & property , value ) ;
2014-12-14 06:06:14 +08:00
return zend_declare_property ( ce , name , name_length , & property , access_type ) ;
2005-02-05 04:24:21 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-02-05 04:24:21 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_declare_property_string ( zend_class_entry * ce , const char * name , size_t name_length , const char * value , int access_type ) /* { { { */
2003-08-25 01:32:47 +08:00
{
2014-02-10 14:04:30 +08:00
zval property ;
2006-05-10 07:53:23 +08:00
2014-08-26 01:24:55 +08:00
ZVAL_NEW_STR ( & property , zend_string_init ( value , strlen ( value ) , ce - > type & ZEND_INTERNAL_CLASS ) ) ;
2014-12-14 06:06:14 +08:00
return zend_declare_property ( ce , name , name_length , & property , access_type ) ;
2003-08-24 03:37:39 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-08-24 03:37:39 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_declare_property_stringl ( zend_class_entry * ce , const char * name , size_t name_length , const char * value , size_t value_len , int access_type ) /* { { { */
2005-02-05 04:24:21 +08:00
{
2014-02-10 14:04:30 +08:00
zval property ;
2006-05-10 07:53:23 +08:00
2014-08-26 01:24:55 +08:00
ZVAL_NEW_STR ( & property , zend_string_init ( value , value_len , ce - > type & ZEND_INTERNAL_CLASS ) ) ;
2014-12-14 06:06:14 +08:00
return zend_declare_property ( ce , name , name_length , & property , access_type ) ;
2005-02-05 04:24:21 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-02-05 04:24:21 +08:00
2015-12-08 17:40:42 +08:00
ZEND_API int zend_declare_class_constant_ex ( zend_class_entry * ce , zend_string * name , zval * value , int access_type , zend_string * doc_comment ) /* { { { */
2005-09-01 18:05:32 +08:00
{
2015-12-08 17:40:42 +08:00
zend_class_constant * c ;
if ( ce - > ce_flags & ZEND_ACC_INTERFACE ) {
if ( access_type ! = ZEND_ACC_PUBLIC ) {
zend_error_noreturn ( E_COMPILE_ERROR , " Access type for interface constant %s::%s must be public " , ZSTR_VAL ( ce - > name ) , ZSTR_VAL ( name ) ) ;
}
}
if ( zend_string_equals_literal_ci ( name , " class " ) ) {
2015-12-11 05:22:49 +08:00
zend_error_noreturn ( ce - > type = = ZEND_INTERNAL_CLASS ? E_CORE_ERROR : E_COMPILE_ERROR ,
2015-12-08 17:40:42 +08:00
" A class constant must not be called 'class'; it is reserved for class name fetching " ) ;
}
if ( ce - > type = = ZEND_INTERNAL_CLASS ) {
c = pemalloc ( sizeof ( zend_class_constant ) , 1 ) ;
} else {
c = zend_arena_alloc ( & CG ( arena ) , sizeof ( zend_class_constant ) ) ;
}
ZVAL_COPY_VALUE ( & c - > value , value ) ;
Z_ACCESS_FLAGS ( c - > value ) = access_type ;
c - > doc_comment = doc_comment ;
c - > ce = ce ;
2017-10-10 15:11:05 +08:00
if ( Z_TYPE_P ( value ) = = IS_CONSTANT_AST ) {
2014-06-17 03:32:58 +08:00
ce - > ce_flags & = ~ ZEND_ACC_CONSTANTS_UPDATED ;
}
2015-12-11 05:22:49 +08:00
if ( ! zend_hash_add_ptr ( & ce - > constants_table , name , c ) ) {
zend_error_noreturn ( ce - > type = = ZEND_INTERNAL_CLASS ? E_CORE_ERROR : E_COMPILE_ERROR ,
" Cannot redefine class constant %s::%s " , ZSTR_VAL ( ce - > name ) , ZSTR_VAL ( name ) ) ;
}
return SUCCESS ;
2005-09-01 18:05:32 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-09-01 18:05:32 +08:00
2015-12-08 17:40:42 +08:00
ZEND_API int zend_declare_class_constant ( zend_class_entry * ce , const char * name , size_t name_length , zval * value ) /* { { { */
{
int ret ;
2017-10-19 05:02:56 +08:00
zend_string * key ;
2017-03-04 17:39:13 +08:00
if ( ce - > type = = ZEND_INTERNAL_CLASS ) {
2017-10-19 05:02:56 +08:00
key = zend_string_init_interned ( name , name_length , 1 ) ;
} else {
key = zend_string_init ( name , name_length , 0 ) ;
2017-03-04 17:39:13 +08:00
}
2015-12-08 17:40:42 +08:00
ret = zend_declare_class_constant_ex ( ce , key , value , ZEND_ACC_PUBLIC , NULL ) ;
zend_string_release ( key ) ;
return ret ;
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API int zend_declare_class_constant_null ( zend_class_entry * ce , const char * name , size_t name_length ) /* { { { */
2006-03-06 00:12:24 +08:00
{
2014-02-10 14:04:30 +08:00
zval constant ;
2006-03-06 00:12:24 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_NULL ( & constant ) ;
2014-12-14 06:06:14 +08:00
return zend_declare_class_constant ( ce , name , name_length , & constant ) ;
2006-03-06 00:12:24 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2006-03-06 00:12:24 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_declare_class_constant_long ( zend_class_entry * ce , const char * name , size_t name_length , zend_long value ) /* { { { */
2005-09-01 18:05:32 +08:00
{
2014-02-10 14:04:30 +08:00
zval constant ;
2005-09-01 18:05:32 +08:00
2014-08-26 01:24:55 +08:00
ZVAL_LONG ( & constant , value ) ;
2014-12-14 06:06:14 +08:00
return zend_declare_class_constant ( ce , name , name_length , & constant ) ;
2005-09-01 18:05:32 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-09-01 18:05:32 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_declare_class_constant_bool ( zend_class_entry * ce , const char * name , size_t name_length , zend_bool value ) /* { { { */
2005-09-01 18:05:32 +08:00
{
2014-02-10 14:04:30 +08:00
zval constant ;
2005-09-01 18:05:32 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_BOOL ( & constant , value ) ;
2014-12-14 06:06:14 +08:00
return zend_declare_class_constant ( ce , name , name_length , & constant ) ;
2005-09-01 18:05:32 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-09-01 18:05:32 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_declare_class_constant_double ( zend_class_entry * ce , const char * name , size_t name_length , double value ) /* { { { */
2005-09-01 18:05:32 +08:00
{
2014-02-10 14:04:30 +08:00
zval constant ;
2005-09-01 18:05:32 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_DOUBLE ( & constant , value ) ;
2014-12-14 06:06:14 +08:00
return zend_declare_class_constant ( ce , name , name_length , & constant ) ;
2005-09-01 18:05:32 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-09-01 18:05:32 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_declare_class_constant_stringl ( zend_class_entry * ce , const char * name , size_t name_length , const char * value , size_t value_length ) /* { { { */
2005-09-01 18:05:32 +08:00
{
2014-02-10 14:04:30 +08:00
zval constant ;
2005-09-01 18:05:32 +08:00
2014-08-26 01:24:55 +08:00
ZVAL_NEW_STR ( & constant , zend_string_init ( value , value_length , ce - > type & ZEND_INTERNAL_CLASS ) ) ;
2014-12-14 06:06:14 +08:00
return zend_declare_class_constant ( ce , name , name_length , & constant ) ;
2005-09-01 18:05:32 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-09-01 18:05:32 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_declare_class_constant_string ( zend_class_entry * ce , const char * name , size_t name_length , const char * value ) /* { { { */
2005-09-01 18:05:32 +08:00
{
2014-12-14 06:06:14 +08:00
return zend_declare_class_constant_stringl ( ce , name , name_length , value , strlen ( value ) ) ;
2005-09-01 18:05:32 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-09-01 18:05:32 +08:00
2015-05-05 21:19:51 +08:00
ZEND_API void zend_update_property_ex ( zend_class_entry * scope , zval * object , zend_string * name , zval * value ) /* { { { */
{
zval property ;
2016-04-28 09:13:34 +08:00
zend_class_entry * old_scope = EG ( fake_scope ) ;
2015-05-05 21:19:51 +08:00
2016-04-28 09:13:34 +08:00
EG ( fake_scope ) = scope ;
2015-05-05 21:19:51 +08:00
if ( ! Z_OBJ_HT_P ( object ) - > write_property ) {
2016-06-21 21:00:37 +08:00
zend_error_noreturn ( E_CORE_ERROR , " Property %s of class %s cannot be updated " , ZSTR_VAL ( name ) , ZSTR_VAL ( Z_OBJCE_P ( object ) - > name ) ) ;
2015-05-05 21:19:51 +08:00
}
ZVAL_STR ( & property , name ) ;
Z_OBJ_HT_P ( object ) - > write_property ( object , & property , value , NULL ) ;
2016-04-28 09:13:34 +08:00
EG ( fake_scope ) = old_scope ;
2015-05-05 21:19:51 +08:00
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API void zend_update_property ( zend_class_entry * scope , zval * object , const char * name , size_t name_length , zval * value ) /* { { { */
2003-08-24 03:37:39 +08:00
{
2014-02-10 14:04:30 +08:00
zval property ;
2016-04-28 09:13:34 +08:00
zend_class_entry * old_scope = EG ( fake_scope ) ;
2006-05-10 07:53:23 +08:00
2016-04-28 09:13:34 +08:00
EG ( fake_scope ) = scope ;
2003-08-24 03:37:39 +08:00
if ( ! Z_OBJ_HT_P ( object ) - > write_property ) {
2015-06-30 18:59:27 +08:00
zend_error_noreturn ( E_CORE_ERROR , " Property %s of class %s cannot be updated " , name , ZSTR_VAL ( Z_OBJCE_P ( object ) - > name ) ) ;
2003-08-24 03:37:39 +08:00
}
2014-02-10 14:04:30 +08:00
ZVAL_STRINGL ( & property , name , name_length ) ;
2014-12-14 06:06:14 +08:00
Z_OBJ_HT_P ( object ) - > write_property ( object , & property , value , NULL ) ;
2005-11-23 19:15:11 +08:00
zval_ptr_dtor ( & property ) ;
2003-08-24 03:37:39 +08:00
2016-04-28 09:13:34 +08:00
EG ( fake_scope ) = old_scope ;
2003-08-24 03:37:39 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-08-24 03:37:39 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API void zend_update_property_null ( zend_class_entry * scope , zval * object , const char * name , size_t name_length ) /* { { { */
2003-08-24 03:37:39 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2003-08-24 03:37:39 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_NULL ( & tmp ) ;
2014-12-14 06:06:14 +08:00
zend_update_property ( scope , object , name , name_length , & tmp ) ;
2003-08-24 03:37:39 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-08-24 03:37:39 +08:00
2016-09-26 10:53:59 +08:00
ZEND_API void zend_unset_property ( zend_class_entry * scope , zval * object , const char * name , size_t name_length ) /* { { { */
{
zval property ;
2016-10-13 00:31:46 +08:00
zend_class_entry * old_scope = EG ( fake_scope ) ;
2016-09-26 10:53:59 +08:00
2016-10-13 00:31:46 +08:00
EG ( fake_scope ) = scope ;
2016-09-26 10:53:59 +08:00
if ( ! Z_OBJ_HT_P ( object ) - > unset_property ) {
zend_error_noreturn ( E_CORE_ERROR , " Property %s of class %s cannot be unset " , name , ZSTR_VAL ( Z_OBJCE_P ( object ) - > name ) ) ;
}
ZVAL_STRINGL ( & property , name , name_length ) ;
Z_OBJ_HT_P ( object ) - > unset_property ( object , & property , 0 ) ;
zval_ptr_dtor ( & property ) ;
2016-10-13 00:31:46 +08:00
EG ( fake_scope ) = old_scope ;
2016-09-26 10:53:59 +08:00
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API void zend_update_property_bool ( zend_class_entry * scope , zval * object , const char * name , size_t name_length , zend_long value ) /* { { { */
2005-02-05 04:24:21 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_BOOL ( & tmp , value ) ;
2014-12-14 06:06:14 +08:00
zend_update_property ( scope , object , name , name_length , & tmp ) ;
2005-02-05 04:24:21 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-02-05 04:24:21 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API void zend_update_property_long ( zend_class_entry * scope , zval * object , const char * name , size_t name_length , zend_long value ) /* { { { */
2003-08-24 03:37:39 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-08-26 01:24:55 +08:00
ZVAL_LONG ( & tmp , value ) ;
2014-12-14 06:06:14 +08:00
zend_update_property ( scope , object , name , name_length , & tmp ) ;
2003-08-24 03:37:39 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-08-24 03:37:39 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API void zend_update_property_double ( zend_class_entry * scope , zval * object , const char * name , size_t name_length , double value ) /* { { { */
2005-02-05 04:24:21 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_DOUBLE ( & tmp , value ) ;
2014-12-14 06:06:14 +08:00
zend_update_property ( scope , object , name , name_length , & tmp ) ;
2005-02-05 04:24:21 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-02-05 04:24:21 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API void zend_update_property_str ( zend_class_entry * scope , zval * object , const char * name , size_t name_length , zend_string * value ) /* { { { */
2014-02-21 20:14:42 +08:00
{
zval tmp ;
2014-02-28 17:29:18 +08:00
ZVAL_STR ( & tmp , value ) ;
2014-12-14 06:06:14 +08:00
zend_update_property ( scope , object , name , name_length , & tmp ) ;
2014-02-21 20:14:42 +08:00
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API void zend_update_property_string ( zend_class_entry * scope , zval * object , const char * name , size_t name_length , const char * value ) /* { { { */
2003-08-24 03:37:39 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_STRING ( & tmp , value ) ;
Z_SET_REFCOUNT ( tmp , 0 ) ;
2014-12-14 06:06:14 +08:00
zend_update_property ( scope , object , name , name_length , & tmp ) ;
2003-08-24 03:37:39 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-08-24 03:37:39 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API void zend_update_property_stringl ( zend_class_entry * scope , zval * object , const char * name , size_t name_length , const char * value , size_t value_len ) /* { { { */
2005-02-05 04:24:21 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_STRINGL ( & tmp , value , value_len ) ;
Z_SET_REFCOUNT ( tmp , 0 ) ;
2014-12-14 06:06:14 +08:00
zend_update_property ( scope , object , name , name_length , & tmp ) ;
2005-02-05 04:24:21 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-02-05 04:24:21 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_update_static_property ( zend_class_entry * scope , const char * name , size_t name_length , zval * value ) /* { { { */
2005-09-01 18:05:32 +08:00
{
2014-02-10 14:04:30 +08:00
zval * property ;
2016-04-28 09:13:34 +08:00
zend_class_entry * old_scope = EG ( fake_scope ) ;
2014-08-26 01:24:55 +08:00
zend_string * key = zend_string_init ( name , name_length , 0 ) ;
2006-05-10 07:53:23 +08:00
2016-04-28 09:13:34 +08:00
EG ( fake_scope ) = scope ;
2015-01-13 14:33:15 +08:00
property = zend_std_get_static_property ( scope , key , 0 ) ;
2016-04-28 09:13:34 +08:00
EG ( fake_scope ) = old_scope ;
2014-08-26 01:24:55 +08:00
zend_string_free ( key ) ;
2005-09-01 18:05:32 +08:00
if ( ! property ) {
return FAILURE ;
} else {
2014-02-10 14:04:30 +08:00
if ( property ! = value ) {
if ( Z_ISREF_P ( property ) ) {
2016-05-06 14:23:37 +08:00
zval_dtor ( property ) ;
2014-02-10 14:04:30 +08:00
ZVAL_COPY_VALUE ( property , value ) ;
2015-07-13 08:42:18 +08:00
if ( Z_REFCOUNTED_P ( value ) & & Z_REFCOUNT_P ( value ) > 0 ) {
2014-04-04 06:52:53 +08:00
zval_opt_copy_ctor ( property ) ;
2005-09-01 18:05:32 +08:00
}
} else {
2014-02-10 14:04:30 +08:00
zval garbage ;
2005-09-01 18:05:32 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_COPY_VALUE ( & garbage , property ) ;
2014-09-29 12:06:56 +08:00
if ( Z_REFCOUNTED_P ( value ) ) {
Z_ADDREF_P ( value ) ;
if ( Z_ISREF_P ( value ) ) {
SEPARATE_ZVAL ( value ) ;
}
2005-09-01 18:05:32 +08:00
}
2014-02-10 14:04:30 +08:00
ZVAL_COPY_VALUE ( property , value ) ;
2005-09-01 18:05:32 +08:00
zval_ptr_dtor ( & garbage ) ;
}
}
return SUCCESS ;
}
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-09-01 18:05:32 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_update_static_property_null ( zend_class_entry * scope , const char * name , size_t name_length ) /* { { { */
2005-09-01 18:05:32 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2015-01-03 17:22:58 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_NULL ( & tmp ) ;
2014-12-14 06:06:14 +08:00
return zend_update_static_property ( scope , name , name_length , & tmp ) ;
2005-09-01 18:05:32 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-09-01 18:05:32 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_update_static_property_bool ( zend_class_entry * scope , const char * name , size_t name_length , zend_long value ) /* { { { */
2005-09-01 18:05:32 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_BOOL ( & tmp , value ) ;
2014-12-14 06:06:14 +08:00
return zend_update_static_property ( scope , name , name_length , & tmp ) ;
2005-09-01 18:05:32 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-09-01 18:05:32 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_update_static_property_long ( zend_class_entry * scope , const char * name , size_t name_length , zend_long value ) /* { { { */
2005-09-01 18:05:32 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-08-26 01:24:55 +08:00
ZVAL_LONG ( & tmp , value ) ;
2014-12-14 06:06:14 +08:00
return zend_update_static_property ( scope , name , name_length , & tmp ) ;
2005-09-01 18:05:32 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-09-01 18:05:32 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_update_static_property_double ( zend_class_entry * scope , const char * name , size_t name_length , double value ) /* { { { */
2005-09-01 18:05:32 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_DOUBLE ( & tmp , value ) ;
2014-12-14 06:06:14 +08:00
return zend_update_static_property ( scope , name , name_length , & tmp ) ;
2005-09-01 18:05:32 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-09-01 18:05:32 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_update_static_property_string ( zend_class_entry * scope , const char * name , size_t name_length , const char * value ) /* { { { */
2005-09-01 18:05:32 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_STRING ( & tmp , value ) ;
Z_SET_REFCOUNT ( tmp , 0 ) ;
2014-12-14 06:06:14 +08:00
return zend_update_static_property ( scope , name , name_length , & tmp ) ;
2005-09-01 18:05:32 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-09-01 18:05:32 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_update_static_property_stringl ( zend_class_entry * scope , const char * name , size_t name_length , const char * value , size_t value_len ) /* { { { */
2005-09-01 18:05:32 +08:00
{
2014-02-10 14:04:30 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_STRINGL ( & tmp , value , value_len ) ;
Z_SET_REFCOUNT ( tmp , 0 ) ;
2014-12-14 06:06:14 +08:00
return zend_update_static_property ( scope , name , name_length , & tmp ) ;
2005-09-01 18:05:32 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-09-01 18:05:32 +08:00
2016-05-12 18:47:22 +08:00
ZEND_API zval * zend_read_property_ex ( zend_class_entry * scope , zval * object , zend_string * name , zend_bool silent , zval * rv ) /* { { { */
2003-08-24 08:36:53 +08:00
{
2014-02-10 14:04:30 +08:00
zval property , * value ;
2016-04-28 09:13:34 +08:00
zend_class_entry * old_scope = EG ( fake_scope ) ;
2006-05-10 07:53:23 +08:00
2016-04-28 09:13:34 +08:00
EG ( fake_scope ) = scope ;
2003-08-24 08:36:53 +08:00
if ( ! Z_OBJ_HT_P ( object ) - > read_property ) {
2016-06-21 21:00:37 +08:00
zend_error_noreturn ( E_CORE_ERROR , " Property %s of class %s cannot be read " , ZSTR_VAL ( name ) , ZSTR_VAL ( Z_OBJCE_P ( object ) - > name ) ) ;
2003-08-24 08:36:53 +08:00
}
2006-05-10 07:53:23 +08:00
2016-05-12 18:47:22 +08:00
ZVAL_STR ( & property , name ) ;
2015-01-22 16:50:42 +08:00
value = Z_OBJ_HT_P ( object ) - > read_property ( object , & property , silent ? BP_VAR_IS : BP_VAR_R , NULL , rv ) ;
2006-05-10 07:53:23 +08:00
2016-04-28 09:13:34 +08:00
EG ( fake_scope ) = old_scope ;
2003-08-24 08:36:53 +08:00
return value ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-08-24 08:36:53 +08:00
2016-05-12 18:47:22 +08:00
ZEND_API zval * zend_read_property ( zend_class_entry * scope , zval * object , const char * name , size_t name_length , zend_bool silent , zval * rv ) /* { { { */
{
zval * value ;
zend_string * str ;
str = zend_string_init ( name , name_length , 0 ) ;
value = zend_read_property_ex ( scope , object , str , silent , rv ) ;
zend_string_release ( str ) ;
return value ;
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API zval * zend_read_static_property ( zend_class_entry * scope , const char * name , size_t name_length , zend_bool silent ) /* { { { */
2005-09-01 18:05:32 +08:00
{
2014-02-10 14:04:30 +08:00
zval * property ;
2016-04-28 09:13:34 +08:00
zend_class_entry * old_scope = EG ( fake_scope ) ;
2014-08-26 01:24:55 +08:00
zend_string * key = zend_string_init ( name , name_length , 0 ) ;
2006-05-10 07:53:23 +08:00
2016-04-28 09:13:34 +08:00
EG ( fake_scope ) = scope ;
2015-01-13 14:33:15 +08:00
property = zend_std_get_static_property ( scope , key , silent ) ;
2016-04-28 09:13:34 +08:00
EG ( fake_scope ) = old_scope ;
2014-08-26 01:24:55 +08:00
zend_string_free ( key ) ;
2005-09-01 18:05:32 +08:00
2014-02-10 14:04:30 +08:00
return property ;
2005-09-01 18:05:32 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-09-01 18:05:32 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API void zend_save_error_handling ( zend_error_handling * current ) /* { { { */
2008-08-09 01:47:31 +08:00
{
current - > handling = EG ( error_handling ) ;
current - > exception = EG ( exception_class ) ;
2014-02-10 14:04:30 +08:00
ZVAL_COPY ( & current - > user_handler , & EG ( user_error_handler ) ) ;
2008-08-09 01:47:31 +08:00
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API void zend_replace_error_handling ( zend_error_handling_t error_handling , zend_class_entry * exception_class , zend_error_handling * current ) /* { { { */
2008-08-09 01:47:31 +08:00
{
if ( current ) {
2014-12-14 06:06:14 +08:00
zend_save_error_handling ( current ) ;
2014-02-10 14:04:30 +08:00
if ( error_handling ! = EH_NORMAL & & Z_TYPE ( EG ( user_error_handler ) ) ! = IS_UNDEF ) {
2008-08-12 01:19:20 +08:00
zval_ptr_dtor ( & EG ( user_error_handler ) ) ;
2014-02-10 14:04:30 +08:00
ZVAL_UNDEF ( & EG ( user_error_handler ) ) ;
2008-08-12 01:19:20 +08:00
}
2008-08-09 01:47:31 +08:00
}
EG ( error_handling ) = error_handling ;
EG ( exception_class ) = error_handling = = EH_THROW ? exception_class : NULL ;
}
/* }}} */
2014-03-20 02:43:36 +08:00
static int same_zval ( zval * zv1 , zval * zv2 ) /* { { { */
{
if ( Z_TYPE_P ( zv1 ) ! = Z_TYPE_P ( zv2 ) ) {
return 0 ;
}
switch ( Z_TYPE_P ( zv1 ) ) {
case IS_UNDEF :
case IS_NULL :
2014-04-30 22:32:42 +08:00
case IS_FALSE :
case IS_TRUE :
2014-03-20 02:43:36 +08:00
return 1 ;
2014-08-26 01:24:55 +08:00
case IS_LONG :
return Z_LVAL_P ( zv1 ) = = Z_LVAL_P ( zv2 ) ;
2014-03-20 02:43:36 +08:00
case IS_DOUBLE :
2014-08-26 01:24:55 +08:00
return Z_LVAL_P ( zv1 ) = = Z_LVAL_P ( zv2 ) ;
2014-03-20 02:43:36 +08:00
case IS_STRING :
case IS_ARRAY :
case IS_OBJECT :
case IS_RESOURCE :
return Z_COUNTED_P ( zv1 ) = = Z_COUNTED_P ( zv2 ) ;
default :
return 0 ;
}
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API void zend_restore_error_handling ( zend_error_handling * saved ) /* { { { */
2008-08-09 01:47:31 +08:00
{
EG ( error_handling ) = saved - > handling ;
EG ( exception_class ) = saved - > handling = = EH_THROW ? saved - > exception : NULL ;
2014-02-12 22:08:11 +08:00
if ( Z_TYPE ( saved - > user_handler ) ! = IS_UNDEF
2014-03-20 02:43:36 +08:00
& & ! same_zval ( & saved - > user_handler , & EG ( user_error_handler ) ) ) {
2014-02-10 14:04:30 +08:00
zval_ptr_dtor ( & EG ( user_error_handler ) ) ;
ZVAL_COPY_VALUE ( & EG ( user_error_handler ) , & saved - > user_handler ) ;
2014-02-12 22:08:11 +08:00
} else if ( Z_TYPE ( saved - > user_handler ) ) {
zval_ptr_dtor ( & saved - > user_handler ) ;
2008-08-12 01:19:20 +08:00
}
2014-02-10 14:04:30 +08:00
ZVAL_UNDEF ( & saved - > user_handler ) ;
2008-08-09 01:47:31 +08:00
}
/* }}} */
2014-02-10 14:04:30 +08:00
ZEND_API zend_string * zend_find_alias_name ( zend_class_entry * ce , zend_string * name ) /* { { { */
2013-03-21 21:09:30 +08:00
{
zend_trait_alias * alias , * * alias_ptr ;
2013-08-29 14:02:15 +08:00
if ( ( alias_ptr = ce - > trait_aliases ) ) {
2013-03-21 21:09:30 +08:00
alias = * alias_ptr ;
2013-08-29 11:33:42 +08:00
while ( alias ) {
2015-07-28 16:39:58 +08:00
if ( alias - > alias & & zend_string_equals_ci ( alias - > alias , name ) ) {
2013-08-29 11:33:42 +08:00
return alias - > alias ;
}
alias_ptr + + ;
alias = * alias_ptr ;
}
2013-03-21 21:09:30 +08:00
}
return name ;
}
/* }}} */
2014-02-10 14:04:30 +08:00
ZEND_API zend_string * zend_resolve_method_name ( zend_class_entry * ce , zend_function * f ) /* { { { */
2013-03-21 21:09:30 +08:00
{
zend_function * func ;
HashTable * function_table ;
2014-04-18 23:18:11 +08:00
zend_string * name ;
2013-03-21 21:09:30 +08:00
if ( f - > common . type ! = ZEND_USER_FUNCTION | |
2015-02-20 19:59:30 +08:00
( f - > op_array . refcount & & * ( f - > op_array . refcount ) < 2 ) | |
2013-03-21 21:09:30 +08:00
! f - > common . scope | |
! f - > common . scope - > trait_aliases ) {
return f - > common . function_name ;
}
function_table = & ce - > function_table ;
2014-04-22 21:46:34 +08:00
ZEND_HASH_FOREACH_STR_KEY_PTR ( function_table , name , func ) {
2013-03-21 21:09:30 +08:00
if ( func = = f ) {
2014-04-18 23:18:11 +08:00
if ( ! name ) {
2013-03-21 21:09:30 +08:00
return f - > common . function_name ;
}
2015-06-30 18:59:27 +08:00
if ( ZSTR_LEN ( name ) = = ZSTR_LEN ( f - > common . function_name ) & &
! strncasecmp ( ZSTR_VAL ( name ) , ZSTR_VAL ( f - > common . function_name ) , ZSTR_LEN ( f - > common . function_name ) ) ) {
2013-03-21 21:09:30 +08:00
return f - > common . function_name ;
}
2014-02-10 14:04:30 +08:00
return zend_find_alias_name ( f - > common . scope , name ) ;
2013-03-21 21:09:30 +08:00
}
2014-04-18 23:18:11 +08:00
} ZEND_HASH_FOREACH_END ( ) ;
2013-03-21 21:09:30 +08:00
return f - > common . function_name ;
}
/* }}} */
2015-03-25 14:01:04 +08:00
ZEND_API const char * zend_get_object_type ( const zend_class_entry * ce ) /* { { { */
2015-03-25 13:31:11 +08:00
{
if ( ce - > ce_flags & ZEND_ACC_TRAIT ) {
return " trait " ;
} else if ( ce - > ce_flags & ZEND_ACC_INTERFACE ) {
return " interface " ;
} else {
return " class " ;
}
}
/* }}} */
2016-06-04 06:42:04 +08:00
ZEND_API zend_bool zend_is_iterable ( zval * iterable ) /* { { { */
{
switch ( Z_TYPE_P ( iterable ) ) {
case IS_ARRAY :
return 1 ;
case IS_OBJECT :
return instanceof_function ( Z_OBJCE_P ( iterable ) , zend_ce_traversable ) ;
default :
return 0 ;
}
}
/* }}} */
2003-02-01 09:49:15 +08:00
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* indent - tabs - mode : t
* End :
2017-07-05 00:12:45 +08:00
* vim600 : sw = 4 ts = 4 fdm = marker
* vim < 600 : sw = 4 ts = 4
2003-02-01 09:49:15 +08:00
*/