1999-04-08 02:10:10 +08:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| Zend Engine |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2007-12-31 15:17:19 +08:00
| Copyright ( c ) 1998 - 2008 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 , |
2002-10-25 02:04:12 +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 > |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
2003-02-01 09:49:15 +08:00
/* $Id$ */
2000-02-10 05:48:16 +08:00
# define ZEND_INTENSIVE_DEBUGGING 0
1999-07-16 22:58:16 +08:00
1999-04-08 02:10:10 +08:00
# include <stdio.h>
# include <signal.h>
# include "zend.h"
# include "zend_compile.h"
# include "zend_execute.h"
# include "zend_API.h"
# include "zend_ptr_stack.h"
# include "zend_constants.h"
# include "zend_extensions.h"
2002-11-20 01:51:30 +08:00
# include "zend_ini.h"
2004-02-12 18:38:14 +08:00
# include "zend_exceptions.h"
2006-05-10 07:53:23 +08:00
# include "zend_interfaces.h"
2004-09-24 05:43:32 +08:00
# include "zend_vm.h"
2006-05-15 23:31:27 +08:00
/* Virtual current working directory support */
# include "tsrm_virtual_cwd.h"
2004-10-23 05:42:14 +08:00
# define _CONST_CODE 0
# define _TMP_CODE 1
# define _VAR_CODE 2
# define _UNUSED_CODE 3
# define _CV_CODE 4
2004-09-24 05:43:32 +08:00
typedef int ( * incdec_t ) ( zval * ) ;
1999-04-08 02:10:10 +08:00
2004-10-05 03:54:35 +08:00
# define get_zval_ptr(node, Ts, should_free, type) _get_zval_ptr(node, Ts, should_free, type TSRMLS_CC)
# define get_zval_ptr_ptr(node, Ts, should_free, type) _get_zval_ptr_ptr(node, Ts, should_free, type TSRMLS_CC)
# define get_obj_zval_ptr(node, Ts, should_free, type) _get_obj_zval_ptr(node, Ts, should_free, type TSRMLS_CC)
# define get_obj_zval_ptr_ptr(node, Ts, should_free, type) _get_obj_zval_ptr_ptr(node, Ts, should_free, type TSRMLS_CC)
1999-04-08 02:10:10 +08:00
/* Prototypes */
2001-07-31 12:53:54 +08:00
static void zend_extension_statement_handler ( zend_extension * extension , zend_op_array * op_array TSRMLS_DC ) ;
static void zend_extension_fcall_begin_handler ( zend_extension * extension , zend_op_array * op_array TSRMLS_DC ) ;
static void zend_extension_fcall_end_handler ( zend_extension * extension , zend_op_array * op_array TSRMLS_DC ) ;
1999-04-08 02:10:10 +08:00
1999-12-21 23:55:46 +08:00
# define RETURN_VALUE_USED(opline) (!((opline)->result.u.EA.type & EXT_TYPE_UNUSED))
2002-10-24 04:40:07 +08:00
# define EX_T(offset) (*(temp_variable *)((char *) EX(Ts) + offset))
# define T(offset) (*(temp_variable *)((char *) Ts + offset))
2002-10-24 04:26:28 +08:00
2004-08-02 10:35:01 +08:00
# define TEMP_VAR_STACK_LIMIT 2000
2003-08-19 07:11:58 +08:00
2006-12-25 22:16:27 +08:00
static inline void zend_pzval_unlock_func ( zval * z , zend_free_op * should_free , int unref )
2003-08-19 07:11:58 +08:00
{
2007-10-07 13:22:07 +08:00
if ( ! Z_DELREF_P ( z ) ) {
Z_SET_REFCOUNT_P ( z , 1 ) ;
Z_UNSET_ISREF_P ( z ) ;
2004-08-20 04:03:06 +08:00
should_free - > var = z ;
2004-09-24 05:43:32 +08:00
/* should_free->is_var = 1; */
2004-08-20 04:03:06 +08:00
} else {
should_free - > var = 0 ;
2007-10-07 13:22:07 +08:00
if ( unref & & Z_ISREF_P ( z ) & & Z_REFCOUNT_P ( z ) = = 1 ) {
Z_UNSET_ISREF_P ( z ) ;
2005-06-23 16:21:03 +08:00
}
2003-08-19 07:11:58 +08:00
}
}
2004-08-20 04:03:06 +08:00
static inline void zend_pzval_unlock_free_func ( zval * z )
2003-08-19 07:11:58 +08:00
{
2007-10-07 13:22:07 +08:00
if ( ! Z_DELREF_P ( z ) ) {
2004-08-20 04:03:06 +08:00
zval_dtor ( z ) ;
safe_free_zval_ptr ( z ) ;
2003-08-19 07:11:58 +08:00
}
}
2006-12-25 22:16:27 +08:00
# define PZVAL_UNLOCK(z, f) zend_pzval_unlock_func(z, f, 1)
# define PZVAL_UNLOCK_EX(z, f, u) zend_pzval_unlock_func(z, f, u)
2004-08-20 04:03:06 +08:00
# define PZVAL_UNLOCK_FREE(z) zend_pzval_unlock_free_func(z)
2007-10-07 13:22:07 +08:00
# define PZVAL_LOCK(z) Z_ADDREF_P((z))
2004-02-12 00:28:46 +08:00
# define RETURN_VALUE_UNUSED(pzn) (((pzn)->u.EA.type & EXT_TYPE_UNUSED))
# define SELECTIVE_PZVAL_LOCK(pzv, pzn) if (!RETURN_VALUE_UNUSED(pzn)) { PZVAL_LOCK(pzv); }
2004-08-20 04:03:06 +08:00
# define AI_USE_PTR(ai) \
if ( ( ai ) . ptr_ptr ) { \
( ai ) . ptr = * ( ( ai ) . ptr_ptr ) ; \
( ai ) . ptr_ptr = & ( ( ai ) . ptr ) ; \
} else { \
( ai ) . ptr = NULL ; \
}
2007-12-14 22:14:50 +08:00
# define AI_SET_PTR(ai, val) \
( ai ) . ptr = ( val ) ; \
( ai ) . ptr_ptr = & ( ( ai ) . ptr ) ;
2004-08-20 04:03:06 +08:00
# define FREE_OP(should_free) \
if ( should_free . var ) { \
2007-04-16 16:09:56 +08:00
if ( ( zend_uintptr_t ) should_free . var & 1L ) { \
zval_dtor ( ( zval * ) ( ( zend_uintptr_t ) should_free . var & ~ 1L ) ) ; \
2004-08-20 04:03:06 +08:00
} else { \
zval_ptr_dtor ( & should_free . var ) ; \
} \
}
2004-09-24 05:43:32 +08:00
# define FREE_OP_IF_VAR(should_free) \
2007-04-16 16:09:56 +08:00
if ( should_free . var ! = NULL & & ( ( ( zend_uintptr_t ) should_free . var & 1L ) = = 0 ) ) { \
2004-08-20 04:03:06 +08:00
zval_ptr_dtor ( & should_free . var ) ; \
}
# define FREE_OP_VAR_PTR(should_free) \
if ( should_free . var ) { \
zval_ptr_dtor ( & should_free . var ) ; \
}
2007-04-16 16:09:56 +08:00
# define TMP_FREE(z) (zval*)(((zend_uintptr_t)(z)) | 1L)
2004-09-24 05:43:32 +08:00
2007-04-16 16:09:56 +08:00
# define IS_TMP_FREE(should_free) ((zend_uintptr_t)should_free.var & 1L)
2004-09-24 05:43:32 +08:00
# define INIT_PZVAL_COPY(z,v) \
( z ) - > value = ( v ) - > value ; \
2006-05-10 07:53:23 +08:00
Z_TYPE_P ( z ) = Z_TYPE_P ( v ) ; \
2007-10-07 13:22:07 +08:00
Z_SET_REFCOUNT_P ( z , 1 ) ; \
Z_UNSET_ISREF_P ( z ) ;
2003-08-19 07:11:58 +08:00
2005-06-03 19:16:19 +08:00
# define MAKE_REAL_ZVAL_PTR(val) \
do { \
zval * _tmp ; \
ALLOC_ZVAL ( _tmp ) ; \
_tmp - > value = ( val ) - > value ; \
2006-05-10 07:53:23 +08:00
Z_TYPE_P ( _tmp ) = Z_TYPE_P ( val ) ; \
2007-10-07 13:22:07 +08:00
Z_SET_REFCOUNT_P ( _tmp , 1 ) ; \
Z_UNSET_ISREF_P ( _tmp ) ; \
2005-06-03 19:16:19 +08:00
val = _tmp ; \
} while ( 0 )
2003-08-19 07:11:58 +08:00
/* End of zend_execute_locks.h */
2004-10-05 03:54:35 +08:00
# define CV_OF(i) (EG(current_execute_data)->CVs[i])
# define CV_DEF_OF(i) (EG(active_op_array)->vars[i])
2007-09-29 15:28:34 +08:00
# define CTOR_CALL_BIT 0x1
# define CTOR_USED_BIT 0x2
# define IS_CTOR_CALL(ce) (((zend_uintptr_t)(ce)) & CTOR_CALL_BIT)
# define IS_CTOR_USED(ce) (((zend_uintptr_t)(ce)) & CTOR_USED_BIT)
# define ENCODE_CTOR(ce, used) \
( ( zend_class_entry * ) ( ( ( zend_uintptr_t ) ( ce ) ) | CTOR_CALL_BIT | ( ( used ) ? CTOR_USED_BIT : 0 ) ) )
# define DECODE_CTOR(ce) \
( ( zend_class_entry * ) ( ( ( zend_uintptr_t ) ( ce ) ) & ~ ( CTOR_CALL_BIT | CTOR_USED_BIT ) ) )
2005-01-22 10:29:18 +08:00
ZEND_API zval * * zend_get_compiled_variable_value ( zend_execute_data * execute_data_ptr , zend_uint var )
{
return execute_data_ptr - > CVs [ var ] ;
}
2004-10-05 03:54:35 +08:00
static inline void zend_get_cv_address ( zend_compiled_variable * cv , zval * * * ptr , temp_variable * Ts TSRMLS_DC )
{
2006-05-12 05:07:39 +08:00
zval * new_zval = & EG ( uninitialized_zval ) ;
2007-10-07 13:22:07 +08:00
Z_ADDREF_P ( new_zval ) ;
2006-05-12 05:07:39 +08:00
zend_hash_quick_update ( EG ( active_symbol_table ) , cv - > name , cv - > name_len + 1 , cv - > hash_value , & new_zval , sizeof ( zval * ) , ( void * * ) ptr ) ;
2004-10-05 03:54:35 +08:00
}
2005-06-14 01:50:07 +08:00
static inline zval * _get_zval_ptr_tmp ( znode * node , temp_variable * Ts , zend_free_op * should_free TSRMLS_DC )
{
return should_free - > var = & T ( node - > u . var ) . tmp_var ;
}
2005-03-24 05:05:56 +08:00
static inline zval * _get_zval_ptr_var ( znode * node , temp_variable * Ts , zend_free_op * should_free TSRMLS_DC )
{
2005-06-14 01:50:07 +08:00
zval * ptr = T ( node - > u . var ) . var . ptr ;
if ( ptr ) {
PZVAL_UNLOCK ( ptr , should_free ) ;
return ptr ;
2005-03-24 05:05:56 +08:00
} else {
temp_variable * T = & T ( node - > u . var ) ;
zval * str = T - > str_offset . str ;
/* string offset */
ALLOC_ZVAL ( ptr ) ;
T - > str_offset . ptr = ptr ;
should_free - > var = ptr ;
if ( T - > str_offset . str - > type ! = IS_STRING
2006-02-26 18:57:00 +08:00
| | ( ( int ) T - > str_offset . offset < 0 )
| | ( T - > str_offset . str - > value . str . len < = ( int ) T - > str_offset . offset ) ) {
2005-03-24 05:05:56 +08:00
zend_error ( E_NOTICE , " Uninitialized string offset: %d " , T - > str_offset . offset ) ;
ptr - > value . str . val = STR_EMPTY_ALLOC ( ) ;
ptr - > value . str . len = 0 ;
} else {
2007-12-14 22:14:50 +08:00
ptr - > value . str . val = estrndup ( str - > value . str . val + T - > str_offset . offset , 1 ) ;
2005-03-24 05:05:56 +08:00
ptr - > value . str . len = 1 ;
}
PZVAL_UNLOCK_FREE ( str ) ;
2007-10-07 13:22:07 +08:00
Z_SET_REFCOUNT_P ( ptr , 1 ) ;
Z_SET_ISREF_P ( ptr ) ;
2005-03-24 05:05:56 +08:00
ptr - > type = IS_STRING ;
return ptr ;
}
}
2005-06-14 01:50:07 +08:00
static inline zval * _get_zval_ptr_cv ( znode * node , temp_variable * Ts , int type TSRMLS_DC )
2004-10-05 03:54:35 +08:00
{
zval * * * ptr = & CV_OF ( node - > u . var ) ;
2006-05-10 07:53:23 +08:00
2004-10-05 03:54:35 +08:00
if ( ! * ptr ) {
zend_compiled_variable * cv = & CV_DEF_OF ( node - > u . var ) ;
if ( zend_hash_quick_find ( EG ( active_symbol_table ) , cv - > name , cv - > name_len + 1 , cv - > hash_value , ( void * * ) ptr ) = = FAILURE ) {
switch ( type ) {
case BP_VAR_R :
2004-10-05 17:09:18 +08:00
case BP_VAR_UNSET :
2004-12-27 21:43:26 +08:00
zend_error ( E_NOTICE , " Undefined variable: %s " , cv - > name ) ;
2004-10-05 03:54:35 +08:00
/* break missing intentionally */
case BP_VAR_IS :
return & EG ( uninitialized_zval ) ;
break ;
case BP_VAR_RW :
2004-12-27 21:43:26 +08:00
zend_error ( E_NOTICE , " Undefined variable: %s " , cv - > name ) ;
2004-10-05 03:54:35 +08:00
/* break missing intentionally */
case BP_VAR_W :
zend_get_cv_address ( cv , ptr , Ts TSRMLS_CC ) ;
break ;
}
}
}
return * * ptr ;
}
2005-06-14 01:50:07 +08:00
static inline zval * _get_zval_ptr ( znode * node , temp_variable * Ts , zend_free_op * should_free , int type TSRMLS_DC )
2004-09-24 05:43:32 +08:00
{
2005-06-14 01:50:07 +08:00
/* should_free->is_var = 0; */
switch ( node - > op_type ) {
case IS_CONST :
should_free - > var = 0 ;
return & node - > u . constant ;
break ;
case IS_TMP_VAR :
should_free - > var = TMP_FREE ( & T ( node - > u . var ) . tmp_var ) ;
return & T ( node - > u . var ) . tmp_var ;
break ;
case IS_VAR :
return _get_zval_ptr_var ( node , Ts , should_free TSRMLS_CC ) ;
break ;
case IS_UNUSED :
should_free - > var = 0 ;
return NULL ;
break ;
case IS_CV :
should_free - > var = 0 ;
return _get_zval_ptr_cv ( node , Ts , type TSRMLS_CC ) ;
break ;
EMPTY_SWITCH_DEFAULT_CASE ( )
}
2004-09-24 05:43:32 +08:00
return NULL ;
}
static inline zval * * _get_zval_ptr_ptr_var ( znode * node , temp_variable * Ts , zend_free_op * should_free TSRMLS_DC )
{
2005-06-14 01:50:07 +08:00
zval * * ptr_ptr = T ( node - > u . var ) . var . ptr_ptr ;
if ( ptr_ptr ) {
PZVAL_UNLOCK ( * ptr_ptr , should_free ) ;
2003-10-05 15:52:28 +08:00
} else {
2004-09-24 05:43:32 +08:00
/* string offset */
PZVAL_UNLOCK ( T ( node - > u . var ) . str_offset . str , should_free ) ;
2002-03-10 21:42:37 +08:00
}
2005-06-14 01:50:07 +08:00
return ptr_ptr ;
2004-09-24 05:43:32 +08:00
}
2005-06-14 01:50:07 +08:00
static inline zval * * _get_zval_ptr_ptr_cv ( znode * node , temp_variable * Ts , int type TSRMLS_DC )
2004-10-05 03:54:35 +08:00
{
zval * * * ptr = & CV_OF ( node - > u . var ) ;
2006-05-10 07:53:23 +08:00
2004-10-05 03:54:35 +08:00
if ( ! * ptr ) {
zend_compiled_variable * cv = & CV_DEF_OF ( node - > u . var ) ;
if ( zend_hash_quick_find ( EG ( active_symbol_table ) , cv - > name , cv - > name_len + 1 , cv - > hash_value , ( void * * ) ptr ) = = FAILURE ) {
switch ( type ) {
case BP_VAR_R :
2004-10-05 17:09:18 +08:00
case BP_VAR_UNSET :
2004-12-27 21:43:26 +08:00
zend_error ( E_NOTICE , " Undefined variable: %s " , cv - > name ) ;
2004-10-05 03:54:35 +08:00
/* break missing intentionally */
case BP_VAR_IS :
return & EG ( uninitialized_zval_ptr ) ;
break ;
case BP_VAR_RW :
2004-12-27 21:43:26 +08:00
zend_error ( E_NOTICE , " Undefined variable: %s " , cv - > name ) ;
2004-10-05 03:54:35 +08:00
/* break missing intentionally */
case BP_VAR_W :
zend_get_cv_address ( cv , ptr , Ts TSRMLS_CC ) ;
break ;
}
}
}
return * ptr ;
}
2005-06-14 01:50:07 +08:00
static inline zval * * _get_zval_ptr_ptr ( znode * node , temp_variable * Ts , zend_free_op * should_free , int type TSRMLS_DC )
2004-10-05 03:54:35 +08:00
{
2005-06-14 01:50:07 +08:00
if ( node - > op_type = = IS_CV ) {
should_free - > var = 0 ;
return _get_zval_ptr_ptr_cv ( node , Ts , type TSRMLS_CC ) ;
} else if ( node - > op_type = = IS_VAR ) {
return _get_zval_ptr_ptr_var ( node , Ts , should_free TSRMLS_CC ) ;
} else {
should_free - > var = 0 ;
return NULL ;
}
2004-10-05 03:54:35 +08:00
}
2005-06-14 01:50:07 +08:00
static inline zval * _get_obj_zval_ptr_unused ( TSRMLS_D )
2004-09-24 05:43:32 +08:00
{
if ( EG ( This ) ) {
return EG ( This ) ;
} else {
zend_error_noreturn ( E_ERROR , " Using $this when not in object context " ) ;
return NULL ;
1999-04-08 02:10:10 +08:00
}
}
2005-06-14 01:50:07 +08:00
static inline zval * * _get_obj_zval_ptr_ptr ( znode * op , temp_variable * Ts , zend_free_op * should_free , int type TSRMLS_DC )
2004-10-05 03:54:35 +08:00
{
2005-06-14 01:50:07 +08:00
if ( op - > op_type = = IS_UNUSED ) {
if ( EG ( This ) ) {
/* this should actually never be modified, _ptr_ptr is modified only when
the object is empty */
should_free - > var = 0 ;
return & EG ( This ) ;
} else {
zend_error_noreturn ( E_ERROR , " Using $this when not in object context " ) ;
}
}
return get_zval_ptr_ptr ( op , Ts , should_free , type ) ;
2004-10-05 03:54:35 +08:00
}
2005-06-14 01:50:07 +08:00
static inline zval * * _get_obj_zval_ptr_ptr_unused ( TSRMLS_D )
2004-09-24 05:43:32 +08:00
{
if ( EG ( This ) ) {
return & EG ( This ) ;
} else {
zend_error_noreturn ( E_ERROR , " Using $this when not in object context " ) ;
return NULL ;
}
}
1999-12-23 02:10:38 +08:00
2005-06-14 01:50:07 +08:00
static inline zval * _get_obj_zval_ptr ( znode * op , temp_variable * Ts , zend_free_op * should_free , int type TSRMLS_DC )
{
if ( op - > op_type = = IS_UNUSED ) {
if ( EG ( This ) ) {
should_free - > var = 0 ;
return EG ( This ) ;
} else {
zend_error_noreturn ( E_ERROR , " Using $this when not in object context " ) ;
}
}
return get_zval_ptr ( op , Ts , should_free , type ) ;
}
2007-12-14 22:14:50 +08:00
static inline void zend_switch_free ( temp_variable * T , int type , int extended_value TSRMLS_DC )
1999-12-23 02:10:38 +08:00
{
2007-12-14 22:14:50 +08:00
if ( type = = IS_VAR ) {
if ( T - > var . ptr ) {
if ( extended_value & ZEND_FE_RESET_VARIABLE ) { /* foreach() free */
Z_DELREF_P ( T - > var . ptr ) ;
1999-12-23 02:10:38 +08:00
}
2007-12-14 22:14:50 +08:00
zval_ptr_dtor ( & T - > var . ptr ) ;
} else if ( ! T - > var . ptr_ptr ) {
/* perform the equivalent of equivalent of a
* quick & silent get_zval_ptr , and FREE_OP
*/
PZVAL_UNLOCK_FREE ( T - > str_offset . str ) ;
}
} else { /* IS_TMP_VAR */
zendi_zval_dtor ( T - > tmp_var ) ;
1999-12-23 02:10:38 +08:00
}
}
2004-09-24 05:43:32 +08:00
static void zend_assign_to_variable_reference ( zval * * variable_ptr_ptr , zval * * value_ptr_ptr TSRMLS_DC )
2001-06-22 05:17:10 +08:00
{
zval * variable_ptr ;
zval * value_ptr ;
if ( ! value_ptr_ptr | | ! variable_ptr_ptr ) {
2004-09-24 05:43:32 +08:00
zend_error_noreturn ( E_ERROR , " Cannot create references to/from string offsets nor overloaded objects " ) ;
2001-06-22 05:17:10 +08:00
return ;
}
variable_ptr = * variable_ptr_ptr ;
value_ptr = * value_ptr_ptr ;
if ( variable_ptr = = EG ( error_zval_ptr ) | | value_ptr = = EG ( error_zval_ptr ) ) {
variable_ptr_ptr = & EG ( uninitialized_zval_ptr ) ;
2003-02-17 03:18:23 +08:00
} else if ( variable_ptr ! = value_ptr ) {
2001-06-22 05:17:10 +08:00
if ( ! PZVAL_IS_REF ( value_ptr ) ) {
/* break it away */
2007-10-07 13:22:07 +08:00
Z_DELREF_P ( value_ptr ) ;
if ( Z_REFCOUNT_P ( value_ptr ) > 0 ) {
2001-06-22 05:17:10 +08:00
ALLOC_ZVAL ( * value_ptr_ptr ) ;
* * value_ptr_ptr = * value_ptr ;
value_ptr = * value_ptr_ptr ;
zendi_zval_copy_ctor ( * value_ptr ) ;
}
2007-10-07 13:22:07 +08:00
Z_SET_REFCOUNT_P ( value_ptr , 1 ) ;
Z_SET_ISREF_P ( value_ptr ) ;
2001-06-22 05:17:10 +08:00
}
* variable_ptr_ptr = value_ptr ;
2007-10-07 13:22:07 +08:00
Z_ADDREF_P ( value_ptr ) ;
2005-09-01 21:21:37 +08:00
2006-11-08 04:23:30 +08:00
zval_ptr_dtor ( & variable_ptr ) ;
2007-10-07 13:22:07 +08:00
} else if ( ! Z_ISREF_P ( variable_ptr ) ) {
2003-02-17 03:18:23 +08:00
if ( variable_ptr_ptr = = value_ptr_ptr ) {
2003-02-17 02:34:48 +08:00
SEPARATE_ZVAL ( variable_ptr_ptr ) ;
2003-02-17 03:18:23 +08:00
} else if ( variable_ptr = = EG ( uninitialized_zval_ptr )
2007-10-07 13:22:07 +08:00
| | Z_REFCOUNT_P ( variable_ptr ) > 2 ) {
2003-02-17 03:18:23 +08:00
/* we need to separate */
2007-10-07 13:22:07 +08:00
Z_SET_REFCOUNT_P ( variable_ptr , Z_REFCOUNT_P ( variable_ptr ) - 2 ) ;
2003-02-17 03:18:23 +08:00
ALLOC_ZVAL ( * variable_ptr_ptr ) ;
* * variable_ptr_ptr = * variable_ptr ;
zval_copy_ctor ( * variable_ptr_ptr ) ;
* value_ptr_ptr = * variable_ptr_ptr ;
2007-10-07 13:22:07 +08:00
Z_SET_REFCOUNT_PP ( variable_ptr_ptr , 2 ) ;
2001-06-22 05:17:10 +08:00
}
2007-10-07 13:22:07 +08:00
Z_SET_ISREF_PP ( variable_ptr_ptr ) ;
2001-06-22 05:17:10 +08:00
}
}
2007-07-19 23:29:30 +08:00
/* this should modify object only if it's empty */
2002-03-11 05:02:00 +08:00
static inline void make_real_object ( zval * * object_ptr TSRMLS_DC )
{
2006-05-12 05:07:39 +08:00
if ( Z_TYPE_PP ( object_ptr ) = = IS_NULL
2007-07-19 23:29:30 +08:00
| | ( Z_TYPE_PP ( object_ptr ) = = IS_BOOL & & Z_LVAL_PP ( object_ptr ) = = 0 )
| | ( Z_TYPE_PP ( object_ptr ) = = IS_STRING & & Z_STRLEN_PP ( object_ptr ) = = 0 )
) {
2003-12-01 20:35:46 +08:00
zend_error ( E_STRICT , " Creating default object from empty value " ) ;
2007-07-19 23:29:30 +08:00
SEPARATE_ZVAL_IF_NOT_REF ( object_ptr ) ;
2005-12-22 17:16:11 +08:00
zval_dtor ( * object_ptr ) ;
2002-03-10 21:42:37 +08:00
object_init ( * object_ptr ) ;
}
}
2002-10-17 02:06:36 +08:00
2007-10-01 18:37:14 +08:00
static inline char * zend_verify_arg_class_kind ( const zend_arg_info * cur_arg_info , ulong fetch_type , const char * * class_name , zend_class_entry * * pce TSRMLS_DC )
2006-05-26 08:36:13 +08:00
{
2007-10-01 18:37:14 +08:00
* pce = zend_fetch_class ( cur_arg_info - > class_name , cur_arg_info - > class_name_len , ( fetch_type | ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD ) TSRMLS_CC ) ;
2006-05-26 08:36:13 +08:00
2006-10-02 19:09:52 +08:00
* class_name = ( * pce ) ? ( * pce ) - > name : cur_arg_info - > class_name ;
if ( * pce & & ( * pce ) - > ce_flags & ZEND_ACC_INTERFACE ) {
2006-05-26 08:36:13 +08:00
return " implement interface " ;
} else {
return " be an instance of " ;
}
}
2007-09-28 02:00:48 +08:00
static inline int zend_verify_arg_error ( zend_function * zf , zend_uint arg_num , const zend_arg_info * cur_arg_info , const char * need_msg , const char * need_kind , char * given_msg , char * given_kind TSRMLS_DC )
2006-05-26 08:36:13 +08:00
{
zend_execute_data * ptr = EG ( current_execute_data ) - > prev_execute_data ;
char * fname = zf - > common . function_name ;
char * fsep ;
char * fclass ;
if ( zf - > common . scope ) {
fsep = " :: " ;
fclass = zf - > common . scope - > name ;
} else {
fsep = " " ;
fclass = " " ;
}
if ( ptr & & ptr - > op_array ) {
zend_error ( E_RECOVERABLE_ERROR , " Argument %d passed to %s%s%s() must %s%s, %s%s given, called in %s on line %d and defined " , arg_num , fclass , fsep , fname , need_msg , need_kind , given_msg , given_kind , ptr - > op_array - > filename , ptr - > opline - > lineno ) ;
} else {
zend_error ( E_RECOVERABLE_ERROR , " Argument %d passed to %s%s%s() must %s%s, %s%s given " , arg_num , fclass , fsep , fname , need_msg , need_kind , given_msg , given_kind ) ;
}
return 0 ;
}
2007-10-01 18:37:14 +08:00
static inline int zend_verify_arg_type ( zend_function * zf , zend_uint arg_num , zval * arg , ulong fetch_type TSRMLS_DC )
ntroduce infrastructure for supplying information about arguments,
including:
- Whether or not to pass by ref (replaces the old arg_types, with arg_info)
- Argument name (for future use, maybe introspection)
- Class/Interface name (for type hints)
- If a class/interface name is available, whether to allow a null instance
Both user and builtin functions share the same data structures.
To declare a builtin function that expects its first arg to be an instance
of class 'Person', its second argument as a regular arg, and its third by
reference, use:
ZEND_BEGIN_ARG_INFO(my_func_arg_info, 0)
ZEND_ARG_OBJ_INFO(0, someone, Person, 1)
ZEND_ARG_PASS_INFO(0)
ZEND_ARG_PASS_INFO(1)
ZEND_END_ARG_INFO();
and use my_func_arg_info as the arg_info parameter to the ZEND_FE() family
of macros.
The first arg to each ZEND_ARG_*() macro is whether or not to pass by ref.
The boolean arg to ZEND_BEGIN_ARG_INFO() tells the engine whether to treat
the arguments for which there's no explicit information as pass by reference
or not.
The boolean argument to ZEND_ARG_OBJ_INFO() (4th arg) is whether or not to allownull values.
2003-08-04 01:40:44 +08:00
{
zend_arg_info * cur_arg_info ;
2006-05-26 08:36:13 +08:00
char * need_msg ;
2006-05-22 02:10:31 +08:00
zend_class_entry * ce ;
ntroduce infrastructure for supplying information about arguments,
including:
- Whether or not to pass by ref (replaces the old arg_types, with arg_info)
- Argument name (for future use, maybe introspection)
- Class/Interface name (for type hints)
- If a class/interface name is available, whether to allow a null instance
Both user and builtin functions share the same data structures.
To declare a builtin function that expects its first arg to be an instance
of class 'Person', its second argument as a regular arg, and its third by
reference, use:
ZEND_BEGIN_ARG_INFO(my_func_arg_info, 0)
ZEND_ARG_OBJ_INFO(0, someone, Person, 1)
ZEND_ARG_PASS_INFO(0)
ZEND_ARG_PASS_INFO(1)
ZEND_END_ARG_INFO();
and use my_func_arg_info as the arg_info parameter to the ZEND_FE() family
of macros.
The first arg to each ZEND_ARG_*() macro is whether or not to pass by ref.
The boolean arg to ZEND_BEGIN_ARG_INFO() tells the engine whether to treat
the arguments for which there's no explicit information as pass by reference
or not.
The boolean argument to ZEND_ARG_OBJ_INFO() (4th arg) is whether or not to allownull values.
2003-08-04 01:40:44 +08:00
if ( ! zf - > common . arg_info
| | arg_num > zf - > common . num_args ) {
2006-05-10 07:53:23 +08:00
return 1 ;
ntroduce infrastructure for supplying information about arguments,
including:
- Whether or not to pass by ref (replaces the old arg_types, with arg_info)
- Argument name (for future use, maybe introspection)
- Class/Interface name (for type hints)
- If a class/interface name is available, whether to allow a null instance
Both user and builtin functions share the same data structures.
To declare a builtin function that expects its first arg to be an instance
of class 'Person', its second argument as a regular arg, and its third by
reference, use:
ZEND_BEGIN_ARG_INFO(my_func_arg_info, 0)
ZEND_ARG_OBJ_INFO(0, someone, Person, 1)
ZEND_ARG_PASS_INFO(0)
ZEND_ARG_PASS_INFO(1)
ZEND_END_ARG_INFO();
and use my_func_arg_info as the arg_info parameter to the ZEND_FE() family
of macros.
The first arg to each ZEND_ARG_*() macro is whether or not to pass by ref.
The boolean arg to ZEND_BEGIN_ARG_INFO() tells the engine whether to treat
the arguments for which there's no explicit information as pass by reference
or not.
The boolean argument to ZEND_ARG_OBJ_INFO() (4th arg) is whether or not to allownull values.
2003-08-04 01:40:44 +08:00
}
cur_arg_info = & zf - > common . arg_info [ arg_num - 1 ] ;
if ( cur_arg_info - > class_name ) {
2007-09-28 02:00:48 +08:00
const char * class_name ;
2006-10-02 19:09:52 +08:00
ntroduce infrastructure for supplying information about arguments,
including:
- Whether or not to pass by ref (replaces the old arg_types, with arg_info)
- Argument name (for future use, maybe introspection)
- Class/Interface name (for type hints)
- If a class/interface name is available, whether to allow a null instance
Both user and builtin functions share the same data structures.
To declare a builtin function that expects its first arg to be an instance
of class 'Person', its second argument as a regular arg, and its third by
reference, use:
ZEND_BEGIN_ARG_INFO(my_func_arg_info, 0)
ZEND_ARG_OBJ_INFO(0, someone, Person, 1)
ZEND_ARG_PASS_INFO(0)
ZEND_ARG_PASS_INFO(1)
ZEND_END_ARG_INFO();
and use my_func_arg_info as the arg_info parameter to the ZEND_FE() family
of macros.
The first arg to each ZEND_ARG_*() macro is whether or not to pass by ref.
The boolean arg to ZEND_BEGIN_ARG_INFO() tells the engine whether to treat
the arguments for which there's no explicit information as pass by reference
or not.
The boolean argument to ZEND_ARG_OBJ_INFO() (4th arg) is whether or not to allownull values.
2003-08-04 01:40:44 +08:00
if ( ! arg ) {
2007-10-01 18:37:14 +08:00
need_msg = zend_verify_arg_class_kind ( cur_arg_info , fetch_type , & class_name , & ce TSRMLS_CC ) ;
2006-10-02 19:09:52 +08:00
return zend_verify_arg_error ( zf , arg_num , cur_arg_info , need_msg , class_name , " none " , " " TSRMLS_CC ) ;
ntroduce infrastructure for supplying information about arguments,
including:
- Whether or not to pass by ref (replaces the old arg_types, with arg_info)
- Argument name (for future use, maybe introspection)
- Class/Interface name (for type hints)
- If a class/interface name is available, whether to allow a null instance
Both user and builtin functions share the same data structures.
To declare a builtin function that expects its first arg to be an instance
of class 'Person', its second argument as a regular arg, and its third by
reference, use:
ZEND_BEGIN_ARG_INFO(my_func_arg_info, 0)
ZEND_ARG_OBJ_INFO(0, someone, Person, 1)
ZEND_ARG_PASS_INFO(0)
ZEND_ARG_PASS_INFO(1)
ZEND_END_ARG_INFO();
and use my_func_arg_info as the arg_info parameter to the ZEND_FE() family
of macros.
The first arg to each ZEND_ARG_*() macro is whether or not to pass by ref.
The boolean arg to ZEND_BEGIN_ARG_INFO() tells the engine whether to treat
the arguments for which there's no explicit information as pass by reference
or not.
The boolean argument to ZEND_ARG_OBJ_INFO() (4th arg) is whether or not to allownull values.
2003-08-04 01:40:44 +08:00
}
2006-05-26 08:36:13 +08:00
if ( Z_TYPE_P ( arg ) = = IS_OBJECT ) {
2007-10-01 18:37:14 +08:00
need_msg = zend_verify_arg_class_kind ( cur_arg_info , fetch_type , & class_name , & ce TSRMLS_CC ) ;
2006-10-02 19:09:52 +08:00
if ( ! ce | | ! instanceof_function ( Z_OBJCE_P ( arg ) , ce TSRMLS_CC ) ) {
return zend_verify_arg_error ( zf , arg_num , cur_arg_info , need_msg , class_name , " instance of " , Z_OBJCE_P ( arg ) - > name TSRMLS_CC ) ;
2006-05-22 02:10:31 +08:00
}
2006-05-26 08:36:13 +08:00
} else if ( Z_TYPE_P ( arg ) ! = IS_NULL | | ! cur_arg_info - > allow_null ) {
2007-10-01 18:37:14 +08:00
need_msg = zend_verify_arg_class_kind ( cur_arg_info , fetch_type , & class_name , & ce TSRMLS_CC ) ;
2006-10-02 19:09:52 +08:00
return zend_verify_arg_error ( zf , arg_num , cur_arg_info , need_msg , class_name , zend_zval_type_name ( arg ) , " " TSRMLS_CC ) ;
ntroduce infrastructure for supplying information about arguments,
including:
- Whether or not to pass by ref (replaces the old arg_types, with arg_info)
- Argument name (for future use, maybe introspection)
- Class/Interface name (for type hints)
- If a class/interface name is available, whether to allow a null instance
Both user and builtin functions share the same data structures.
To declare a builtin function that expects its first arg to be an instance
of class 'Person', its second argument as a regular arg, and its third by
reference, use:
ZEND_BEGIN_ARG_INFO(my_func_arg_info, 0)
ZEND_ARG_OBJ_INFO(0, someone, Person, 1)
ZEND_ARG_PASS_INFO(0)
ZEND_ARG_PASS_INFO(1)
ZEND_END_ARG_INFO();
and use my_func_arg_info as the arg_info parameter to the ZEND_FE() family
of macros.
The first arg to each ZEND_ARG_*() macro is whether or not to pass by ref.
The boolean arg to ZEND_BEGIN_ARG_INFO() tells the engine whether to treat
the arguments for which there's no explicit information as pass by reference
or not.
The boolean argument to ZEND_ARG_OBJ_INFO() (4th arg) is whether or not to allownull values.
2003-08-04 01:40:44 +08:00
}
2005-09-15 21:10:31 +08:00
} else if ( cur_arg_info - > array_type_hint ) {
2005-05-26 21:46:17 +08:00
if ( ! arg ) {
2006-05-26 08:36:13 +08:00
return zend_verify_arg_error ( zf , arg_num , cur_arg_info , " be an array " , " " , " none " , " " TSRMLS_CC ) ;
2005-05-26 21:46:17 +08:00
}
2006-05-26 08:36:13 +08:00
if ( Z_TYPE_P ( arg ) ! = IS_ARRAY & & ( Z_TYPE_P ( arg ) ! = IS_NULL | | ! cur_arg_info - > allow_null ) ) {
return zend_verify_arg_error ( zf , arg_num , cur_arg_info , " be an array " , " " , zend_zval_type_name ( arg ) , " " TSRMLS_CC ) ;
2005-05-26 21:46:17 +08:00
}
}
2006-05-10 07:53:23 +08:00
return 1 ;
ntroduce infrastructure for supplying information about arguments,
including:
- Whether or not to pass by ref (replaces the old arg_types, with arg_info)
- Argument name (for future use, maybe introspection)
- Class/Interface name (for type hints)
- If a class/interface name is available, whether to allow a null instance
Both user and builtin functions share the same data structures.
To declare a builtin function that expects its first arg to be an instance
of class 'Person', its second argument as a regular arg, and its third by
reference, use:
ZEND_BEGIN_ARG_INFO(my_func_arg_info, 0)
ZEND_ARG_OBJ_INFO(0, someone, Person, 1)
ZEND_ARG_PASS_INFO(0)
ZEND_ARG_PASS_INFO(1)
ZEND_END_ARG_INFO();
and use my_func_arg_info as the arg_info parameter to the ZEND_FE() family
of macros.
The first arg to each ZEND_ARG_*() macro is whether or not to pass by ref.
The boolean arg to ZEND_BEGIN_ARG_INFO() tells the engine whether to treat
the arguments for which there's no explicit information as pass by reference
or not.
The boolean argument to ZEND_ARG_OBJ_INFO() (4th arg) is whether or not to allownull values.
2003-08-04 01:40:44 +08:00
}
2004-09-24 05:43:32 +08:00
2007-12-14 22:14:50 +08:00
static inline void zend_assign_to_object ( znode * result , zval * * object_ptr , zval * property_name , znode * value_op , temp_variable * Ts , int opcode TSRMLS_DC )
2002-03-10 21:42:37 +08:00
{
zval * object ;
2007-12-14 22:14:50 +08:00
zend_free_op free_value ;
2003-01-27 23:13:01 +08:00
zval * value = get_zval_ptr ( value_op , Ts , & free_value , BP_VAR_R ) ;
2002-10-24 04:26:28 +08:00
zval * * retval = & T ( result - > u . var ) . var . ptr ;
2002-03-10 21:42:37 +08:00
2007-06-27 16:51:40 +08:00
if ( ! object_ptr ) {
zend_error_noreturn ( E_ERROR , " Cannot use string offset as an array " ) ;
}
2007-12-14 22:14:50 +08:00
if ( Z_TYPE_P ( * object_ptr ) ! = IS_OBJECT ) {
if ( * object_ptr = = EG ( error_zval_ptr ) ) {
if ( ! RETURN_VALUE_UNUSED ( result ) ) {
* retval = EG ( uninitialized_zval_ptr ) ;
PZVAL_LOCK ( * retval ) ;
}
FREE_OP ( free_value ) ;
return ;
2006-01-19 15:23:32 +08:00
}
2007-12-14 22:14:50 +08:00
if ( Z_TYPE_PP ( object_ptr ) = = IS_NULL | |
( Z_TYPE_PP ( object_ptr ) = = IS_BOOL & & Z_LVAL_PP ( object_ptr ) = = 0 ) | |
( Z_TYPE_PP ( object_ptr ) = = IS_STRING & & Z_STRLEN_PP ( object_ptr ) = = 0 ) ) {
zend_error ( E_STRICT , " Creating default object from empty value " ) ;
SEPARATE_ZVAL_IF_NOT_REF ( object_ptr ) ;
zval_dtor ( * object_ptr ) ;
object_init ( * object_ptr ) ;
} else {
zend_error ( E_WARNING , " Attempt to assign property of non-object " ) ;
if ( ! RETURN_VALUE_UNUSED ( result ) ) {
* retval = EG ( uninitialized_zval_ptr ) ;
PZVAL_LOCK ( * retval ) ;
}
FREE_OP ( free_value ) ;
return ;
2004-08-20 04:03:06 +08:00
}
2002-03-10 21:42:37 +08:00
}
2006-06-05 21:58:52 +08:00
2002-03-10 21:42:37 +08:00
/* here we are sure we are dealing with an object */
2007-12-14 22:14:50 +08:00
object = * object_ptr ;
2003-01-29 16:55:12 +08:00
/* separate our value if necessary */
2006-06-05 21:58:52 +08:00
if ( EG ( ze1_compatibility_mode ) & & Z_TYPE_P ( value ) = = IS_OBJECT ) {
zval * orig_value = value ;
char * class_name ;
zend_uint class_name_len ;
int dup ;
ALLOC_ZVAL ( value ) ;
* value = * orig_value ;
2007-10-07 13:22:07 +08:00
Z_UNSET_ISREF_P ( value ) ;
Z_SET_REFCOUNT_P ( value , 0 ) ;
2006-06-05 21:58:52 +08:00
dup = zend_get_object_classname ( orig_value , & class_name , & class_name_len TSRMLS_CC ) ;
if ( Z_OBJ_HANDLER_P ( value , clone_obj ) = = NULL ) {
zend_error_noreturn ( E_ERROR , " Trying to clone an uncloneable object of class %s " , class_name ) ;
}
zend_error ( E_STRICT , " Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode' " , class_name ) ;
value - > value . obj = Z_OBJ_HANDLER_P ( orig_value , clone_obj ) ( orig_value TSRMLS_CC ) ;
if ( ! dup ) {
efree ( class_name ) ;
}
} else if ( value_op - > op_type = = IS_TMP_VAR ) {
2003-01-29 16:55:12 +08:00
zval * orig_value = value ;
ALLOC_ZVAL ( value ) ;
* value = * orig_value ;
2007-10-07 13:22:07 +08:00
Z_UNSET_ISREF_P ( value ) ;
Z_SET_REFCOUNT_P ( value , 0 ) ;
2004-02-12 03:12:16 +08:00
} else if ( value_op - > op_type = = IS_CONST ) {
zval * orig_value = value ;
ALLOC_ZVAL ( value ) ;
* value = * orig_value ;
2007-10-07 13:22:07 +08:00
Z_UNSET_ISREF_P ( value ) ;
Z_SET_REFCOUNT_P ( value , 0 ) ;
2004-02-12 03:12:16 +08:00
zval_copy_ctor ( value ) ;
2003-01-29 16:55:12 +08:00
}
2006-05-10 07:53:23 +08:00
2004-02-12 03:12:16 +08:00
2007-10-07 13:22:07 +08:00
Z_ADDREF_P ( value ) ;
2003-07-07 17:00:36 +08:00
if ( opcode = = ZEND_ASSIGN_OBJ ) {
2007-12-14 22:14:50 +08:00
if ( ! Z_OBJ_HT_P ( object ) - > write_property ) {
zend_error ( E_WARNING , " Attempt to assign property of non-object " ) ;
if ( ! RETURN_VALUE_UNUSED ( result ) ) {
* retval = EG ( uninitialized_zval_ptr ) ;
PZVAL_LOCK ( * retval ) ;
}
FREE_OP ( free_value ) ;
return ;
2004-02-11 23:56:13 +08:00
}
Z_OBJ_HT_P ( object ) - > write_property ( object , property_name , value TSRMLS_CC ) ;
2003-07-07 17:00:36 +08:00
} else {
2004-02-11 23:56:13 +08:00
/* Note: property_name in this case is really the array index! */
2003-07-31 01:12:06 +08:00
if ( ! Z_OBJ_HT_P ( object ) - > write_dimension ) {
2004-09-24 05:43:32 +08:00
zend_error_noreturn ( E_ERROR , " Cannot use object as array " ) ;
2003-07-31 01:12:06 +08:00
}
2004-02-11 23:56:13 +08:00
Z_OBJ_HT_P ( object ) - > write_dimension ( object , property_name , value TSRMLS_CC ) ;
2002-03-10 21:42:37 +08:00
}
2006-05-10 07:53:23 +08:00
2007-12-14 22:14:50 +08:00
if ( ! RETURN_VALUE_UNUSED ( result ) & & ! EG ( exception ) ) {
AI_SET_PTR ( T ( result - > u . var ) . var , value ) ;
2004-08-20 04:03:06 +08:00
PZVAL_LOCK ( value ) ;
2002-03-10 21:42:37 +08:00
}
2004-03-18 22:03:58 +08:00
zval_ptr_dtor ( & value ) ;
2004-09-24 05:43:32 +08:00
FREE_OP_IF_VAR ( free_value ) ;
2002-03-10 21:42:37 +08:00
}
2007-12-14 22:14:50 +08:00
static inline void zend_assign_to_string_offset ( temp_variable * T , zval * value , int value_type TSRMLS_DC )
1999-04-08 02:10:10 +08:00
{
2007-12-14 22:14:50 +08:00
if ( Z_TYPE_P ( T - > str_offset . str ) = = IS_STRING ) {
1999-04-08 02:10:10 +08:00
2007-12-14 22:14:50 +08:00
if ( ( ( int ) T - > str_offset . offset < 0 ) ) {
zend_error ( E_WARNING , " Illegal string offset: %d " , T - > str_offset . offset ) ;
return ;
}
1999-04-08 02:10:10 +08:00
2008-01-11 23:10:24 +08:00
if ( T - > str_offset . offset > = Z_STRLEN_P ( T - > str_offset . str ) ) {
Z_STRVAL_P ( T - > str_offset . str ) = ( char * ) erealloc ( Z_STRVAL_P ( T - > str_offset . str ) , T - > str_offset . offset + 1 + 1 ) ;
memset ( Z_STRVAL_P ( T - > str_offset . str ) + Z_STRLEN_P ( T - > str_offset . str ) ,
' ' ,
T - > str_offset . offset - Z_STRLEN_P ( T - > str_offset . str ) ) ;
2007-12-14 22:14:50 +08:00
Z_STRVAL_P ( T - > str_offset . str ) [ T - > str_offset . offset + 1 ] = 0 ;
Z_STRLEN_P ( T - > str_offset . str ) = T - > str_offset . offset + 1 ;
}
1999-04-08 02:10:10 +08:00
2008-01-11 23:10:24 +08:00
if ( Z_TYPE_P ( value ) ! = IS_STRING ) {
zval tmp = * value ;
if ( value_type ! = IS_TMP_VAR ) {
2007-12-14 22:14:50 +08:00
zval_copy_ctor ( & tmp ) ;
2003-12-14 20:32:02 +08:00
}
2007-12-14 22:14:50 +08:00
convert_to_string ( & tmp ) ;
2008-01-11 23:10:24 +08:00
Z_STRVAL_P ( T - > str_offset . str ) [ T - > str_offset . offset ] = Z_STRVAL ( tmp ) [ 0 ] ;
STR_FREE ( Z_STRVAL ( tmp ) ) ;
} else {
Z_STRVAL_P ( T - > str_offset . str ) [ T - > str_offset . offset ] = Z_STRVAL_P ( value ) [ 0 ] ;
if ( value_type = = IS_TMP_VAR ) {
/* we can safely free final_value here
* because separation is done only
* in case value_type = = IS_VAR */
STR_FREE ( Z_STRVAL_P ( value ) ) ;
}
2004-08-20 04:03:06 +08:00
}
2007-12-14 22:14:50 +08:00
/*
* the value of an assignment to a string offset is undefined
T ( result - > u . var ) . var = & T - > str_offset . str ;
*/
1999-04-08 02:10:10 +08:00
}
2007-12-14 22:14:50 +08:00
}
1999-04-08 02:10:10 +08:00
2007-12-14 22:14:50 +08:00
static inline zval * zend_assign_to_variable ( zval * * variable_ptr_ptr , zval * value , int is_tmp_var TSRMLS_DC )
{
zval * variable_ptr = * variable_ptr_ptr ;
2008-01-11 16:42:06 +08:00
zval garbage ;
1999-04-08 02:10:10 +08:00
if ( variable_ptr = = EG ( error_zval_ptr ) ) {
2007-12-14 22:14:50 +08:00
if ( is_tmp_var ) {
2000-01-19 06:18:17 +08:00
zval_dtor ( value ) ;
}
2007-12-14 22:14:50 +08:00
return EG ( uninitialized_zval_ptr ) ;
1999-04-08 02:10:10 +08:00
}
2004-03-25 21:03:04 +08:00
2006-05-12 05:07:39 +08:00
if ( Z_TYPE_P ( variable_ptr ) = = IS_OBJECT & & Z_OBJ_HANDLER_P ( variable_ptr , set ) ) {
2004-03-28 22:57:29 +08:00
Z_OBJ_HANDLER_P ( variable_ptr , set ) ( variable_ptr_ptr , value TSRMLS_CC ) ;
2008-01-15 19:52:45 +08:00
return variable_ptr ;
2004-03-28 22:57:29 +08:00
}
2006-05-12 05:07:39 +08:00
2006-06-05 21:58:52 +08:00
if ( EG ( ze1_compatibility_mode ) & & Z_TYPE_P ( value ) = = IS_OBJECT ) {
char * class_name ;
zend_uint class_name_len ;
int dup ;
dup = zend_get_object_classname ( value , & class_name , & class_name_len TSRMLS_CC ) ;
if ( Z_OBJ_HANDLER_P ( value , clone_obj ) = = NULL ) {
zend_error_noreturn ( E_ERROR , " Trying to clone an uncloneable object of class %s " , class_name ) ;
} else if ( PZVAL_IS_REF ( variable_ptr ) ) {
if ( variable_ptr ! = value ) {
2007-10-07 13:22:07 +08:00
zend_uint refcount = Z_REFCOUNT_P ( variable_ptr ) ;
2006-06-05 21:58:52 +08:00
2007-12-14 22:14:50 +08:00
if ( ! is_tmp_var ) {
2007-10-07 13:22:07 +08:00
Z_ADDREF_P ( value ) ;
2006-06-05 21:58:52 +08:00
}
garbage = * variable_ptr ;
* variable_ptr = * value ;
2007-10-07 13:22:07 +08:00
Z_SET_REFCOUNT_P ( variable_ptr , refcount ) ;
Z_SET_ISREF_P ( variable_ptr ) ;
2006-06-05 21:58:52 +08:00
zend_error ( E_STRICT , " Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode' " , class_name ) ;
variable_ptr - > value . obj = Z_OBJ_HANDLER_P ( value , clone_obj ) ( value TSRMLS_CC ) ;
2007-12-14 22:14:50 +08:00
if ( ! is_tmp_var ) {
2007-10-07 13:22:07 +08:00
Z_DELREF_P ( value ) ;
2006-06-05 21:58:52 +08:00
}
zendi_zval_dtor ( garbage ) ;
2008-01-15 19:52:45 +08:00
return variable_ptr ;
2006-06-05 21:58:52 +08:00
}
} else {
if ( variable_ptr ! = value ) {
2007-10-07 13:22:07 +08:00
Z_ADDREF_P ( value ) ;
Z_DELREF_P ( variable_ptr ) ;
if ( Z_REFCOUNT_P ( variable_ptr ) = = 0 ) {
2006-06-05 21:58:52 +08:00
zendi_zval_dtor ( * variable_ptr ) ;
} else {
ALLOC_ZVAL ( variable_ptr ) ;
* variable_ptr_ptr = variable_ptr ;
}
* variable_ptr = * value ;
INIT_PZVAL ( variable_ptr ) ;
zend_error ( E_STRICT , " Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode' " , class_name ) ;
variable_ptr - > value . obj = Z_OBJ_HANDLER_P ( value , clone_obj ) ( value TSRMLS_CC ) ;
zval_ptr_dtor ( & value ) ;
}
}
if ( ! dup ) {
efree ( class_name ) ;
}
} else if ( PZVAL_IS_REF ( variable_ptr ) ) {
1999-04-08 02:10:10 +08:00
if ( variable_ptr ! = value ) {
2007-10-07 13:22:07 +08:00
zend_uint refcount = Z_REFCOUNT_P ( variable_ptr ) ;
2006-05-10 07:53:23 +08:00
2007-12-14 22:14:50 +08:00
if ( ! is_tmp_var ) {
2007-10-07 13:22:07 +08:00
Z_ADDREF_P ( value ) ;
1999-07-13 02:07:01 +08:00
}
2000-02-09 04:10:47 +08:00
garbage = * variable_ptr ;
1999-04-08 02:10:10 +08:00
* variable_ptr = * value ;
2007-10-07 13:22:07 +08:00
Z_SET_REFCOUNT_P ( variable_ptr , refcount ) ;
Z_SET_ISREF_P ( variable_ptr ) ;
2007-12-14 22:14:50 +08:00
if ( ! is_tmp_var ) {
1999-04-08 02:10:10 +08:00
zendi_zval_copy_ctor ( * variable_ptr ) ;
2007-10-07 13:22:07 +08:00
Z_DELREF_P ( value ) ;
1999-04-08 02:10:10 +08:00
}
2000-02-09 04:10:47 +08:00
zendi_zval_dtor ( garbage ) ;
2008-01-15 19:52:45 +08:00
return variable_ptr ;
1999-04-08 02:10:10 +08:00
}
} else {
2007-12-14 22:14:50 +08:00
if ( Z_DELREF_P ( variable_ptr ) = = 0 ) {
if ( ! is_tmp_var ) {
if ( variable_ptr = = value ) {
Z_ADDREF_P ( variable_ptr ) ;
} else if ( PZVAL_IS_REF ( value ) ) {
2008-01-11 16:42:06 +08:00
garbage = * variable_ptr ;
* variable_ptr = * value ;
INIT_PZVAL ( variable_ptr ) ;
zval_copy_ctor ( variable_ptr ) ;
zendi_zval_dtor ( garbage ) ;
return variable_ptr ;
2007-12-14 22:14:50 +08:00
} else {
Z_ADDREF_P ( value ) ;
2008-01-11 16:42:06 +08:00
* variable_ptr_ptr = value ;
2007-12-14 22:14:50 +08:00
zendi_zval_dtor ( * variable_ptr ) ;
safe_free_zval_ptr ( variable_ptr ) ;
2008-01-11 16:42:06 +08:00
return value ;
2007-12-14 22:14:50 +08:00
}
} else {
2008-01-11 16:42:06 +08:00
garbage = * variable_ptr ;
2007-12-14 22:14:50 +08:00
* variable_ptr = * value ;
2008-01-11 16:42:06 +08:00
INIT_PZVAL ( variable_ptr ) ;
zendi_zval_dtor ( garbage ) ;
return variable_ptr ;
2007-12-14 22:14:50 +08:00
}
1999-04-08 02:10:10 +08:00
} else { /* we need to split */
2007-12-14 22:14:50 +08:00
if ( ! is_tmp_var ) {
if ( PZVAL_IS_REF ( value ) & & Z_REFCOUNT_P ( value ) > 0 ) {
ALLOC_ZVAL ( variable_ptr ) ;
* variable_ptr_ptr = variable_ptr ;
* variable_ptr = * value ;
zval_copy_ctor ( variable_ptr ) ;
Z_SET_REFCOUNT_P ( variable_ptr , 1 ) ;
} else {
1999-04-08 02:10:10 +08:00
* variable_ptr_ptr = value ;
2007-10-07 13:22:07 +08:00
Z_ADDREF_P ( value ) ;
2007-12-14 22:14:50 +08:00
}
} else {
ALLOC_ZVAL ( * variable_ptr_ptr ) ;
Z_SET_REFCOUNT_P ( value , 1 ) ;
* * variable_ptr_ptr = * value ;
}
1999-04-08 02:10:10 +08:00
}
2007-10-07 13:22:07 +08:00
Z_UNSET_ISREF_PP ( variable_ptr_ptr ) ;
1999-04-08 02:10:10 +08:00
}
2006-05-10 07:53:23 +08:00
2007-12-14 22:14:50 +08:00
return * variable_ptr_ptr ;
1999-04-08 02:10:10 +08:00
}
2004-09-24 05:43:32 +08:00
static inline void zend_receive ( zval * * variable_ptr_ptr , zval * value TSRMLS_DC )
{
2006-06-05 21:58:52 +08:00
zval * variable_ptr = * variable_ptr_ptr ;
if ( EG ( ze1_compatibility_mode ) & & Z_TYPE_P ( value ) = = IS_OBJECT ) {
char * class_name ;
zend_uint class_name_len ;
int dup ;
dup = zend_get_object_classname ( value , & class_name , & class_name_len TSRMLS_CC ) ;
if ( Z_OBJ_HANDLER_P ( value , clone_obj ) = = NULL ) {
zend_error_noreturn ( E_ERROR , " Trying to clone an uncloneable object of class %s " , class_name ) ;
} else {
2007-10-07 13:22:07 +08:00
Z_DELREF_P ( variable_ptr ) ;
2006-06-05 21:58:52 +08:00
ALLOC_ZVAL ( variable_ptr ) ;
* variable_ptr_ptr = variable_ptr ;
* variable_ptr = * value ;
INIT_PZVAL ( variable_ptr ) ;
zend_error ( E_STRICT , " Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode' " , class_name ) ;
variable_ptr - > value . obj = Z_OBJ_HANDLER_P ( value , clone_obj ) ( value TSRMLS_CC ) ;
}
if ( ! dup ) {
efree ( class_name ) ;
}
} else {
2007-10-07 13:22:07 +08:00
Z_DELREF_P ( variable_ptr ) ;
2006-06-05 21:58:52 +08:00
* variable_ptr_ptr = value ;
2007-10-07 13:22:07 +08:00
Z_ADDREF_P ( value ) ;
2006-06-05 21:58:52 +08:00
}
2004-09-24 05:43:32 +08:00
}
1999-04-08 02:10:10 +08:00
/* Utility Functions for Extensions */
2001-07-31 12:53:54 +08:00
static void zend_extension_statement_handler ( zend_extension * extension , zend_op_array * op_array TSRMLS_DC )
1999-04-08 02:10:10 +08:00
{
if ( extension - > statement_handler ) {
extension - > statement_handler ( op_array ) ;
}
}
2001-07-31 12:53:54 +08:00
static void zend_extension_fcall_begin_handler ( zend_extension * extension , zend_op_array * op_array TSRMLS_DC )
1999-04-08 02:10:10 +08:00
{
if ( extension - > fcall_begin_handler ) {
extension - > fcall_begin_handler ( op_array ) ;
}
}
2001-07-31 12:53:54 +08:00
static void zend_extension_fcall_end_handler ( zend_extension * extension , zend_op_array * op_array TSRMLS_DC )
1999-04-08 02:10:10 +08:00
{
if ( extension - > fcall_end_handler ) {
extension - > fcall_end_handler ( op_array ) ;
}
}
2002-10-17 02:29:41 +08:00
static inline HashTable * zend_get_target_symbol_table ( zend_op * opline , temp_variable * Ts , int type , zval * variable TSRMLS_DC )
1999-04-08 02:10:10 +08:00
{
2002-01-06 03:59:09 +08:00
switch ( opline - > op2 . u . EA . type ) {
1999-04-08 02:10:10 +08:00
case ZEND_FETCH_LOCAL :
2002-02-05 03:29:56 +08:00
return EG ( active_symbol_table ) ;
1999-04-08 02:10:10 +08:00
break ;
case ZEND_FETCH_GLOBAL :
2005-07-04 21:24:46 +08:00
case ZEND_FETCH_GLOBAL_LOCK :
2002-02-05 03:29:56 +08:00
return & EG ( symbol_table ) ;
1999-04-08 02:10:10 +08:00
break ;
case ZEND_FETCH_STATIC :
1999-04-08 08:18:29 +08:00
if ( ! EG ( active_op_array ) - > static_variables ) {
1999-12-28 03:07:33 +08:00
ALLOC_HASHTABLE ( EG ( active_op_array ) - > static_variables ) ;
1999-12-22 01:14:31 +08:00
zend_hash_init ( EG ( active_op_array ) - > static_variables , 2 , NULL , ZVAL_PTR_DTOR , 0 ) ;
1999-04-08 08:18:29 +08:00
}
2002-02-05 03:29:56 +08:00
return EG ( active_op_array ) - > static_variables ;
1999-04-08 02:10:10 +08:00
break ;
2000-01-29 05:43:46 +08:00
EMPTY_SWITCH_DEFAULT_CASE ( )
1999-04-08 02:10:10 +08:00
}
2002-02-07 22:08:43 +08:00
return NULL ;
2002-02-05 03:29:56 +08:00
}
2004-09-24 05:43:32 +08:00
static inline zval * * zend_fetch_dimension_address_inner ( HashTable * ht , zval * dim , int type TSRMLS_DC )
1999-04-08 02:10:10 +08:00
{
zval * * retval ;
2000-01-04 01:26:24 +08:00
char * offset_key ;
int offset_key_length ;
1999-04-08 02:10:10 +08:00
switch ( dim - > type ) {
2000-01-04 21:22:58 +08:00
case IS_NULL :
2000-01-04 01:26:24 +08:00
offset_key = " " ;
offset_key_length = 0 ;
goto fetch_string_dim ;
2006-07-10 08:36:28 +08:00
2000-01-04 01:26:24 +08:00
case IS_STRING :
2003-05-23 23:11:15 +08:00
2000-01-04 01:26:24 +08:00
offset_key = dim - > value . str . val ;
offset_key_length = dim - > value . str . len ;
2003-05-23 23:11:15 +08:00
2000-01-04 01:26:24 +08:00
fetch_string_dim :
2003-07-23 00:06:07 +08:00
if ( zend_symtable_find ( ht , offset_key , offset_key_length + 1 , ( void * * ) & retval ) = = FAILURE ) {
2000-01-04 01:26:24 +08:00
switch ( type ) {
2004-02-11 21:58:29 +08:00
case BP_VAR_R :
zend_error ( E_NOTICE , " Undefined index: %s " , offset_key ) ;
2000-01-04 01:26:24 +08:00
/* break missing intentionally */
2004-02-11 21:58:29 +08:00
case BP_VAR_UNSET :
2000-01-04 01:26:24 +08:00
case BP_VAR_IS :
retval = & EG ( uninitialized_zval_ptr ) ;
break ;
case BP_VAR_RW :
zend_error ( E_NOTICE , " Undefined index: %s " , offset_key ) ;
/* break missing intentionally */
case BP_VAR_W : {
zval * new_zval = & EG ( uninitialized_zval ) ;
2007-10-07 13:22:07 +08:00
Z_ADDREF_P ( new_zval ) ;
2003-07-24 20:56:05 +08:00
zend_symtable_update ( ht , offset_key , offset_key_length + 1 , & new_zval , sizeof ( zval * ) , ( void * * ) & retval ) ;
2000-01-04 01:26:24 +08:00
}
break ;
1999-04-08 02:10:10 +08:00
}
}
break ;
1999-10-06 23:09:26 +08:00
case IS_RESOURCE :
2006-05-12 05:07:39 +08:00
zend_error ( E_STRICT , " Resource ID#%ld used as offset, casting to integer (%ld) " , Z_LVAL_P ( dim ) , Z_LVAL_P ( dim ) ) ;
2004-06-24 07:20:44 +08:00
/* Fall Through */
case IS_DOUBLE :
2006-05-10 07:53:23 +08:00
case IS_BOOL :
2003-07-23 00:06:07 +08:00
case IS_LONG : {
long index ;
1999-09-09 04:38:08 +08:00
2006-05-10 07:53:23 +08:00
if ( Z_TYPE_P ( dim ) = = IS_DOUBLE ) {
index = ( long ) Z_DVAL_P ( dim ) ;
2003-07-23 00:06:07 +08:00
} else {
2006-05-10 07:53:23 +08:00
index = Z_LVAL_P ( dim ) ;
2003-07-23 00:06:07 +08:00
}
if ( zend_hash_index_find ( ht , index , ( void * * ) & retval ) = = FAILURE ) {
switch ( type ) {
2004-02-11 21:58:29 +08:00
case BP_VAR_R :
2003-08-29 00:41:20 +08:00
zend_error ( E_NOTICE , " Undefined offset: %ld " , index ) ;
2003-07-23 00:06:07 +08:00
/* break missing intentionally */
2004-02-11 21:58:29 +08:00
case BP_VAR_UNSET :
2003-07-23 00:06:07 +08:00
case BP_VAR_IS :
retval = & EG ( uninitialized_zval_ptr ) ;
break ;
case BP_VAR_RW :
2003-08-29 00:41:20 +08:00
zend_error ( E_NOTICE , " Undefined offset: %ld " , index ) ;
2003-07-23 00:06:07 +08:00
/* break missing intentionally */
case BP_VAR_W : {
zval * new_zval = & EG ( uninitialized_zval ) ;
2007-10-07 13:22:07 +08:00
Z_ADDREF_P ( new_zval ) ;
2003-07-23 00:06:07 +08:00
zend_hash_index_update ( ht , index , & new_zval , sizeof ( zval * ) , ( void * * ) & retval ) ;
}
break ;
1999-04-08 02:10:10 +08:00
}
}
}
break ;
2006-05-10 07:53:23 +08:00
default :
1999-04-08 02:10:10 +08:00
zend_error ( E_WARNING , " Illegal offset type " ) ;
2004-02-11 21:58:29 +08:00
switch ( type ) {
case BP_VAR_R :
case BP_VAR_IS :
case BP_VAR_UNSET :
retval = & EG ( uninitialized_zval_ptr ) ;
break ;
default :
retval = & EG ( error_zval_ptr ) ;
break ;
1999-04-08 02:10:10 +08:00
}
break ;
}
return retval ;
}
2005-06-03 19:16:19 +08:00
static void zend_fetch_dimension_address ( temp_variable * result , zval * * container_ptr , zval * dim , int dim_is_tmp_var , int type TSRMLS_DC )
1999-04-08 02:10:10 +08:00
{
zval * container ;
2007-11-20 19:01:28 +08:00
zval * * retval ;
1999-04-08 02:10:10 +08:00
2002-11-13 23:13:24 +08:00
if ( ! container_ptr ) {
2004-09-24 05:43:32 +08:00
zend_error_noreturn ( E_ERROR , " Cannot use string offset as an array " ) ;
2002-11-13 23:13:24 +08:00
}
2006-05-10 07:53:23 +08:00
1999-04-08 02:10:10 +08:00
container = * container_ptr ;
2006-05-10 07:53:23 +08:00
switch ( Z_TYPE_P ( container ) ) {
2004-09-24 05:43:32 +08:00
1999-04-08 02:10:10 +08:00
case IS_ARRAY :
2007-12-14 22:14:50 +08:00
if ( type ! = BP_VAR_UNSET & & Z_REFCOUNT_P ( container ) > 1 & & ! PZVAL_IS_REF ( container ) ) {
2000-08-05 21:54:07 +08:00
SEPARATE_ZVAL ( container_ptr ) ;
1999-04-08 02:10:10 +08:00
container = * container_ptr ;
}
2007-11-20 19:01:28 +08:00
fetch_from_array :
2004-09-24 05:43:32 +08:00
if ( dim = = NULL ) {
1999-05-21 04:00:59 +08:00
zval * new_zval = & EG ( uninitialized_zval ) ;
1999-04-08 02:10:10 +08:00
2007-10-07 13:22:07 +08:00
Z_ADDREF_P ( new_zval ) ;
2006-05-10 07:53:23 +08:00
if ( zend_hash_next_index_insert ( Z_ARRVAL_P ( container ) , & new_zval , sizeof ( zval * ) , ( void * * ) & retval ) = = FAILURE ) {
2002-11-12 02:27:32 +08:00
zend_error ( E_WARNING , " Cannot add element to the array as the next element is already occupied " ) ;
2005-06-07 18:21:52 +08:00
retval = & EG ( error_zval_ptr ) ;
2007-10-07 13:22:07 +08:00
Z_DELREF_P ( new_zval ) ;
2002-08-02 00:07:19 +08:00
}
1999-04-08 02:10:10 +08:00
} else {
2006-05-10 07:53:23 +08:00
retval = zend_fetch_dimension_address_inner ( Z_ARRVAL_P ( container ) , dim , type TSRMLS_CC ) ;
2004-09-24 05:43:32 +08:00
}
if ( result ) {
result - > var . ptr_ptr = retval ;
2007-11-20 19:01:28 +08:00
PZVAL_LOCK ( * retval ) ;
1999-04-08 02:10:10 +08:00
}
2007-11-20 19:01:28 +08:00
return ;
1999-04-08 02:10:10 +08:00
break ;
2007-11-20 19:01:28 +08:00
case IS_NULL :
if ( container = = EG ( error_zval_ptr ) ) {
if ( result ) {
result - > var . ptr_ptr = & EG ( error_zval_ptr ) ;
PZVAL_LOCK ( EG ( error_zval_ptr ) ) ;
}
2007-12-14 22:14:50 +08:00
} else if ( type ! = BP_VAR_UNSET ) {
2007-11-20 19:01:28 +08:00
convert_to_array :
if ( ! PZVAL_IS_REF ( container ) ) {
SEPARATE_ZVAL ( container_ptr ) ;
container = * container_ptr ;
}
zval_dtor ( container ) ;
array_init ( container ) ;
goto fetch_from_array ;
} else if ( result ) {
2007-12-14 22:14:50 +08:00
/* for read-mode only */
2004-09-24 05:43:32 +08:00
result - > var . ptr_ptr = & EG ( uninitialized_zval_ptr ) ;
2007-11-20 19:01:28 +08:00
PZVAL_LOCK ( EG ( uninitialized_zval_ptr ) ) ;
2000-04-12 01:38:19 +08:00
}
2007-11-20 19:01:28 +08:00
return ;
1999-12-31 21:56:59 +08:00
break ;
2007-11-20 19:01:28 +08:00
1999-04-08 02:10:10 +08:00
case IS_STRING : {
1999-12-31 21:56:59 +08:00
zval tmp ;
1999-04-08 02:10:10 +08:00
2007-12-14 22:14:50 +08:00
if ( type ! = BP_VAR_UNSET & & Z_STRLEN_P ( container ) = = 0 ) {
2007-11-20 19:01:28 +08:00
goto convert_to_array ;
}
2004-09-24 05:43:32 +08:00
if ( dim = = NULL ) {
zend_error_noreturn ( E_ERROR , " [] operator not supported for strings " ) ;
2000-01-04 04:01:54 +08:00
}
2006-05-10 07:53:23 +08:00
if ( Z_TYPE_P ( dim ) ! = IS_LONG ) {
2006-06-01 19:56:44 +08:00
switch ( Z_TYPE_P ( dim ) ) {
/* case IS_LONG: */
case IS_STRING :
case IS_DOUBLE :
case IS_NULL :
case IS_BOOL :
/* do nothing */
break ;
default :
zend_error ( E_WARNING , " Illegal offset type " ) ;
break ;
}
2004-09-24 05:43:32 +08:00
tmp = * dim ;
1999-12-31 21:56:59 +08:00
zval_copy_ctor ( & tmp ) ;
convert_to_long ( & tmp ) ;
2004-09-24 05:43:32 +08:00
dim = & tmp ;
1999-12-31 21:56:59 +08:00
}
2007-12-14 22:14:50 +08:00
if ( type ! = BP_VAR_UNSET ) {
SEPARATE_ZVAL_IF_NOT_REF ( container_ptr ) ;
1999-04-08 02:10:10 +08:00
}
2004-09-24 05:43:32 +08:00
if ( result ) {
container = * container_ptr ;
result - > str_offset . str = container ;
PZVAL_LOCK ( container ) ;
2006-05-10 07:53:23 +08:00
result - > str_offset . offset = Z_LVAL_P ( dim ) ;
2004-09-24 05:43:32 +08:00
result - > var . ptr_ptr = NULL ;
2007-12-14 22:14:50 +08:00
result - > var . ptr = NULL ;
2004-08-20 04:03:06 +08:00
}
1999-12-31 21:56:59 +08:00
return ;
1999-04-08 02:10:10 +08:00
}
break ;
2007-11-20 19:01:28 +08:00
2003-07-07 18:53:27 +08:00
case IS_OBJECT :
2004-02-09 01:23:20 +08:00
if ( ! Z_OBJ_HT_P ( container ) - > read_dimension ) {
2004-09-24 05:43:32 +08:00
zend_error_noreturn ( E_ERROR , " Cannot use object as array " ) ;
2004-02-09 01:23:20 +08:00
} else {
2005-06-03 19:16:19 +08:00
zval * overloaded_result ;
2006-05-10 07:53:23 +08:00
2005-06-03 19:16:19 +08:00
if ( dim_is_tmp_var ) {
zval * orig = dim ;
MAKE_REAL_ZVAL_PTR ( dim ) ;
ZVAL_NULL ( orig ) ;
2006-05-10 07:53:23 +08:00
}
2005-06-03 19:16:19 +08:00
overloaded_result = Z_OBJ_HT_P ( container ) - > read_dimension ( container , dim , type TSRMLS_CC ) ;
2003-11-25 04:57:54 +08:00
2004-02-09 01:23:20 +08:00
if ( overloaded_result ) {
2007-12-14 22:14:50 +08:00
if ( ! Z_ISREF_P ( overloaded_result ) ) {
2007-10-07 13:22:07 +08:00
if ( Z_REFCOUNT_P ( overloaded_result ) > 0 ) {
2006-12-08 23:55:31 +08:00
zval * tmp = overloaded_result ;
ALLOC_ZVAL ( overloaded_result ) ;
* overloaded_result = * tmp ;
zval_copy_ctor ( overloaded_result ) ;
2007-10-07 13:22:07 +08:00
Z_UNSET_ISREF_P ( overloaded_result ) ;
Z_SET_REFCOUNT_P ( overloaded_result , 0 ) ;
2006-12-08 23:55:31 +08:00
}
if ( Z_TYPE_P ( overloaded_result ) ! = IS_OBJECT ) {
zend_class_entry * ce = Z_OBJCE_P ( container ) ;
zend_error ( E_NOTICE , " Indirect modification of overloaded element of %s has no effect " , ce - > name ) ;
}
2003-12-11 17:52:33 +08:00
}
2004-09-24 05:43:32 +08:00
retval = & overloaded_result ;
2004-02-09 01:23:20 +08:00
} else {
2004-09-24 05:43:32 +08:00
retval = & EG ( error_zval_ptr ) ;
2003-07-31 01:12:06 +08:00
}
2004-09-24 05:43:32 +08:00
if ( result ) {
2007-12-14 22:14:50 +08:00
AI_SET_PTR ( result - > var , * retval ) ;
PZVAL_LOCK ( * retval ) ;
2007-10-07 13:22:07 +08:00
} else if ( Z_REFCOUNT_PP ( retval ) = = 0 ) {
2005-07-19 15:33:00 +08:00
/* Destroy unused result from offsetGet() magic method */
2007-10-07 13:22:07 +08:00
Z_SET_REFCOUNT_PP ( retval , 1 ) ;
2005-07-19 15:33:00 +08:00
zval_ptr_dtor ( retval ) ;
2004-09-24 05:43:32 +08:00
}
2005-06-03 19:16:19 +08:00
if ( dim_is_tmp_var ) {
zval_ptr_dtor ( & dim ) ;
}
2003-07-07 18:53:27 +08:00
}
2007-11-20 19:01:28 +08:00
return ;
2003-07-07 18:53:27 +08:00
break ;
2007-11-20 19:01:28 +08:00
case IS_BOOL :
2007-12-14 22:14:50 +08:00
if ( type ! = BP_VAR_UNSET & & Z_LVAL_P ( container ) = = 0 ) {
2007-11-20 19:01:28 +08:00
goto convert_to_array ;
}
/* break missing intentionally */
default :
2007-12-14 22:14:50 +08:00
if ( type = = BP_VAR_UNSET ) {
zend_error ( E_WARNING , " Cannot unset offset in a non-array variable " ) ;
if ( result ) {
AI_SET_PTR ( result - > var , EG ( uninitialized_zval_ptr ) ) ;
PZVAL_LOCK ( EG ( uninitialized_zval_ptr ) ) ;
}
} else {
zend_error ( E_WARNING , " Cannot use a scalar value as an array " ) ;
if ( result ) {
result - > var . ptr_ptr = & EG ( error_zval_ptr ) ;
PZVAL_LOCK ( EG ( error_zval_ptr ) ) ;
}
}
break ;
}
}
static void zend_fetch_dimension_address_read ( temp_variable * result , zval * * container_ptr , zval * dim , int dim_is_tmp_var , int type TSRMLS_DC )
{
zval * container ;
zval * * retval ;
if ( ! container_ptr ) {
zend_error_noreturn ( E_ERROR , " Cannot use string offset as an array " ) ;
}
container = * container_ptr ;
switch ( Z_TYPE_P ( container ) ) {
case IS_ARRAY :
if ( dim = = NULL ) {
zval * new_zval = & EG ( uninitialized_zval ) ;
Z_ADDREF_P ( new_zval ) ;
if ( zend_hash_next_index_insert ( Z_ARRVAL_P ( container ) , & new_zval , sizeof ( zval * ) , ( void * * ) & retval ) = = FAILURE ) {
zend_error ( E_WARNING , " Cannot add element to the array as the next element is already occupied " ) ;
retval = & EG ( error_zval_ptr ) ;
Z_DELREF_P ( new_zval ) ;
}
} else {
retval = zend_fetch_dimension_address_inner ( Z_ARRVAL_P ( container ) , dim , type TSRMLS_CC ) ;
}
if ( result ) {
AI_SET_PTR ( result - > var , * retval ) ;
PZVAL_LOCK ( * retval ) ;
}
return ;
break ;
case IS_NULL :
if ( container = = EG ( error_zval_ptr ) ) {
if ( result ) {
AI_SET_PTR ( result - > var , EG ( error_zval_ptr ) ) ;
PZVAL_LOCK ( EG ( error_zval_ptr ) ) ;
}
} else if ( result ) {
AI_SET_PTR ( result - > var , EG ( uninitialized_zval_ptr ) ) ;
PZVAL_LOCK ( EG ( uninitialized_zval_ptr ) ) ;
}
return ;
break ;
case IS_STRING : {
zval tmp ;
if ( dim = = NULL ) {
zend_error_noreturn ( E_ERROR , " [] operator not supported for strings " ) ;
}
if ( Z_TYPE_P ( dim ) ! = IS_LONG ) {
switch ( Z_TYPE_P ( dim ) ) {
/* case IS_LONG: */
case IS_STRING :
case IS_DOUBLE :
case IS_NULL :
case IS_BOOL :
/* do nothing */
break ;
default :
zend_error ( E_WARNING , " Illegal offset type " ) ;
break ;
2007-11-20 19:01:28 +08:00
}
2007-12-14 22:14:50 +08:00
tmp = * dim ;
zval_copy_ctor ( & tmp ) ;
convert_to_long ( & tmp ) ;
dim = & tmp ;
}
if ( result ) {
result - > str_offset . str = container ;
PZVAL_LOCK ( container ) ;
result - > str_offset . offset = Z_LVAL_P ( dim ) ;
result - > var . ptr_ptr = NULL ;
result - > var . ptr = NULL ;
}
return ;
}
break ;
case IS_OBJECT :
if ( ! Z_OBJ_HT_P ( container ) - > read_dimension ) {
zend_error_noreturn ( E_ERROR , " Cannot use object as array " ) ;
} else {
zval * overloaded_result ;
if ( dim_is_tmp_var ) {
zval * orig = dim ;
MAKE_REAL_ZVAL_PTR ( dim ) ;
ZVAL_NULL ( orig ) ;
}
overloaded_result = Z_OBJ_HT_P ( container ) - > read_dimension ( container , dim , type TSRMLS_CC ) ;
if ( overloaded_result ) {
2007-11-20 19:01:28 +08:00
if ( result ) {
2007-12-14 22:14:50 +08:00
AI_SET_PTR ( result - > var , overloaded_result ) ;
PZVAL_LOCK ( overloaded_result ) ;
} else if ( Z_REFCOUNT_P ( overloaded_result ) = = 0 ) {
/* Destroy unused result from offsetGet() magic method */
Z_SET_REFCOUNT_P ( overloaded_result , 1 ) ;
zval_ptr_dtor ( & overloaded_result ) ;
2007-11-20 19:01:28 +08:00
}
2007-12-14 22:14:50 +08:00
} else if ( result ) {
AI_SET_PTR ( result - > var , EG ( error_zval_ptr ) ) ;
PZVAL_LOCK ( EG ( error_zval_ptr ) ) ;
}
if ( dim_is_tmp_var ) {
zval_ptr_dtor ( & dim ) ;
}
1999-04-08 02:10:10 +08:00
}
2007-12-14 22:14:50 +08:00
return ;
break ;
default :
if ( result ) {
AI_SET_PTR ( result - > var , EG ( uninitialized_zval_ptr ) ) ;
PZVAL_LOCK ( EG ( uninitialized_zval_ptr ) ) ;
}
return ;
1999-04-08 02:10:10 +08:00
break ;
}
}
2005-06-03 19:16:19 +08:00
static void zend_fetch_property_address ( temp_variable * result , zval * * container_ptr , zval * prop_ptr , int type TSRMLS_DC )
1999-04-08 02:10:10 +08:00
{
zval * container ;
2006-05-10 07:53:23 +08:00
2007-07-09 16:53:14 +08:00
if ( ! container_ptr ) {
2007-07-13 07:33:50 +08:00
zend_error ( E_WARNING , " Cannot use string offset as an array " ) ;
if ( result ) {
result - > var . ptr_ptr = & EG ( error_zval_ptr ) ;
PZVAL_LOCK ( * result - > var . ptr_ptr ) ;
}
return ;
2007-07-09 16:53:14 +08:00
}
1999-04-08 02:10:10 +08:00
container = * container_ptr ;
2007-12-14 22:14:50 +08:00
if ( Z_TYPE_P ( container ) ! = IS_OBJECT ) {
if ( container = = EG ( error_zval_ptr ) ) {
if ( result ) {
result - > var . ptr_ptr = & EG ( error_zval_ptr ) ;
PZVAL_LOCK ( * result - > var . ptr_ptr ) ;
}
return ;
1999-04-08 02:10:10 +08:00
}
2006-05-10 07:53:23 +08:00
2007-12-14 22:14:50 +08:00
/* this should modify object only if it's empty */
if ( type ! = BP_VAR_UNSET & &
( ( Z_TYPE_P ( container ) = = IS_NULL | |
( Z_TYPE_P ( container ) = = IS_BOOL & & Z_LVAL_P ( container ) = = 0 ) | |
( Z_TYPE_P ( container ) = = IS_STRING & & Z_STRLEN_P ( container ) = = 0 ) ) ) ) {
if ( ! PZVAL_IS_REF ( container ) ) {
SEPARATE_ZVAL ( container_ptr ) ;
container = * container_ptr ;
}
object_init ( container ) ;
} else {
if ( result ) {
2004-09-24 05:43:32 +08:00
result - > var . ptr_ptr = & EG ( error_zval_ptr ) ;
2007-12-14 22:14:50 +08:00
PZVAL_LOCK ( EG ( error_zval_ptr ) ) ;
2004-08-20 04:03:06 +08:00
}
2007-12-14 22:14:50 +08:00
return ;
1999-04-08 02:10:10 +08:00
}
}
2006-05-10 07:53:23 +08:00
2004-09-24 05:43:32 +08:00
if ( Z_OBJ_HT_P ( container ) - > get_property_ptr_ptr ) {
zval * * ptr_ptr = Z_OBJ_HT_P ( container ) - > get_property_ptr_ptr ( container , prop_ptr TSRMLS_CC ) ;
2006-05-10 07:53:23 +08:00
if ( NULL = = ptr_ptr ) {
2005-01-18 17:05:39 +08:00
zval * ptr ;
if ( Z_OBJ_HT_P ( container ) - > read_property & &
2006-07-10 08:36:28 +08:00
( ptr = Z_OBJ_HT_P ( container ) - > read_property ( container , prop_ptr , type TSRMLS_CC ) ) ! = NULL ) {
2005-01-18 17:05:39 +08:00
if ( result ) {
2007-12-14 22:14:50 +08:00
AI_SET_PTR ( result - > var , ptr ) ;
PZVAL_LOCK ( ptr ) ;
2005-01-18 17:05:39 +08:00
}
} else {
zend_error ( E_ERROR , " Cannot access undefined property for object with overloaded property access " ) ;
}
} else if ( result ) {
2004-09-24 05:43:32 +08:00
result - > var . ptr_ptr = ptr_ptr ;
2007-12-14 22:14:50 +08:00
PZVAL_LOCK ( * ptr_ptr ) ;
2002-02-07 22:08:43 +08:00
}
2004-09-24 05:43:32 +08:00
} else if ( Z_OBJ_HT_P ( container ) - > read_property ) {
2007-12-14 22:14:50 +08:00
zval * ptr = Z_OBJ_HT_P ( container ) - > read_property ( container , prop_ptr , type TSRMLS_CC ) ;
2004-09-24 05:43:32 +08:00
if ( result ) {
2007-12-14 22:14:50 +08:00
AI_SET_PTR ( result - > var , ptr ) ;
PZVAL_LOCK ( ptr ) ;
2002-02-07 22:08:43 +08:00
}
2004-09-24 05:43:32 +08:00
} else {
zend_error ( E_WARNING , " This object doesn't support property references " ) ;
if ( result ) {
result - > var . ptr_ptr = & EG ( error_zval_ptr ) ;
2007-12-14 22:14:50 +08:00
PZVAL_LOCK ( EG ( error_zval_ptr ) ) ;
2004-02-12 00:28:46 +08:00
}
2001-05-03 03:51:33 +08:00
}
1999-04-08 02:10:10 +08:00
}
2004-09-24 05:43:32 +08:00
static inline zend_brk_cont_element * zend_brk_cont ( zval * nest_levels_zval , int array_offset , zend_op_array * op_array , temp_variable * Ts TSRMLS_DC )
2002-03-10 21:42:37 +08:00
{
2004-09-24 05:43:32 +08:00
zval tmp ;
int nest_levels , original_nest_levels ;
zend_brk_cont_element * jmp_to ;
2002-03-10 21:42:37 +08:00
2004-09-24 05:43:32 +08:00
if ( nest_levels_zval - > type ! = IS_LONG ) {
tmp = * nest_levels_zval ;
zval_copy_ctor ( & tmp ) ;
convert_to_long ( & tmp ) ;
nest_levels = tmp . value . lval ;
} else {
nest_levels = nest_levels_zval - > value . lval ;
2004-09-10 00:47:22 +08:00
}
2004-09-24 05:43:32 +08:00
original_nest_levels = nest_levels ;
do {
if ( array_offset = = - 1 ) {
zend_error_noreturn ( E_ERROR , " Cannot break/continue %d level%s " , original_nest_levels , ( original_nest_levels = = 1 ) ? " " : " s " ) ;
2004-09-10 00:47:22 +08:00
}
2004-09-24 05:43:32 +08:00
jmp_to = & op_array - > brk_cont_array [ array_offset ] ;
if ( nest_levels > 1 ) {
zend_op * brk_opline = & op_array - > opcodes [ jmp_to - > brk ] ;
2004-09-10 00:47:22 +08:00
2004-09-24 05:43:32 +08:00
switch ( brk_opline - > opcode ) {
case ZEND_SWITCH_FREE :
2007-12-14 22:14:50 +08:00
zend_switch_free ( & T ( brk_opline - > op1 . u . var ) , brk_opline - > op1 . op_type , brk_opline - > extended_value TSRMLS_CC ) ;
2004-09-24 05:43:32 +08:00
break ;
case ZEND_FREE :
zendi_zval_dtor ( T ( brk_opline - > op1 . u . var ) . tmp_var ) ;
break ;
2004-09-10 00:47:22 +08:00
}
}
2004-09-24 05:43:32 +08:00
array_offset = jmp_to - > parent ;
} while ( - - nest_levels > 0 ) ;
return jmp_to ;
2002-03-10 21:42:37 +08:00
}
2000-02-10 05:48:16 +08:00
# if ZEND_INTENSIVE_DEBUGGING
# define CHECK_SYMBOL_TABLES() \
2001-07-31 12:53:54 +08:00
zend_hash_apply ( & EG ( symbol_table ) , ( apply_func_t ) zend_check_symbol TSRMLS_CC ) ; \
2000-02-10 05:48:16 +08:00
if ( & EG ( symbol_table ) ! = EG ( active_symbol_table ) ) { \
2001-07-31 12:53:54 +08:00
zend_hash_apply ( EG ( active_symbol_table ) , ( apply_func_t ) zend_check_symbol TSRMLS_CC ) ; \
2000-02-10 05:48:16 +08:00
}
2001-07-31 12:53:54 +08:00
static int zend_check_symbol ( zval * * pz TSRMLS_DC )
2000-02-10 05:48:16 +08:00
{
2001-08-06 10:52:03 +08:00
if ( Z_TYPE_PP ( pz ) > 9 ) {
2000-02-10 05:48:16 +08:00
fprintf ( stderr , " Warning! %x has invalid type! \n " , * pz ) ;
2001-08-06 10:52:03 +08:00
} else if ( Z_TYPE_PP ( pz ) = = IS_ARRAY ) {
zend_hash_apply ( Z_ARRVAL_PP ( pz ) , ( apply_func_t ) zend_check_symbol TSRMLS_CC ) ;
} else if ( Z_TYPE_PP ( pz ) = = IS_OBJECT ) {
2006-05-10 07:53:23 +08:00
2002-02-07 22:08:43 +08:00
/* OBJ-TBI - doesn't support new object model! */
2001-08-06 10:52:03 +08:00
zend_hash_apply ( Z_OBJPROP_PP ( pz ) , ( apply_func_t ) zend_check_symbol TSRMLS_CC ) ;
2000-02-10 05:48:16 +08:00
}
return 0 ;
}
# else
# define CHECK_SYMBOL_TABLES()
# endif
2004-09-24 05:43:32 +08:00
ZEND_API opcode_handler_t * zend_opcode_handlers ;
2001-08-30 23:26:30 +08:00
2003-01-12 00:12:44 +08:00
ZEND_API void execute_internal ( zend_execute_data * execute_data_ptr , int return_value_used TSRMLS_DC )
{
2005-06-16 22:56:13 +08:00
zval * * return_value_ptr = & ( * ( temp_variable * ) ( ( char * ) execute_data_ptr - > Ts + execute_data_ptr - > opline - > result . u . var ) ) . var . ptr ;
( ( zend_internal_function * ) execute_data_ptr - > function_state . function ) - > handler ( execute_data_ptr - > opline - > extended_value , * return_value_ptr , execute_data_ptr - > function_state . function - > common . return_reference ? return_value_ptr : NULL , execute_data_ptr - > object , return_value_used TSRMLS_CC ) ;
2003-01-12 00:12:44 +08:00
}
2004-10-23 05:42:14 +08:00
# define ZEND_VM_NEXT_OPCODE() \
2006-05-10 07:53:23 +08:00
CHECK_SYMBOL_TABLES ( ) \
EX ( opline ) + + ; \
ZEND_VM_CONTINUE ( )
2004-10-23 05:42:14 +08:00
# define ZEND_VM_SET_OPCODE(new_op) \
2006-05-10 07:53:23 +08:00
CHECK_SYMBOL_TABLES ( ) \
EX ( opline ) = new_op
2004-10-23 05:42:14 +08:00
2005-11-01 03:25:14 +08:00
# define ZEND_VM_JMP(new_op) \
CHECK_SYMBOL_TABLES ( ) \
EX ( opline ) = EG ( exception ) ? EX ( opline ) + 1 : new_op ; \
ZEND_VM_CONTINUE ( )
2004-10-23 05:42:14 +08:00
# define ZEND_VM_INC_OPCODE() \
2006-05-10 07:53:23 +08:00
if ( ! EG ( exception ) ) { \
CHECK_SYMBOL_TABLES ( ) \
EX ( opline ) + + ; \
}
2004-10-23 05:42:14 +08:00
2007-11-21 20:28:13 +08:00
# define ZEND_VM_EXIT_FROM_EXECUTE_LOOP() \
2007-11-22 21:27:13 +08:00
free_alloca ( EX ( CVs ) , EX ( use_heap ) ) ; \
2006-05-10 07:53:23 +08:00
EG ( in_execution ) = EX ( original_in_execution ) ; \
EG ( current_execute_data ) = EX ( prev_execute_data ) ; \
2007-11-21 20:28:13 +08:00
EG ( opline_ptr ) = NULL ;
# define ZEND_VM_RETURN_FROM_EXECUTE_LOOP() \
ZEND_VM_EXIT_FROM_EXECUTE_LOOP ( ) \
2006-05-10 07:53:23 +08:00
ZEND_VM_RETURN ( )
2004-10-23 05:42:14 +08:00
# include "zend_vm_execute.h"
2003-02-01 09:49:15 +08:00
2005-06-10 17:54:38 +08:00
ZEND_API int zend_set_user_opcode_handler ( zend_uchar opcode , opcode_handler_t handler )
{
if ( opcode ! = ZEND_USER_OPCODE ) {
zend_user_opcodes [ opcode ] = ZEND_USER_OPCODE ;
zend_user_opcode_handlers [ opcode ] = handler ;
return SUCCESS ;
}
return FAILURE ;
}
ZEND_API opcode_handler_t zend_get_user_opcode_handler ( zend_uchar opcode )
{
return zend_user_opcode_handlers [ opcode ] ;
}
2005-06-16 22:27:08 +08:00
ZEND_API zval * zend_get_zval_ptr ( znode * node , temp_variable * Ts , zend_free_op * should_free , int type TSRMLS_DC ) {
2005-06-17 01:29:29 +08:00
return get_zval_ptr ( node , Ts , should_free , type ) ;
2005-06-16 19:50:08 +08:00
}
2005-06-16 22:27:08 +08:00
ZEND_API zval * * zend_get_zval_ptr_ptr ( znode * node , temp_variable * Ts , zend_free_op * should_free , int type TSRMLS_DC ) {
2005-06-17 01:29:29 +08:00
return get_zval_ptr_ptr ( node , Ts , should_free , type ) ;
2005-06-16 19:50:08 +08:00
}
2003-02-01 09:49:15 +08:00
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* indent - tabs - mode : t
* End :
*/