2006-05-10 07:53:23 +08:00
/*
2003-02-01 09:49:15 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| Zend Engine |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2007-01-01 17:36:18 +08:00
| Copyright ( c ) 1998 - 2007 Zend Technologies Ltd . ( http : //www.zend.com) |
2003-02-01 09:49:15 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| This source file is subject to version 2.00 of the Zend license , |
| 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 : |
2003-02-01 09:49:15 +08:00
| http : //www.zend.com/license/2_00.txt. |
| 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 . |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| Authors : Andi Gutmans < andi @ zend . com > |
| Zeev Suraski < zeev @ zend . com > |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
/* $Id$ */
2002-02-07 22:08:43 +08:00
# include "zend.h"
# include "zend_globals.h"
# include "zend_variables.h"
# include "zend_API.h"
# include "zend_objects.h"
2002-05-31 20:09:19 +08:00
# include "zend_objects_API.h"
2002-02-07 22:08:43 +08:00
# include "zend_object_handlers.h"
2003-11-25 04:57:54 +08:00
# include "zend_interfaces.h"
2002-02-07 22:08:43 +08:00
2002-02-21 19:50:44 +08:00
# define DEBUG_OBJECT_HANDLERS 0
2002-02-07 22:08:43 +08:00
2003-03-26 14:32:53 +08:00
# define Z_OBJ_P(zval_p) zend_objects_get_address(zval_p TSRMLS_CC)
2003-01-12 22:39:45 +08:00
2002-09-04 17:07:58 +08:00
/*
__X accessors explanation :
if we have __get and property that is not part of the properties array is
requested , we call __get handler . If it fails , we return uninitialized .
if we have __set and property that is not part of the properties array is
set , we call __set handler . If it fails , we do not change the array .
for both handlers above , when we are inside __get / __set , no further calls for
2007-10-11 09:03:19 +08:00
__get / __set for this property of this object will be made , to prevent endless
2007-03-24 01:16:55 +08:00
recursion and enable accessors to change properties array .
2002-09-04 17:07:58 +08:00
if we have __call and method which is not part of the class function table is
2006-05-10 07:53:23 +08:00
called , we cal __call handler .
2002-09-04 17:07:58 +08:00
*/
2007-10-11 09:03:19 +08:00
ZEND_API HashTable * zend_std_get_properties ( zval * object TSRMLS_DC )
2002-02-07 22:08:43 +08:00
{
zend_object * zobj ;
2002-04-22 22:22:27 +08:00
zobj = Z_OBJ_P ( object ) ;
2002-02-07 22:08:43 +08:00
return zobj - > properties ;
}
2002-09-04 17:07:58 +08:00
static zval * zend_std_call_getter ( zval * object , zval * member TSRMLS_DC )
{
zval * retval = NULL ;
2004-09-29 06:55:22 +08:00
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
2006-05-10 07:53:23 +08:00
2004-09-29 06:55:22 +08:00
/* __get handler is called with one argument:
property name
2002-09-04 17:07:58 +08:00
it should return whether the call was successfull or not
*/
2006-05-10 07:53:23 +08:00
2005-02-02 15:19:22 +08:00
SEPARATE_ARG_IF_REF ( member ) ;
2004-09-29 06:55:22 +08:00
zend_call_method_with_1_params ( & object , ce , & ce - > __get , ZEND_GET_FUNC_NAME , & retval , member ) ;
2002-09-04 17:07:58 +08:00
2005-02-02 15:19:22 +08:00
zval_ptr_dtor ( & member ) ;
2003-06-30 07:41:49 +08:00
if ( retval ) {
2007-10-07 13:22:07 +08:00
Z_DELREF_P ( retval ) ;
2003-06-30 07:41:49 +08:00
}
2002-09-04 17:07:58 +08:00
return retval ;
}
static int zend_std_call_setter ( zval * object , zval * member , zval * value TSRMLS_DC )
{
zval * retval = NULL ;
2005-03-19 23:32:18 +08:00
int result ;
2004-09-29 06:55:22 +08:00
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
2005-02-02 15:19:22 +08:00
SEPARATE_ARG_IF_REF ( member ) ;
2007-10-07 13:22:07 +08:00
Z_ADDREF_P ( value ) ;
2004-09-29 06:55:22 +08:00
2002-09-04 17:07:58 +08:00
/* __set handler is called with two arguments:
2004-09-29 06:55:22 +08:00
property name
value to be set
2002-09-04 17:07:58 +08:00
it should return whether the call was successfull or not
*/
2004-09-29 06:55:22 +08:00
zend_call_method_with_2_params ( & object , ce , & ce - > __set , ZEND_SET_FUNC_NAME , & retval , member , value ) ;
2002-09-04 17:07:58 +08:00
2005-02-02 15:19:22 +08:00
zval_ptr_dtor ( & member ) ;
2002-09-04 17:07:58 +08:00
zval_ptr_dtor ( & value ) ;
2002-09-15 15:45:26 +08:00
if ( retval ) {
2005-03-19 23:32:18 +08:00
result = i_zend_is_true ( retval ) ? SUCCESS : FAILURE ;
2002-09-04 17:07:58 +08:00
zval_ptr_dtor ( & retval ) ;
2005-03-19 23:32:18 +08:00
return result ;
} else {
return FAILURE ;
2002-09-04 17:07:58 +08:00
}
}
2005-07-08 00:07:09 +08:00
static void zend_std_call_unsetter ( zval * object , zval * member TSRMLS_DC )
{
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
2006-05-10 07:53:23 +08:00
2005-07-08 00:07:09 +08:00
/* __unset handler is called with one argument:
property name
*/
2006-05-10 07:53:23 +08:00
2005-07-08 00:07:09 +08:00
SEPARATE_ARG_IF_REF ( member ) ;
zend_call_method_with_1_params ( & object , ce , & ce - > __unset , ZEND_UNSET_FUNC_NAME , NULL , member ) ;
zval_ptr_dtor ( & member ) ;
}
static zval * zend_std_call_issetter ( zval * object , zval * member TSRMLS_DC )
{
zval * retval = NULL ;
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
2006-05-10 07:53:23 +08:00
2005-07-08 00:07:09 +08:00
/* __isset handler is called with one argument:
property name
it should return whether the property is set or not
*/
2006-05-10 07:53:23 +08:00
2005-07-08 00:07:09 +08:00
SEPARATE_ARG_IF_REF ( member ) ;
zend_call_method_with_1_params ( & object , ce , & ce - > __isset , ZEND_ISSET_FUNC_NAME , & retval , member ) ;
zval_ptr_dtor ( & member ) ;
return retval ;
}
2003-02-04 20:12:34 +08:00
2003-12-19 04:07:30 +08:00
static int zend_verify_property_access ( zend_property_info * property_info , zend_class_entry * ce TSRMLS_DC )
2003-02-04 20:12:34 +08:00
{
switch ( property_info - > flags & ZEND_ACC_PPP_MASK ) {
case ZEND_ACC_PUBLIC :
return 1 ;
2003-02-05 21:35:52 +08:00
case ZEND_ACC_PROTECTED :
2006-05-28 02:39:53 +08:00
return zend_check_protected ( property_info - > ce , EG ( scope ) ) ;
2003-02-10 18:03:19 +08:00
case ZEND_ACC_PRIVATE :
2007-07-24 19:39:56 +08:00
if ( ( ce = = EG ( scope ) | | property_info - > ce = = EG ( scope ) ) & & EG ( scope ) ) {
2003-02-10 18:03:19 +08:00
return 1 ;
} else {
return 0 ;
}
break ;
2003-02-04 20:12:34 +08:00
}
return 0 ;
}
2003-07-21 20:13:16 +08:00
static inline zend_bool is_derived_class ( zend_class_entry * child_class , zend_class_entry * parent_class )
{
child_class = child_class - > parent ;
while ( child_class ) {
if ( child_class = = parent_class ) {
return 1 ;
}
child_class = child_class - > parent ;
}
return 0 ;
}
2005-04-08 19:35:11 +08:00
ZEND_API struct _zend_property_info * zend_get_property_info ( zend_class_entry * ce , zval * member , int silent TSRMLS_DC )
2003-02-07 18:05:36 +08:00
{
2003-03-19 00:30:23 +08:00
zend_property_info * property_info = NULL ;
zend_property_info * scope_property_info ;
zend_bool denied_access = 0 ;
2005-04-29 18:40:01 +08:00
ulong h ;
2003-03-19 00:30:23 +08:00
2005-04-29 01:40:11 +08:00
if ( Z_STRVAL_P ( member ) [ 0 ] = = ' \0 ' ) {
if ( ! silent ) {
if ( Z_STRLEN_P ( member ) = = 0 ) {
zend_error ( E_ERROR , " Cannot access empty property " ) ;
} else {
zend_error ( E_ERROR , " Cannot access property started with ' \\ 0' " ) ;
}
}
2006-05-28 02:39:53 +08:00
return NULL ;
2005-04-29 01:40:11 +08:00
}
2005-04-29 18:40:01 +08:00
h = zend_get_hash_value ( Z_STRVAL_P ( member ) , Z_STRLEN_P ( member ) + 1 ) ;
2005-04-08 19:35:11 +08:00
if ( zend_hash_quick_find ( & ce - > properties_info , Z_STRVAL_P ( member ) , Z_STRLEN_P ( member ) + 1 , h , ( void * * ) & property_info ) = = SUCCESS ) {
2005-06-10 01:20:44 +08:00
if ( property_info - > flags & ZEND_ACC_SHADOW ) {
/* if it's a shadow - go to access it's private */
property_info = NULL ;
} else {
if ( zend_verify_property_access ( property_info , ce TSRMLS_CC ) ) {
if ( property_info - > flags & ZEND_ACC_CHANGED
& & ! ( property_info - > flags & ZEND_ACC_PRIVATE ) ) {
/* We still need to make sure that we're not in a context
* where the right property is a different ' statically linked ' private
* continue checking below . . .
*/
} else {
if ( ! silent & & ( property_info - > flags & ZEND_ACC_STATIC ) ) {
zend_error ( E_STRICT , " Accessing static property %s::$%s as non static " , ce - > name , Z_STRVAL_P ( member ) ) ;
}
return property_info ;
2005-06-08 16:08:18 +08:00
}
2005-06-10 01:20:44 +08:00
} else {
/* Try to look in the scope instead */
denied_access = 1 ;
2003-03-19 00:30:23 +08:00
}
2003-02-07 18:05:36 +08:00
}
2003-02-14 06:47:25 +08:00
}
2005-04-08 19:35:11 +08:00
if ( EG ( scope ) ! = ce
& & is_derived_class ( ce , EG ( scope ) )
2003-03-19 00:30:23 +08:00
& & EG ( scope )
& & zend_hash_quick_find ( & EG ( scope ) - > properties_info , Z_STRVAL_P ( member ) , Z_STRLEN_P ( member ) + 1 , h , ( void * * ) & scope_property_info ) = = SUCCESS
& & scope_property_info - > flags & ZEND_ACC_PRIVATE ) {
return scope_property_info ;
} else if ( property_info ) {
if ( denied_access ) {
/* Information was available, but we were denied access. Error out. */
2003-12-19 04:07:30 +08:00
if ( silent ) {
return NULL ;
}
2005-04-08 19:35:11 +08:00
zend_error ( E_ERROR , " Cannot access %s property %s::$%s " , zend_visibility_string ( property_info - > flags ) , ce - > name , Z_STRVAL_P ( member ) ) ;
2003-03-19 00:30:23 +08:00
} else {
/* fall through, return property_info... */
}
2003-02-07 18:05:36 +08:00
} else {
EG ( std_property_info ) . flags = ZEND_ACC_PUBLIC ;
EG ( std_property_info ) . name = Z_STRVAL_P ( member ) ;
EG ( std_property_info ) . name_length = Z_STRLEN_P ( member ) ;
2005-11-15 21:35:23 +08:00
EG ( std_property_info ) . h = h ;
2006-05-28 02:39:53 +08:00
EG ( std_property_info ) . ce = ce ;
2003-02-07 18:05:36 +08:00
property_info = & EG ( std_property_info ) ;
}
return property_info ;
}
2003-02-04 20:12:34 +08:00
2006-07-25 01:58:32 +08:00
ZEND_API int zend_check_property_access ( zend_object * zobj , char * prop_info_name , int prop_info_name_len TSRMLS_DC )
2003-12-19 04:07:30 +08:00
{
zend_property_info * property_info ;
char * class_name , * prop_name ;
zval member ;
2006-07-25 01:58:32 +08:00
zend_unmangle_property_name ( prop_info_name , prop_info_name_len , & class_name , & prop_name ) ;
2003-12-19 04:07:30 +08:00
ZVAL_STRING ( & member , prop_name , 0 ) ;
2005-04-08 19:35:11 +08:00
property_info = zend_get_property_info ( zobj - > ce , & member , 1 TSRMLS_CC ) ;
2003-12-19 04:07:30 +08:00
if ( ! property_info ) {
return FAILURE ;
}
2005-06-06 15:52:08 +08:00
if ( prop_info_name [ 0 ] = = ' \0 ' & & prop_info_name [ 1 ] ! = ' * ' ) {
if ( ! ( property_info - > flags & ZEND_ACC_PRIVATE ) ) {
/* we we're looking for a private prop but found a non private one of the same name */
return FAILURE ;
} else if ( strcmp ( prop_info_name + 1 , property_info - > name + 1 ) ) {
/* we we're looking for a private prop but found a private one of the same name but another class */
return FAILURE ;
}
2003-12-19 04:07:30 +08:00
}
return zend_verify_property_access ( property_info , zobj - > ce TSRMLS_CC ) ? SUCCESS : FAILURE ;
}
2005-11-15 21:35:23 +08:00
static int zend_get_property_guard ( zend_object * zobj , zend_property_info * property_info , zval * member , zend_guard * * pguard )
{
zend_property_info info ;
zend_guard stub ;
if ( ! property_info ) {
property_info = & info ;
info . name = Z_STRVAL_P ( member ) ;
info . name_length = Z_STRLEN_P ( member ) ;
info . h = zend_get_hash_value ( Z_STRVAL_P ( member ) , Z_STRLEN_P ( member ) + 1 ) ;
}
if ( ! zobj - > guards ) {
ALLOC_HASHTABLE ( zobj - > guards ) ;
zend_hash_init ( zobj - > guards , 0 , NULL , NULL , 0 ) ;
} else if ( zend_hash_quick_find ( zobj - > guards , property_info - > name , property_info - > name_length + 1 , property_info - > h , ( void * * ) pguard ) = = SUCCESS ) {
return SUCCESS ;
}
stub . in_get = 0 ;
stub . in_set = 0 ;
stub . in_unset = 0 ;
stub . in_isset = 0 ;
return zend_hash_quick_add ( zobj - > guards , property_info - > name , property_info - > name_length + 1 , property_info - > h , ( void * * ) & stub , sizeof ( stub ) , ( void * * ) pguard ) ;
}
2004-03-22 02:07:27 +08:00
zval * zend_std_read_property ( zval * object , zval * member , int type TSRMLS_DC )
2002-02-07 22:08:43 +08:00
{
zend_object * zobj ;
2005-06-03 19:16:19 +08:00
zval * tmp_member = NULL ;
2002-02-07 22:08:43 +08:00
zval * * retval ;
2002-09-04 17:07:58 +08:00
zval * rv = NULL ;
2003-02-04 20:12:34 +08:00
zend_property_info * property_info ;
2004-03-22 02:07:27 +08:00
int silent ;
silent = ( type = = BP_VAR_IS ) ;
2002-04-22 22:22:27 +08:00
zobj = Z_OBJ_P ( object ) ;
2002-02-07 22:08:43 +08:00
if ( member - > type ! = IS_STRING ) {
2005-06-03 19:16:19 +08:00
ALLOC_ZVAL ( tmp_member ) ;
* tmp_member = * member ;
INIT_PZVAL ( tmp_member ) ;
zval_copy_ctor ( tmp_member ) ;
convert_to_string ( tmp_member ) ;
member = tmp_member ;
2002-02-07 22:08:43 +08:00
}
# if DEBUG_OBJECT_HANDLERS
fprintf ( stderr , " Read object #%d property: %s \n " , Z_OBJ_HANDLE_P ( object ) , Z_STRVAL_P ( member ) ) ;
2007-10-11 09:03:19 +08:00
# endif
2003-02-04 20:12:34 +08:00
2004-07-19 22:26:53 +08:00
/* make zend_get_property_info silent if we have getter - we may want to use it */
2005-11-15 21:35:23 +08:00
property_info = zend_get_property_info ( zobj - > ce , member , ( zobj - > ce - > __get ! = NULL ) TSRMLS_CC ) ;
2003-02-04 20:12:34 +08:00
2004-07-19 22:26:53 +08:00
if ( ! property_info | | zend_hash_quick_find ( zobj - > properties , property_info - > name , property_info - > name_length + 1 , property_info - > h , ( void * * ) & retval ) = = FAILURE ) {
2005-11-15 21:35:23 +08:00
zend_guard * guard ;
if ( zobj - > ce - > __get & &
zend_get_property_guard ( zobj , property_info , member , & guard ) = = SUCCESS & &
! guard - > in_get ) {
2002-09-04 17:07:58 +08:00
/* have getter - try with it! */
2005-11-15 21:35:23 +08:00
guard - > in_get = 1 ; /* prevent circular getting */
2002-09-04 17:07:58 +08:00
rv = zend_std_call_getter ( object , member TSRMLS_CC ) ;
2005-11-15 21:35:23 +08:00
guard - > in_get = 0 ;
2002-09-04 17:07:58 +08:00
2002-09-15 15:45:26 +08:00
if ( rv ) {
2002-09-04 17:07:58 +08:00
retval = & rv ;
2007-10-07 13:22:07 +08:00
if ( ! Z_ISREF_P ( rv ) & &
2007-01-10 23:58:08 +08:00
( type = = BP_VAR_W | | type = = BP_VAR_RW | | type = = BP_VAR_UNSET ) ) {
2007-10-07 13:22:07 +08:00
if ( Z_REFCOUNT_P ( rv ) > 0 ) {
2006-12-08 23:55:31 +08:00
zval * tmp = rv ;
ALLOC_ZVAL ( rv ) ;
* rv = * tmp ;
zval_copy_ctor ( rv ) ;
2007-10-07 13:22:07 +08:00
Z_UNSET_ISREF_P ( rv ) ;
Z_SET_REFCOUNT_P ( rv , 0 ) ;
2006-12-08 23:55:31 +08:00
}
2006-07-21 18:32:17 +08:00
if ( Z_TYPE_P ( rv ) ! = IS_OBJECT ) {
zend_error ( E_NOTICE , " Indirect modification of overloaded property %s::$%s has no effect " , zobj - > ce - > name , Z_STRVAL_P ( member ) ) ;
}
}
2002-09-04 17:07:58 +08:00
} else {
2006-05-10 07:53:23 +08:00
retval = & EG ( uninitialized_zval_ptr ) ;
2002-09-04 17:07:58 +08:00
}
} else {
2003-07-22 21:49:33 +08:00
if ( ! silent ) {
zend_error ( E_NOTICE , " Undefined property: %s::$%s " , zobj - > ce - > name , Z_STRVAL_P ( member ) ) ;
}
2003-02-07 18:05:36 +08:00
retval = & EG ( uninitialized_zval_ptr ) ;
2002-02-07 22:08:43 +08:00
}
}
2005-06-03 19:16:19 +08:00
if ( tmp_member ) {
2007-10-07 13:22:07 +08:00
Z_ADDREF_PP ( retval ) ;
2005-06-03 19:16:19 +08:00
zval_ptr_dtor ( & tmp_member ) ;
2007-10-07 13:22:07 +08:00
Z_DELREF_PP ( retval ) ;
2002-02-07 22:08:43 +08:00
}
return * retval ;
}
2003-02-04 20:12:34 +08:00
2002-02-07 22:08:43 +08:00
static void zend_std_write_property ( zval * object , zval * member , zval * value TSRMLS_DC )
{
zend_object * zobj ;
2005-06-03 19:16:19 +08:00
zval * tmp_member = NULL ;
2002-03-10 21:42:37 +08:00
zval * * variable_ptr ;
2003-02-04 20:12:34 +08:00
zend_property_info * property_info ;
2004-07-19 22:26:53 +08:00
2002-04-22 22:22:27 +08:00
zobj = Z_OBJ_P ( object ) ;
2002-02-07 22:08:43 +08:00
if ( member - > type ! = IS_STRING ) {
2005-06-03 19:16:19 +08:00
ALLOC_ZVAL ( tmp_member ) ;
* tmp_member = * member ;
INIT_PZVAL ( tmp_member ) ;
zval_copy_ctor ( tmp_member ) ;
convert_to_string ( tmp_member ) ;
member = tmp_member ;
2002-02-07 22:08:43 +08:00
}
2005-11-15 21:35:23 +08:00
property_info = zend_get_property_info ( zobj - > ce , member , ( zobj - > ce - > __set ! = NULL ) TSRMLS_CC ) ;
2003-02-04 20:12:34 +08:00
2004-07-19 22:26:53 +08:00
if ( property_info & & zend_hash_quick_find ( zobj - > properties , property_info - > name , property_info - > name_length + 1 , property_info - > h , ( void * * ) & variable_ptr ) = = SUCCESS ) {
2006-07-26 23:29:27 +08:00
/* if we already have this value there, we don't actually need to do anything */
if ( * variable_ptr ! = value ) {
2002-10-10 01:14:25 +08:00
/* if we are assigning reference, we shouldn't move it, but instead assign variable
to the same pointer */
if ( PZVAL_IS_REF ( * variable_ptr ) ) {
2005-11-16 19:52:27 +08:00
zval garbage = * * variable_ptr ; /* old value should be destroyed */
2002-10-10 18:07:22 +08:00
/* To check: can't *variable_ptr be some system variable like error_zval here? */
2002-10-10 01:14:25 +08:00
( * variable_ptr ) - > type = value - > type ;
( * variable_ptr ) - > value = value - > value ;
2007-10-07 13:22:07 +08:00
if ( Z_REFCOUNT_P ( value ) > 0 ) {
2003-01-29 16:55:12 +08:00
zval_copy_ctor ( * variable_ptr ) ;
}
2005-11-16 19:52:27 +08:00
zval_dtor ( & garbage ) ;
2006-07-26 23:29:27 +08:00
} else {
zval * garbage = * variable_ptr ;
/* if we assign referenced variable, we should separate it */
2007-10-07 13:22:07 +08:00
Z_ADDREF_P ( value ) ;
2006-07-26 23:29:27 +08:00
if ( PZVAL_IS_REF ( value ) ) {
SEPARATE_ZVAL ( & value ) ;
}
* variable_ptr = value ;
zval_ptr_dtor ( & garbage ) ;
2002-02-07 22:08:43 +08:00
}
}
2006-08-16 04:30:42 +08:00
} else {
2006-07-26 23:29:27 +08:00
int setter_done = 0 ;
2005-11-15 21:35:23 +08:00
zend_guard * guard ;
if ( zobj - > ce - > __set & &
zend_get_property_guard ( zobj , property_info , member , & guard ) = = SUCCESS & &
! guard - > in_set ) {
guard - > in_set = 1 ; /* prevent circular setting */
2002-09-15 15:45:26 +08:00
if ( zend_std_call_setter ( object , member , value TSRMLS_CC ) ! = SUCCESS ) {
2002-09-09 16:59:18 +08:00
/* for now, just ignore it - __set should take care of warnings, etc. */
2002-09-04 17:07:58 +08:00
}
setter_done = 1 ;
2005-11-15 21:35:23 +08:00
guard - > in_set = 0 ;
2002-09-04 17:07:58 +08:00
}
2006-08-16 04:30:42 +08:00
if ( ! setter_done & & property_info ) {
2006-07-26 23:29:27 +08:00
zval * * foo ;
2003-02-07 18:05:36 +08:00
2006-07-26 23:29:27 +08:00
/* if we assign referenced variable, we should separate it */
2007-10-07 13:22:07 +08:00
Z_ADDREF_P ( value ) ;
2006-07-26 23:29:27 +08:00
if ( PZVAL_IS_REF ( value ) ) {
SEPARATE_ZVAL ( & value ) ;
}
zend_hash_quick_update ( zobj - > properties , property_info - > name , property_info - > name_length + 1 , property_info - > h , & value , sizeof ( zval * ) , ( void * * ) & foo ) ;
2002-10-10 01:14:25 +08:00
}
2002-09-04 17:07:58 +08:00
}
2006-07-26 23:29:27 +08:00
2005-06-03 19:16:19 +08:00
if ( tmp_member ) {
zval_ptr_dtor ( & tmp_member ) ;
2002-02-07 22:08:43 +08:00
}
}
2004-02-09 01:23:20 +08:00
zval * zend_std_read_dimension ( zval * object , zval * offset , int type TSRMLS_DC )
2003-07-07 18:53:27 +08:00
{
2003-11-25 04:57:54 +08:00
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
zval * retval ;
2006-05-10 07:53:23 +08:00
2003-11-25 04:57:54 +08:00
if ( instanceof_function_ex ( ce , zend_ce_arrayaccess , 1 TSRMLS_CC ) ) {
2004-07-14 17:01:58 +08:00
if ( offset = = NULL ) {
/* [] construct */
2005-02-02 15:19:22 +08:00
ALLOC_INIT_ZVAL ( offset ) ;
} else {
SEPARATE_ARG_IF_REF ( offset ) ;
2004-07-14 17:01:58 +08:00
}
2004-07-14 17:04:13 +08:00
zend_call_method_with_1_params ( & object , ce , NULL , " offsetget " , & retval , offset ) ;
2005-02-02 15:19:22 +08:00
zval_ptr_dtor ( & offset ) ;
2003-12-11 17:56:06 +08:00
if ( ! retval ) {
if ( ! EG ( exception ) ) {
zend_error ( E_ERROR , " Undefined offset for object of type %s used as array " , ce - > name ) ;
}
return 0 ;
}
2004-02-12 21:49:55 +08:00
/* Undo PZVAL_LOCK() */
2007-10-07 13:22:07 +08:00
Z_DELREF_P ( retval ) ;
2004-02-12 21:49:55 +08:00
2003-11-25 04:57:54 +08:00
return retval ;
} else {
zend_error ( E_ERROR , " Cannot use object of type %s as array " , ce - > name ) ;
return 0 ;
}
2003-07-07 18:53:27 +08:00
}
2003-07-07 17:00:36 +08:00
static void zend_std_write_dimension ( zval * object , zval * offset , zval * value TSRMLS_DC )
{
2003-11-25 04:57:54 +08:00
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
2005-02-02 15:19:22 +08:00
2003-11-25 04:57:54 +08:00
if ( instanceof_function_ex ( ce , zend_ce_arrayaccess , 1 TSRMLS_CC ) ) {
2003-12-23 00:27:14 +08:00
if ( ! offset ) {
2005-02-02 15:19:22 +08:00
ALLOC_INIT_ZVAL ( offset ) ;
} else {
SEPARATE_ARG_IF_REF ( offset ) ;
2003-12-23 00:27:14 +08:00
}
2003-11-25 04:57:54 +08:00
zend_call_method_with_2_params ( & object , ce , NULL , " offsetset " , NULL , offset , value ) ;
2005-02-02 15:19:22 +08:00
zval_ptr_dtor ( & offset ) ;
2003-11-25 04:57:54 +08:00
} else {
zend_error ( E_ERROR , " Cannot use object of type %s as array " , ce - > name ) ;
}
2003-07-07 17:00:36 +08:00
}
2003-11-11 04:44:50 +08:00
static int zend_std_has_dimension ( zval * object , zval * offset , int check_empty TSRMLS_DC )
2003-11-11 00:14:44 +08:00
{
2003-11-25 04:57:54 +08:00
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
zval * retval ;
int result ;
2006-05-10 07:53:23 +08:00
2003-11-25 04:57:54 +08:00
if ( instanceof_function_ex ( ce , zend_ce_arrayaccess , 1 TSRMLS_CC ) ) {
2005-02-02 15:19:22 +08:00
SEPARATE_ARG_IF_REF ( offset ) ;
2003-11-25 04:57:54 +08:00
zend_call_method_with_1_params ( & object , ce , NULL , " offsetexists " , & retval , offset ) ;
2005-03-19 23:32:18 +08:00
if ( retval ) {
result = i_zend_is_true ( retval ) ;
zval_ptr_dtor ( & retval ) ;
2005-07-08 00:07:09 +08:00
if ( check_empty & & result & & ! EG ( exception ) ) {
zend_call_method_with_1_params ( & object , ce , NULL , " offsetget " , & retval , offset ) ;
if ( retval ) {
result = i_zend_is_true ( retval ) ;
zval_ptr_dtor ( & retval ) ;
}
}
2005-03-19 23:32:18 +08:00
} else {
2005-07-08 00:07:09 +08:00
result = 0 ;
2005-03-19 23:32:18 +08:00
}
2005-07-08 00:07:09 +08:00
zval_ptr_dtor ( & offset ) ;
2003-11-25 04:57:54 +08:00
} else {
zend_error ( E_ERROR , " Cannot use object of type %s as array " , ce - > name ) ;
return 0 ;
}
2005-07-08 00:07:09 +08:00
return result ;
2003-11-11 00:14:44 +08:00
}
2003-10-05 15:52:28 +08:00
static zval * * zend_std_get_property_ptr_ptr ( zval * object , zval * member TSRMLS_DC )
2002-02-07 22:08:43 +08:00
{
zend_object * zobj ;
zval tmp_member ;
zval * * retval ;
2003-02-05 17:41:31 +08:00
zend_property_info * property_info ;
2006-05-10 07:53:23 +08:00
2002-04-22 22:22:27 +08:00
zobj = Z_OBJ_P ( object ) ;
2002-02-07 22:08:43 +08:00
if ( member - > type ! = IS_STRING ) {
tmp_member = * member ;
zval_copy_ctor ( & tmp_member ) ;
convert_to_string ( & tmp_member ) ;
member = & tmp_member ;
}
# if DEBUG_OBJECT_HANDLERS
fprintf ( stderr , " Ptr object #%d property: %s \n " , Z_OBJ_HANDLE_P ( object ) , Z_STRVAL_P ( member ) ) ;
2006-05-10 07:53:23 +08:00
# endif
2002-02-07 22:08:43 +08:00
2005-11-15 21:35:23 +08:00
property_info = zend_get_property_info ( zobj - > ce , member , ( zobj - > ce - > __get ! = NULL ) TSRMLS_CC ) ;
2003-02-05 17:41:31 +08:00
2005-10-20 17:47:12 +08:00
if ( ! property_info | | zend_hash_quick_find ( zobj - > properties , property_info - > name , property_info - > name_length + 1 , property_info - > h , ( void * * ) & retval ) = = FAILURE ) {
2002-09-04 17:07:58 +08:00
zval * new_zval ;
2005-11-15 21:35:23 +08:00
zend_guard * guard ;
2002-09-04 17:07:58 +08:00
2005-11-15 21:35:23 +08:00
if ( ! zobj - > ce - > __get | |
zend_get_property_guard ( zobj , property_info , member , & guard ) ! = SUCCESS | |
guard - > in_get ) {
2004-01-05 19:45:46 +08:00
/* we don't have access controls - will just add it */
2002-09-04 17:07:58 +08:00
new_zval = & EG ( uninitialized_zval ) ;
2002-02-07 22:08:43 +08:00
2002-10-21 03:22:04 +08:00
/* zend_error(E_NOTICE, "Undefined property: %s", Z_STRVAL_P(member)); */
2007-10-07 13:22:07 +08:00
Z_ADDREF_P ( new_zval ) ;
2003-02-07 18:05:36 +08:00
zend_hash_quick_update ( zobj - > properties , property_info - > name , property_info - > name_length + 1 , property_info - > h , & new_zval , sizeof ( zval * ) , ( void * * ) & retval ) ;
2002-09-04 17:07:58 +08:00
} else {
/* we do have getter - fail and let it try again with usual get/set */
retval = NULL ;
}
2002-02-07 22:08:43 +08:00
}
if ( member = = & tmp_member ) {
zval_dtor ( member ) ;
}
return retval ;
}
2003-10-05 15:52:28 +08:00
2002-02-07 22:08:43 +08:00
static void zend_std_unset_property ( zval * object , zval * member TSRMLS_DC )
{
zend_object * zobj ;
2005-07-08 00:07:09 +08:00
zval * tmp_member = NULL ;
2003-02-05 22:27:30 +08:00
zend_property_info * property_info ;
2006-05-10 07:53:23 +08:00
2002-04-22 22:22:27 +08:00
zobj = Z_OBJ_P ( object ) ;
2002-02-07 22:08:43 +08:00
if ( member - > type ! = IS_STRING ) {
2005-07-08 00:07:09 +08:00
ALLOC_ZVAL ( tmp_member ) ;
* tmp_member = * member ;
INIT_PZVAL ( tmp_member ) ;
zval_copy_ctor ( tmp_member ) ;
convert_to_string ( tmp_member ) ;
member = tmp_member ;
2002-02-07 22:08:43 +08:00
}
2003-02-05 22:27:30 +08:00
2005-11-15 21:35:23 +08:00
property_info = zend_get_property_info ( zobj - > ce , member , ( zobj - > ce - > __unset ! = NULL ) TSRMLS_CC ) ;
2006-05-10 07:53:23 +08:00
2005-07-08 00:07:09 +08:00
if ( ! property_info | | zend_hash_del ( zobj - > properties , property_info - > name , property_info - > name_length + 1 ) = = FAILURE ) {
2005-11-15 21:35:23 +08:00
zend_guard * guard ;
if ( zobj - > ce - > __unset & &
zend_get_property_guard ( zobj , property_info , member , & guard ) = = SUCCESS & &
! guard - > in_unset ) {
2005-07-08 00:07:09 +08:00
/* have unseter - try with it! */
2006-05-28 02:39:53 +08:00
guard - > in_unset = 1 ; /* prevent circular unsetting */
2005-07-08 00:07:09 +08:00
zend_std_call_unsetter ( object , member TSRMLS_CC ) ;
2005-11-15 21:35:23 +08:00
guard - > in_unset = 0 ;
2005-07-08 00:07:09 +08:00
}
}
if ( tmp_member ) {
zval_ptr_dtor ( & tmp_member ) ;
2002-02-07 22:08:43 +08:00
}
}
2003-07-31 01:12:06 +08:00
static void zend_std_unset_dimension ( zval * object , zval * offset TSRMLS_DC )
{
2003-11-25 04:57:54 +08:00
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
2006-05-10 07:53:23 +08:00
2003-11-25 04:57:54 +08:00
if ( instanceof_function_ex ( ce , zend_ce_arrayaccess , 1 TSRMLS_CC ) ) {
2005-02-02 15:19:22 +08:00
SEPARATE_ARG_IF_REF ( offset ) ;
2005-03-19 23:06:39 +08:00
zend_call_method_with_1_params ( & object , ce , NULL , " offsetunset " , NULL , offset ) ;
2005-02-02 15:19:22 +08:00
zval_ptr_dtor ( & offset ) ;
2003-11-25 04:57:54 +08:00
} else {
zend_error ( E_ERROR , " Cannot use object of type %s as array " , ce - > name ) ;
}
2003-07-31 01:12:06 +08:00
}
2004-01-17 08:39:28 +08:00
ZEND_API void zend_std_call_user_call ( INTERNAL_FUNCTION_PARAMETERS )
2002-09-04 17:07:58 +08:00
{
zend_internal_function * func = ( zend_internal_function * ) EG ( function_state_ptr ) - > function ;
2002-09-04 23:03:41 +08:00
zval * method_name_ptr , * method_args_ptr ;
zval * method_result_ptr = NULL ;
2004-09-29 06:55:22 +08:00
zend_class_entry * ce = Z_OBJCE_P ( this_ptr ) ;
2006-05-10 07:53:23 +08:00
2004-12-18 06:24:51 +08:00
ALLOC_ZVAL ( method_args_ptr ) ;
2004-09-29 06:55:22 +08:00
INIT_PZVAL ( method_args_ptr ) ;
array_init ( method_args_ptr ) ;
2002-09-04 17:07:58 +08:00
2004-09-29 06:55:22 +08:00
if ( zend_copy_parameters_array ( ZEND_NUM_ARGS ( ) , method_args_ptr TSRMLS_CC ) = = FAILURE ) {
zval_dtor ( method_args_ptr ) ;
2002-09-04 17:07:58 +08:00
zend_error ( E_ERROR , " Cannot get arguments for __call " ) ;
RETURN_FALSE ;
}
2004-12-18 06:24:51 +08:00
ALLOC_ZVAL ( method_name_ptr ) ;
2002-09-04 17:07:58 +08:00
INIT_PZVAL ( method_name_ptr ) ;
ZVAL_STRING ( method_name_ptr , func - > function_name , 0 ) ; /* no dup - it's a copy */
2002-09-04 23:03:41 +08:00
/* __call handler is called with two arguments:
2002-09-04 17:07:58 +08:00
method name
array of method parameters
*/
2004-09-29 06:55:22 +08:00
zend_call_method_with_2_params ( & this_ptr , ce , & ce - > __call , ZEND_CALL_FUNC_NAME , & method_result_ptr , method_name_ptr , method_args_ptr ) ;
2002-09-15 15:45:26 +08:00
if ( method_result_ptr ) {
2007-10-07 13:22:07 +08:00
if ( Z_ISREF_P ( method_result_ptr ) | | Z_REFCOUNT_P ( method_result_ptr ) > 1 ) {
2005-05-03 20:47:27 +08:00
RETVAL_ZVAL ( method_result_ptr , 1 , 1 ) ;
} else {
RETVAL_ZVAL ( method_result_ptr , 0 , 1 ) ;
}
2002-09-04 23:03:41 +08:00
}
2006-05-10 07:53:23 +08:00
2002-09-04 17:07:58 +08:00
/* now destruct all auxiliaries */
2004-12-18 06:24:51 +08:00
zval_ptr_dtor ( & method_args_ptr ) ;
zval_ptr_dtor ( & method_name_ptr ) ;
2002-09-04 17:07:58 +08:00
/* destruct the function also, then - we have allocated it in get_method */
efree ( func ) ;
}
2003-02-03 00:17:25 +08:00
/* Ensures that we're allowed to call a private method.
* Returns the function address that should be called , or NULL
* if no such function exists .
*/
2005-04-27 23:45:36 +08:00
static inline zend_function * zend_check_private_int ( zend_function * fbc , zend_class_entry * ce , char * function_name_strval , int function_name_strlen TSRMLS_DC )
2003-02-03 00:17:25 +08:00
{
if ( ! ce ) {
return 0 ;
}
/* We may call a private function if:
* 1. The class of our object is the same as the scope , and the private
* function ( EX ( fbc ) ) has the same scope .
* 2. One of our parent classes are the same as the scope , and it contains
* a private function with the same name that has the same scope .
*/
if ( fbc - > common . scope = = ce & & EG ( scope ) = = ce ) {
/* rule #1 checks out ok, allow the function call */
return fbc ;
}
/* Check rule #2 */
ce = ce - > parent ;
while ( ce ) {
if ( ce = = EG ( scope ) ) {
if ( zend_hash_find ( & ce - > function_table , function_name_strval , function_name_strlen + 1 , ( void * * ) & fbc ) = = SUCCESS
& & fbc - > op_array . fn_flags & ZEND_ACC_PRIVATE
& & fbc - > common . scope = = EG ( scope ) ) {
return fbc ;
}
break ;
}
ce = ce - > parent ;
}
return NULL ;
}
2005-04-27 23:45:36 +08:00
ZEND_API int zend_check_private ( zend_function * fbc , zend_class_entry * ce , char * function_name_strval , int function_name_strlen TSRMLS_DC )
{
return zend_check_private_int ( fbc , ce , function_name_strval , function_name_strlen TSRMLS_CC ) ! = NULL ;
}
2003-02-03 00:17:25 +08:00
/* Ensures that we're allowed to call a protected method.
*/
2003-12-16 18:51:21 +08:00
ZEND_API int zend_check_protected ( zend_class_entry * ce , zend_class_entry * scope )
2003-02-03 00:17:25 +08:00
{
zend_class_entry * fbc_scope = ce ;
/* Is the context that's calling the function, the same as one of
* the function ' s parents ?
*/
while ( fbc_scope ) {
if ( fbc_scope = = scope ) {
return 1 ;
}
fbc_scope = fbc_scope - > parent ;
}
/* Is the function's scope the same as our current object context,
* or any of the parents of our context ?
*/
while ( scope ) {
if ( scope = = ce ) {
return 1 ;
}
scope = scope - > parent ;
}
return 0 ;
}
2006-05-30 04:06:43 +08:00
static inline zend_class_entry * zend_get_function_root_class ( zend_function * fbc )
{
return fbc - > common . prototype ? fbc - > common . prototype - > common . scope : fbc - > common . scope ;
}
2004-10-31 03:11:37 +08:00
static union _zend_function * zend_std_get_method ( zval * * object_ptr , char * method_name , int method_len TSRMLS_DC )
2002-02-07 22:08:43 +08:00
{
zend_object * zobj ;
2003-02-03 00:17:25 +08:00
zend_function * fbc ;
2002-06-06 01:34:56 +08:00
char * lc_method_name ;
2004-10-31 03:11:37 +08:00
zval * object = * object_ptr ;
2007-10-11 09:03:19 +08:00
2002-06-06 01:34:56 +08:00
lc_method_name = do_alloca ( method_len + 1 ) ;
/* Create a zend_copy_str_tolower(dest, src, src_length); */
2003-05-22 06:57:51 +08:00
zend_str_tolower_copy ( lc_method_name , method_name , method_len ) ;
2007-10-11 09:03:19 +08:00
2002-04-22 22:22:27 +08:00
zobj = Z_OBJ_P ( object ) ;
2003-02-03 00:17:25 +08:00
if ( zend_hash_find ( & zobj - > ce - > function_table , lc_method_name , method_len + 1 , ( void * * ) & fbc ) = = FAILURE ) {
2004-05-27 06:19:44 +08:00
free_alloca ( lc_method_name ) ;
2003-01-29 23:02:57 +08:00
if ( zobj - > ce - > __call ) {
2002-09-04 17:07:58 +08:00
zend_internal_function * call_user_call = emalloc ( sizeof ( zend_internal_function ) ) ;
call_user_call - > type = ZEND_INTERNAL_FUNCTION ;
2006-05-10 07:53:23 +08:00
call_user_call - > module = zobj - > ce - > module ;
2002-09-04 17:07:58 +08:00
call_user_call - > handler = zend_std_call_user_call ;
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
call_user_call - > arg_info = NULL ;
call_user_call - > num_args = 0 ;
2002-11-24 04:44:12 +08:00
call_user_call - > scope = zobj - > ce ;
call_user_call - > fn_flags = 0 ;
2002-09-04 17:07:58 +08:00
call_user_call - > function_name = estrndup ( method_name , method_len ) ;
2005-06-16 22:56:13 +08:00
call_user_call - > pass_rest_by_reference = 0 ;
call_user_call - > return_reference = ZEND_RETURN_VALUE ;
2002-09-04 17:07:58 +08:00
return ( union _zend_function * ) call_user_call ;
2003-01-29 23:02:57 +08:00
} else {
return NULL ;
2002-09-04 17:07:58 +08:00
}
2002-02-07 22:08:43 +08:00
}
2002-06-06 01:34:56 +08:00
2003-02-03 00:17:25 +08:00
/* Check access level */
2006-09-12 19:01:16 +08:00
if ( fbc - > op_array . fn_flags & ZEND_ACC_PRIVATE ) {
zend_function * updated_fbc ;
/* Ensure that if we're calling a private function, we're allowed to do so.
*/
updated_fbc = zend_check_private_int ( fbc , Z_OBJ_HANDLER_P ( object , get_class_entry ) ( object TSRMLS_CC ) , lc_method_name , method_len TSRMLS_CC ) ;
if ( ! updated_fbc ) {
zend_error ( E_ERROR , " Call to %s method %s::%s() from context '%s' " , zend_visibility_string ( fbc - > common . fn_flags ) , ZEND_FN_SCOPE_NAME ( fbc ) , method_name , EG ( scope ) ? EG ( scope ) - > name : " " ) ;
}
fbc = updated_fbc ;
} else {
2003-02-03 00:17:25 +08:00
/* Ensure that we haven't overridden a private function and end up calling
* the overriding public function . . .
*/
2007-07-12 18:32:09 +08:00
if ( EG ( scope ) & &
is_derived_class ( fbc - > common . scope , EG ( scope ) ) & &
fbc - > op_array . fn_flags & ZEND_ACC_CHANGED ) {
2003-02-03 00:17:25 +08:00
zend_function * priv_fbc ;
2003-06-09 03:28:29 +08:00
if ( zend_hash_find ( & EG ( scope ) - > function_table , lc_method_name , method_len + 1 , ( void * * ) & priv_fbc ) = = SUCCESS
2005-06-17 18:50:45 +08:00
& & priv_fbc - > common . fn_flags & ZEND_ACC_PRIVATE
& & priv_fbc - > common . scope = = EG ( scope ) ) {
2003-02-03 00:17:25 +08:00
fbc = priv_fbc ;
}
}
2006-09-12 19:01:16 +08:00
if ( ( fbc - > common . fn_flags & ZEND_ACC_PROTECTED ) ) {
/* Ensure that if we're calling a protected function, we're allowed to do so.
*/
if ( ! zend_check_protected ( zend_get_function_root_class ( fbc ) , EG ( scope ) ) ) {
zend_error ( E_ERROR , " Call to %s method %s::%s() from context '%s' " , zend_visibility_string ( fbc - > common . fn_flags ) , ZEND_FN_SCOPE_NAME ( fbc ) , method_name , EG ( scope ) ? EG ( scope ) - > name : " " ) ;
}
2003-02-03 00:17:25 +08:00
}
}
2002-06-06 01:34:56 +08:00
free_alloca ( lc_method_name ) ;
2003-02-03 00:17:25 +08:00
return fbc ;
2002-02-07 22:08:43 +08:00
}
2007-09-29 16:52:40 +08:00
ZEND_API void zend_std_callstatic_user_call ( INTERNAL_FUNCTION_PARAMETERS ) /* { { { */
{
zend_internal_function * func = ( zend_internal_function * ) EG ( function_state_ptr ) - > function ;
zval * method_name_ptr , * method_args_ptr ;
zval * method_result_ptr = NULL ;
zend_class_entry * ce = EG ( scope ) ;
2007-10-11 09:03:19 +08:00
2007-09-29 16:52:40 +08:00
ALLOC_ZVAL ( method_args_ptr ) ;
INIT_PZVAL ( method_args_ptr ) ;
array_init ( method_args_ptr ) ;
if ( zend_copy_parameters_array ( ZEND_NUM_ARGS ( ) , method_args_ptr TSRMLS_CC ) = = FAILURE ) {
zval_dtor ( method_args_ptr ) ;
zend_error ( E_ERROR , " Cannot get arguments for " ZEND_CALLSTATIC_FUNC_NAME ) ;
RETURN_FALSE ;
}
ALLOC_ZVAL ( method_name_ptr ) ;
INIT_PZVAL ( method_name_ptr ) ;
ZVAL_STRING ( method_name_ptr , func - > function_name , 0 ) ; /* no dup - it's a copy */
/* __callStatic handler is called with two arguments:
method name
array of method parameters
*/
zend_call_method_with_2_params ( NULL , ce , & ce - > __callstatic , ZEND_CALLSTATIC_FUNC_NAME , & method_result_ptr , method_name_ptr , method_args_ptr ) ;
if ( method_result_ptr ) {
2007-10-07 13:22:07 +08:00
if ( Z_ISREF_P ( method_result_ptr ) | | Z_REFCOUNT_P ( method_result_ptr ) > 1 ) {
2007-09-29 16:52:40 +08:00
RETVAL_ZVAL ( method_result_ptr , 1 , 1 ) ;
} else {
RETVAL_ZVAL ( method_result_ptr , 0 , 1 ) ;
}
}
/* now destruct all auxiliaries */
zval_ptr_dtor ( & method_args_ptr ) ;
zval_ptr_dtor ( & method_name_ptr ) ;
/* destruct the function also, then - we have allocated it in get_method */
efree ( func ) ;
}
/* }}} */
2003-02-03 00:17:25 +08:00
/* This is not (yet?) in the API, but it belongs in the built-in objects callbacks */
2003-12-16 18:51:21 +08:00
ZEND_API zend_function * zend_std_get_static_method ( zend_class_entry * ce , char * function_name_strval , int function_name_strlen TSRMLS_DC )
2003-02-03 00:17:25 +08:00
{
zend_function * fbc ;
2007-09-29 16:52:40 +08:00
if ( zend_hash_find ( & ce - > function_table , function_name_strval , function_name_strlen + 1 , ( void * * ) & fbc ) = = FAILURE ) {
if ( ce - > __callstatic ) {
zend_internal_function * callstatic_user_call = emalloc ( sizeof ( zend_internal_function ) ) ;
callstatic_user_call - > type = ZEND_INTERNAL_FUNCTION ;
callstatic_user_call - > module = ce - > module ;
callstatic_user_call - > handler = zend_std_callstatic_user_call ;
callstatic_user_call - > arg_info = NULL ;
callstatic_user_call - > num_args = 0 ;
callstatic_user_call - > scope = ce ;
2007-10-11 09:03:19 +08:00
callstatic_user_call - > fn_flags = ZEND_ACC_STATIC | ZEND_ACC_PUBLIC ;
2007-09-29 16:52:40 +08:00
callstatic_user_call - > function_name = estrndup ( function_name_strval , function_name_strlen ) ;
callstatic_user_call - > pass_rest_by_reference = 0 ;
callstatic_user_call - > return_reference = ZEND_RETURN_VALUE ;
return ( zend_function * ) callstatic_user_call ;
} else {
zend_error ( E_ERROR , " Call to undefined method %s::%s() " , ce - > name ? ce - > name : " " , function_name_strval ) ;
2003-03-12 07:19:45 +08:00
}
2003-02-03 00:17:25 +08:00
}
if ( fbc - > op_array . fn_flags & ZEND_ACC_PUBLIC ) {
/* No further checks necessary, most common case */
} else if ( fbc - > op_array . fn_flags & ZEND_ACC_PRIVATE ) {
zend_function * updated_fbc ;
/* Ensure that if we're calling a private function, we're allowed to do so.
*/
2006-05-10 07:53:23 +08:00
updated_fbc = zend_check_private_int ( fbc , EG ( scope ) , function_name_strval , function_name_strlen TSRMLS_CC ) ;
2003-02-03 00:17:25 +08:00
if ( ! updated_fbc ) {
zend_error ( E_ERROR , " Call to %s method %s::%s() from context '%s' " , zend_visibility_string ( fbc - > common . fn_flags ) , ZEND_FN_SCOPE_NAME ( fbc ) , function_name_strval , EG ( scope ) ? EG ( scope ) - > name : " " ) ;
}
fbc = updated_fbc ;
} else if ( ( fbc - > common . fn_flags & ZEND_ACC_PROTECTED ) ) {
/* Ensure that if we're calling a protected function, we're allowed to do so.
*/
2006-05-30 04:06:43 +08:00
if ( ! zend_check_protected ( zend_get_function_root_class ( fbc ) , EG ( scope ) ) ) {
2003-02-03 00:17:25 +08:00
zend_error ( E_ERROR , " Call to %s method %s::%s() from context '%s' " , zend_visibility_string ( fbc - > common . fn_flags ) , ZEND_FN_SCOPE_NAME ( fbc ) , function_name_strval , EG ( scope ) ? EG ( scope ) - > name : " " ) ;
}
}
return fbc ;
}
2003-12-16 18:51:21 +08:00
ZEND_API zval * * zend_std_get_static_property ( zend_class_entry * ce , char * property_name , int property_name_len , zend_bool silent TSRMLS_DC )
2003-02-05 21:35:52 +08:00
{
zval * * retval = NULL ;
zend_class_entry * tmp_ce = ce ;
zend_property_info * property_info ;
zend_property_info std_property_info ;
2005-06-10 01:20:44 +08:00
if ( zend_hash_find ( & ce - > properties_info , property_name , property_name_len + 1 , ( void * * ) & property_info ) = = FAILURE | | ( property_info - > flags & ZEND_ACC_SHADOW ) ) {
2003-06-02 20:13:11 +08:00
std_property_info . flags = ZEND_ACC_PUBLIC ;
std_property_info . name = property_name ;
std_property_info . name_length = property_name_len ;
std_property_info . h = zend_get_hash_value ( std_property_info . name , std_property_info . name_length + 1 ) ;
2006-05-28 02:39:53 +08:00
std_property_info . ce = ce ;
2003-06-02 20:13:11 +08:00
property_info = & std_property_info ;
}
2003-02-05 21:35:52 +08:00
2005-05-18 23:14:36 +08:00
# if DEBUG_OBJECT_HANDLERS
2003-06-02 20:13:11 +08:00
zend_printf ( " Access type for %s::%s is %s \n " , ce - > name , property_name , zend_visibility_string ( property_info - > flags ) ) ;
2003-02-05 21:35:52 +08:00
# endif
2005-05-18 23:30:35 +08:00
if ( ! zend_verify_property_access ( property_info , ce TSRMLS_CC ) ) {
2005-02-28 06:22:26 +08:00
if ( ! silent ) {
zend_error ( E_ERROR , " Cannot access %s property %s::$%s " , zend_visibility_string ( property_info - > flags ) , ce - > name , property_name ) ;
}
return NULL ;
2003-06-02 20:13:11 +08:00
}
2003-02-05 21:35:52 +08:00
2005-09-01 18:05:32 +08:00
zend_update_class_constants ( tmp_ce TSRMLS_CC ) ;
2005-12-01 19:48:17 +08:00
zend_hash_quick_find ( CE_STATIC_MEMBERS ( tmp_ce ) , property_info - > name , property_info - > name_length + 1 , property_info - > h , ( void * * ) & retval ) ;
2003-02-05 21:35:52 +08:00
if ( ! retval ) {
2003-02-17 22:06:39 +08:00
if ( silent ) {
return NULL ;
} else {
zend_error ( E_ERROR , " Access to undeclared static property: %s::$%s " , ce - > name , property_name ) ;
2003-02-05 21:35:52 +08:00
}
}
2006-05-10 07:53:23 +08:00
2003-02-05 21:35:52 +08:00
return retval ;
}
2003-12-16 18:51:21 +08:00
ZEND_API zend_bool zend_std_unset_static_property ( zend_class_entry * ce , char * property_name , int property_name_len TSRMLS_DC )
2003-02-17 22:06:39 +08:00
{
zend_error ( E_ERROR , " Attempt to unset static property %s::$%s " , ce - > name , property_name ) ;
return 0 ;
}
2006-07-05 19:41:25 +08:00
ZEND_API union _zend_function * zend_std_get_constructor ( zval * object TSRMLS_DC )
2002-02-07 22:08:43 +08:00
{
2003-02-03 00:17:25 +08:00
zend_object * zobj = Z_OBJ_P ( object ) ;
zend_function * constructor = zobj - > ce - > constructor ;
if ( constructor ) {
if ( constructor - > op_array . fn_flags & ZEND_ACC_PUBLIC ) {
/* No further checks necessary */
} else if ( constructor - > op_array . fn_flags & ZEND_ACC_PRIVATE ) {
/* Ensure that if we're calling a private function, we're allowed to do so.
*/
2006-05-10 07:53:23 +08:00
if ( Z_OBJ_HANDLER_P ( object , get_class_entry ) ( object TSRMLS_CC ) ! = EG ( scope ) ) {
2006-07-05 19:39:00 +08:00
if ( EG ( scope ) ) {
zend_error ( E_ERROR , " Call to private %s::%s() from context '%s' " , constructor - > common . scope - > name , constructor - > common . function_name , EG ( scope ) - > name ) ;
} else {
zend_error ( E_ERROR , " Call to private %s::%s() from invalid context " , constructor - > common . scope - > name , constructor - > common . function_name ) ;
}
2003-02-03 00:17:25 +08:00
}
} else if ( ( constructor - > common . fn_flags & ZEND_ACC_PROTECTED ) ) {
/* Ensure that if we're calling a protected function, we're allowed to do so.
*/
2006-05-30 04:06:43 +08:00
if ( ! zend_check_protected ( zend_get_function_root_class ( constructor ) , EG ( scope ) ) ) {
2006-07-05 19:39:00 +08:00
if ( EG ( scope ) ) {
2006-07-05 19:54:08 +08:00
zend_error ( E_ERROR , " Call to protected %s::%s() from context '%s' " , constructor - > common . scope - > name , constructor - > common . function_name , EG ( scope ) - > name ) ;
2006-07-05 19:39:00 +08:00
} else {
2006-07-05 19:54:08 +08:00
zend_error ( E_ERROR , " Call to protected %s::%s() from invalid context " , constructor - > common . scope - > name , constructor - > common . function_name ) ;
2006-07-05 19:39:00 +08:00
}
2003-02-03 00:17:25 +08:00
}
}
}
return constructor ;
2002-02-07 22:08:43 +08:00
}
2003-02-05 22:27:30 +08:00
2002-02-07 22:08:43 +08:00
int zend_compare_symbol_tables_i ( HashTable * ht1 , HashTable * ht2 TSRMLS_DC ) ;
2003-02-05 22:27:30 +08:00
2002-02-07 22:08:43 +08:00
static int zend_std_compare_objects ( zval * o1 , zval * o2 TSRMLS_DC )
{
zend_object * zobj1 , * zobj2 ;
2006-05-10 07:53:23 +08:00
2002-04-22 22:22:27 +08:00
zobj1 = Z_OBJ_P ( o1 ) ;
zobj2 = Z_OBJ_P ( o2 ) ;
2002-02-07 22:08:43 +08:00
2002-09-15 15:45:26 +08:00
if ( zobj1 - > ce ! = zobj2 - > ce ) {
2002-02-07 22:08:43 +08:00
return 1 ; /* different classes */
}
return zend_compare_symbol_tables_i ( zobj1 - > properties , zobj2 - > properties TSRMLS_CC ) ;
}
2005-05-03 00:18:02 +08:00
static int zend_std_has_property ( zval * object , zval * member , int has_set_exists TSRMLS_DC )
2002-02-07 22:08:43 +08:00
{
zend_object * zobj ;
int result ;
zval * * value ;
2005-07-08 00:07:09 +08:00
zval * tmp_member = NULL ;
2003-02-05 22:27:30 +08:00
zend_property_info * property_info ;
2006-05-10 07:53:23 +08:00
2003-02-05 22:27:30 +08:00
zobj = Z_OBJ_P ( object ) ;
2006-05-10 07:53:23 +08:00
if ( member - > type ! = IS_STRING ) {
ALLOC_ZVAL ( tmp_member ) ;
2005-07-08 00:07:09 +08:00
* tmp_member = * member ;
INIT_PZVAL ( tmp_member ) ;
zval_copy_ctor ( tmp_member ) ;
convert_to_string ( tmp_member ) ;
member = tmp_member ;
2002-02-07 22:08:43 +08:00
}
2003-02-05 22:27:30 +08:00
# if DEBUG_OBJECT_HANDLERS
fprintf ( stderr , " Read object #%d property: %s \n " , Z_OBJ_HANDLE_P ( object ) , Z_STRVAL_P ( member ) ) ;
2006-05-10 07:53:23 +08:00
# endif
2003-02-05 22:27:30 +08:00
2005-07-08 00:07:09 +08:00
property_info = zend_get_property_info ( zobj - > ce , member , 1 TSRMLS_CC ) ;
if ( ! property_info | | zend_hash_quick_find ( zobj - > properties , property_info - > name , property_info - > name_length + 1 , property_info - > h , ( void * * ) & value ) = = FAILURE ) {
2005-11-15 21:35:23 +08:00
zend_guard * guard ;
2005-07-08 00:07:09 +08:00
result = 0 ;
2005-11-15 21:35:23 +08:00
if ( ( has_set_exists ! = 2 ) & &
zobj - > ce - > __isset & &
zend_get_property_guard ( zobj , property_info , member , & guard ) = = SUCCESS & &
! guard - > in_isset ) {
2005-07-08 00:07:09 +08:00
zval * rv ;
2003-02-05 22:27:30 +08:00
2005-07-08 00:07:09 +08:00
/* have issetter - try with it! */
2005-11-15 21:35:23 +08:00
guard - > in_isset = 1 ; /* prevent circular getting */
2005-07-08 00:07:09 +08:00
rv = zend_std_call_issetter ( object , member TSRMLS_CC ) ;
if ( rv ) {
result = zend_is_true ( rv ) ;
zval_ptr_dtor ( & rv ) ;
2005-11-15 21:35:23 +08:00
if ( has_set_exists & & result & & ! EG ( exception ) & & zobj - > ce - > __get & & ! guard - > in_get ) {
guard - > in_get = 1 ;
2005-07-08 00:07:09 +08:00
rv = zend_std_call_getter ( object , member TSRMLS_CC ) ;
2005-11-15 21:35:23 +08:00
guard - > in_get = 0 ;
2005-07-08 00:07:09 +08:00
if ( rv ) {
2007-10-07 13:22:07 +08:00
Z_ADDREF_P ( rv ) ;
2005-07-08 00:07:09 +08:00
result = i_zend_is_true ( rv ) ;
zval_ptr_dtor ( & rv ) ;
}
}
}
2005-11-15 21:35:23 +08:00
guard - > in_isset = 0 ;
2005-07-08 00:07:09 +08:00
}
} else {
2005-05-03 00:18:02 +08:00
switch ( has_set_exists ) {
case 0 :
2005-04-26 04:41:26 +08:00
result = ( Z_TYPE_PP ( value ) ! = IS_NULL ) ;
2005-05-03 00:18:02 +08:00
break ;
default :
result = zend_is_true ( * value ) ;
break ;
case 2 :
result = 1 ;
break ;
2002-02-07 22:08:43 +08:00
}
}
2005-07-08 00:07:09 +08:00
if ( tmp_member ) {
zval_ptr_dtor ( & tmp_member ) ;
2002-02-07 22:08:43 +08:00
}
return result ;
}
2003-02-05 22:27:30 +08:00
2002-04-30 17:56:48 +08:00
zend_class_entry * zend_std_object_get_class ( zval * object TSRMLS_DC )
{
zend_object * zobj ;
zobj = Z_OBJ_P ( object ) ;
return zobj - > ce ;
}
2003-01-12 21:56:51 +08:00
int zend_std_object_get_class_name ( zval * object , char * * class_name , zend_uint * class_name_len , int parent TSRMLS_DC )
{
zend_object * zobj ;
2003-04-22 01:01:34 +08:00
zend_class_entry * ce ;
2003-01-12 21:56:51 +08:00
zobj = Z_OBJ_P ( object ) ;
2003-01-14 20:13:51 +08:00
if ( parent ) {
if ( ! zobj - > ce - > parent ) {
2003-01-12 21:56:51 +08:00
return FAILURE ;
}
2003-04-22 01:01:34 +08:00
ce = zobj - > ce - > parent ;
2003-01-12 21:56:51 +08:00
} else {
2003-04-22 01:01:34 +08:00
ce = zobj - > ce ;
2003-01-12 21:56:51 +08:00
}
2003-04-22 01:01:34 +08:00
2003-06-04 16:16:55 +08:00
* class_name_len = ce - > name_length ;
* class_name = estrndup ( ce - > name , ce - > name_length ) ;
2003-01-12 21:56:51 +08:00
return SUCCESS ;
}
2006-05-10 07:53:23 +08:00
ZEND_API int zend_std_cast_object_tostring ( zval * readobj , zval * writeobj , int type TSRMLS_DC )
2003-12-16 00:59:21 +08:00
{
2006-05-10 07:53:23 +08:00
zval * retval ;
zend_class_entry * ce ;
2003-12-16 00:59:21 +08:00
switch ( type ) {
case IS_STRING :
2006-05-10 07:53:23 +08:00
ce = Z_OBJCE_P ( readobj ) ;
if ( ce - > __tostring & &
2006-05-11 05:12:48 +08:00
( zend_call_method_with_0_params ( & readobj , ce , & ce - > __tostring , " __tostring " , & retval ) | | EG ( exception ) ) ) {
2006-05-10 07:53:23 +08:00
if ( EG ( exception ) ) {
2006-05-11 05:12:48 +08:00
if ( retval ) {
zval_ptr_dtor ( & retval ) ;
}
2006-05-10 07:53:23 +08:00
zend_error ( E_ERROR , " Method %s::__toString() must not throw an exception " , ce - > name ) ;
return FAILURE ;
}
if ( Z_TYPE_P ( retval ) = = IS_STRING ) {
INIT_PZVAL ( writeobj ) ;
ZVAL_ZVAL ( writeobj , retval , 1 , 1 ) ;
if ( Z_TYPE_P ( writeobj ) ! = type ) {
convert_to_explicit_type ( writeobj , type ) ;
2003-12-16 00:59:21 +08:00
}
2006-05-10 07:53:23 +08:00
return SUCCESS ;
2003-12-16 00:59:21 +08:00
} else {
2006-05-10 07:53:23 +08:00
zval_ptr_dtor ( & retval ) ;
INIT_PZVAL ( writeobj ) ;
ZVAL_EMPTY_STRING ( writeobj ) ;
zend_error ( E_RECOVERABLE_ERROR , " Method %s::__toString() must return a string value " , ce - > name ) ;
return SUCCESS ;
2003-12-16 00:59:21 +08:00
}
}
2006-05-10 07:53:23 +08:00
return FAILURE ;
case IS_BOOL :
INIT_PZVAL ( writeobj ) ;
ZVAL_BOOL ( writeobj , 1 ) ;
return SUCCESS ;
case IS_LONG :
ce = Z_OBJCE_P ( readobj ) ;
zend_error ( E_NOTICE , " Object of class %s could not be converted to int " , ce - > name ) ;
INIT_PZVAL ( writeobj ) ;
ZVAL_LONG ( writeobj , 1 ) ;
return SUCCESS ;
case IS_DOUBLE :
ce = Z_OBJCE_P ( readobj ) ;
zend_error ( E_NOTICE , " Object of class %s could not be converted to double " , ce - > name ) ;
INIT_PZVAL ( writeobj ) ;
ZVAL_DOUBLE ( writeobj , 1 ) ;
return SUCCESS ;
2003-12-16 00:59:21 +08:00
default :
break ;
}
return FAILURE ;
}
2003-09-18 19:38:33 +08:00
2003-12-22 21:09:15 +08:00
ZEND_API zend_object_handlers std_object_handlers = {
2003-07-07 17:12:15 +08:00
zend_objects_store_add_ref , /* add_ref */
zend_objects_store_del_ref , /* del_ref */
zend_objects_clone_obj , /* clone_obj */
2006-05-10 07:53:23 +08:00
2003-07-07 17:12:15 +08:00
zend_std_read_property , /* read_property */
zend_std_write_property , /* write_property */
2003-07-07 18:53:27 +08:00
zend_std_read_dimension , /* read_dimension */
2003-07-07 17:12:15 +08:00
zend_std_write_dimension , /* write_dimension */
2003-10-05 15:52:28 +08:00
zend_std_get_property_ptr_ptr , /* get_property_ptr_ptr */
2003-07-07 17:12:15 +08:00
NULL , /* get */
NULL , /* set */
zend_std_has_property , /* has_property */
zend_std_unset_property , /* unset_property */
2003-11-11 00:14:44 +08:00
zend_std_has_dimension , /* has_dimension */
2003-07-31 01:12:06 +08:00
zend_std_unset_dimension , /* unset_dimension */
2003-07-07 17:12:15 +08:00
zend_std_get_properties , /* get_properties */
zend_std_get_method , /* get_method */
NULL , /* call_method */
zend_std_get_constructor , /* get_constructor */
zend_std_object_get_class , /* get_class_entry */
zend_std_object_get_class_name , /* get_class_name */
zend_std_compare_objects , /* compare_objects */
2006-05-10 07:53:23 +08:00
zend_std_cast_object_tostring , /* cast_object */
2004-05-04 23:03:28 +08:00
NULL , /* count_elements */
2007-10-11 09:03:19 +08:00
NULL , /* get_debug_info */
2002-02-07 22:08:43 +08:00
} ;
2003-02-01 09:49:15 +08:00
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* indent - tabs - mode : t
* End :
*/