2006-05-09 23:53:23 +00:00
/*
2003-02-01 01:49:15 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| Zend Engine |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2013-01-01 08:28:54 +00:00
| Copyright ( c ) 1998 - 2013 Zend Technologies Ltd . ( http : //www.zend.com) |
2003-02-01 01:49:15 +00: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-10 20:04:29 +00:00
| available through the world - wide - web at the following url : |
2003-02-01 01:49:15 +00: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 14:08:43 +00:00
# include "zend.h"
# include "zend_globals.h"
# include "zend_variables.h"
# include "zend_API.h"
# include "zend_objects.h"
2002-05-31 12:09:19 +00:00
# include "zend_objects_API.h"
2002-02-07 14:08:43 +00:00
# include "zend_object_handlers.h"
2003-11-24 20:57:54 +00:00
# include "zend_interfaces.h"
2008-08-14 21:36:56 +00:00
# include "zend_closures.h"
2009-06-18 13:46:16 +00:00
# include "zend_compile.h"
2002-02-07 14:08:43 +00:00
2002-02-21 11:50:44 +00:00
# define DEBUG_OBJECT_HANDLERS 0
2002-02-07 14:08:43 +00:00
2010-05-24 14:11:39 +00:00
# define Z_OBJ_P(zval_p) \
( ( zend_object * ) ( EG ( objects_store ) . object_buckets [ Z_OBJ_HANDLE_P ( zval_p ) ] . bucket . obj . object ) )
2003-01-12 14:39:45 +00:00
2013-01-09 07:30:50 +00:00
# define Z_OBJ_PROTECT_RECURSION(zval_p) \
do { \
if ( EG ( objects_store ) . object_buckets [ Z_OBJ_HANDLE_P ( zval_p ) ] . apply_count + + > = 3 ) { \
zend_error ( E_ERROR , " Nesting level too deep - recursive dependency? " ) ; \
} \
} while ( 0 )
# define Z_OBJ_UNPROTECT_RECURSION(zval_p) \
EG ( objects_store ) . object_buckets [ Z_OBJ_HANDLE_P ( zval_p ) ] . apply_count - -
2002-09-04 09:07:58 +00: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 01:03:19 +00:00
__get / __set for this property of this object will be made , to prevent endless
2007-03-23 17:16:55 +00:00
recursion and enable accessors to change properties array .
2002-09-04 09:07:58 +00:00
if we have __call and method which is not part of the class function table is
2006-05-09 23:53:23 +00:00
called , we cal __call handler .
2002-09-04 09:07:58 +00:00
*/
2010-05-24 14:11:39 +00:00
ZEND_API void rebuild_object_properties ( zend_object * zobj ) /* { { { */
{
if ( ! zobj - > properties ) {
HashPosition pos ;
zend_property_info * prop_info ;
zend_class_entry * ce = zobj - > ce ;
ALLOC_HASHTABLE ( zobj - > properties ) ;
zend_hash_init ( zobj - > properties , 0 , NULL , ZVAL_PTR_DTOR , 0 ) ;
if ( ce - > default_properties_count ) {
for ( zend_hash_internal_pointer_reset_ex ( & ce - > properties_info , & pos ) ;
zend_hash_get_current_data_ex ( & ce - > properties_info , ( void * * ) & prop_info , & pos ) = = SUCCESS ;
zend_hash_move_forward_ex ( & ce - > properties_info , & pos ) ) {
if ( /*prop_info->ce == ce &&*/
2012-05-13 05:12:48 +00:00
( prop_info - > flags & ZEND_ACC_STATIC ) = = 0 & &
2010-05-24 14:11:39 +00:00
prop_info - > offset > = 0 & &
zobj - > properties_table [ prop_info - > offset ] ) {
zend_hash_quick_add ( zobj - > properties , prop_info - > name , prop_info - > name_length + 1 , prop_info - > h , ( void * * ) & zobj - > properties_table [ prop_info - > offset ] , sizeof ( zval * ) , ( void * * ) & zobj - > properties_table [ prop_info - > offset ] ) ;
2012-05-13 05:12:48 +00:00
}
2010-05-24 14:11:39 +00:00
}
while ( ce - > parent & & ce - > parent - > default_properties_count ) {
ce = ce - > parent ;
for ( zend_hash_internal_pointer_reset_ex ( & ce - > properties_info , & pos ) ;
zend_hash_get_current_data_ex ( & ce - > properties_info , ( void * * ) & prop_info , & pos ) = = SUCCESS ;
zend_hash_move_forward_ex ( & ce - > properties_info , & pos ) ) {
if ( prop_info - > ce = = ce & &
2012-05-13 05:12:48 +00:00
( prop_info - > flags & ZEND_ACC_STATIC ) = = 0 & &
( prop_info - > flags & ZEND_ACC_PRIVATE ) ! = 0 & &
2010-05-24 14:11:39 +00:00
prop_info - > offset > = 0 & &
2011-12-16 19:02:52 +00:00
zobj - > properties_table [ prop_info - > offset ] ) {
2011-12-19 16:48:18 +00:00
zend_hash_quick_add ( zobj - > properties , prop_info - > name , prop_info - > name_length + 1 , prop_info - > h , ( void * * ) & zobj - > properties_table [ prop_info - > offset ] , sizeof ( zval * ) , ( void * * ) & zobj - > properties_table [ prop_info - > offset ] ) ;
2012-05-13 05:12:48 +00:00
}
2010-05-24 14:11:39 +00:00
}
}
}
}
}
2011-09-15 14:50:38 +00:00
/* }}} */
2010-05-24 14:11:39 +00:00
2007-11-02 19:40:39 +00:00
ZEND_API HashTable * zend_std_get_properties ( zval * object TSRMLS_DC ) /* { { { */
2002-02-07 14:08:43 +00:00
{
zend_object * zobj ;
2002-04-22 14:22:27 +00:00
zobj = Z_OBJ_P ( object ) ;
2010-05-24 14:11:39 +00:00
if ( ! zobj - > properties ) {
rebuild_object_properties ( zobj ) ;
}
2002-02-07 14:08:43 +00:00
return zobj - > properties ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2011-11-02 06:31:33 +00:00
ZEND_API HashTable * zend_std_get_gc ( zval * object , zval * * * table , int * n TSRMLS_DC ) /* { { { */
{
if ( Z_OBJ_HANDLER_P ( object , get_properties ) ! = zend_std_get_properties ) {
* table = NULL ;
* n = 0 ;
return Z_OBJ_HANDLER_P ( object , get_properties ) ( object TSRMLS_CC ) ;
} else {
zend_object * zobj = Z_OBJ_P ( object ) ;
if ( zobj - > properties ) {
* table = NULL ;
* n = 0 ;
return zobj - > properties ;
} else {
* table = zobj - > properties_table ;
* n = zobj - > ce - > default_properties_count ;
return NULL ;
}
}
}
/* }}} */
2007-11-02 19:40:39 +00:00
ZEND_API HashTable * zend_std_get_debug_info ( zval * object , int * is_temp TSRMLS_DC ) /* { { { */
{
* is_temp = 0 ;
return zend_std_get_properties ( object TSRMLS_CC ) ;
}
/* }}} */
2002-02-07 14:08:43 +00:00
2007-11-02 19:40:39 +00:00
static zval * zend_std_call_getter ( zval * object , zval * member TSRMLS_DC ) /* { { { */
2002-09-04 09:07:58 +00:00
{
zval * retval = NULL ;
2004-09-28 22:55:22 +00:00
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
2006-05-09 23:53:23 +00:00
2004-09-28 22:55:22 +00:00
/* __get handler is called with one argument:
property name
2002-09-04 09:07:58 +00:00
it should return whether the call was successfull or not
*/
2006-05-09 23:53:23 +00:00
2005-02-02 07:19:22 +00:00
SEPARATE_ARG_IF_REF ( member ) ;
2004-09-28 22:55:22 +00:00
zend_call_method_with_1_params ( & object , ce , & ce - > __get , ZEND_GET_FUNC_NAME , & retval , member ) ;
2002-09-04 09:07:58 +00:00
2005-02-02 07:19:22 +00:00
zval_ptr_dtor ( & member ) ;
2003-06-29 23:41:49 +00:00
if ( retval ) {
2007-10-07 05:22:07 +00:00
Z_DELREF_P ( retval ) ;
2003-06-29 23:41:49 +00:00
}
2002-09-04 09:07:58 +00:00
return retval ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2002-09-04 09:07:58 +00:00
2007-11-02 19:40:39 +00:00
static int zend_std_call_setter ( zval * object , zval * member , zval * value TSRMLS_DC ) /* { { { */
2002-09-04 09:07:58 +00:00
{
zval * retval = NULL ;
2005-03-19 15:32:18 +00:00
int result ;
2004-09-28 22:55:22 +00:00
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
2005-02-02 07:19:22 +00:00
SEPARATE_ARG_IF_REF ( member ) ;
2007-10-07 05:22:07 +00:00
Z_ADDREF_P ( value ) ;
2004-09-28 22:55:22 +00:00
2002-09-04 09:07:58 +00:00
/* __set handler is called with two arguments:
2004-09-28 22:55:22 +00:00
property name
value to be set
2002-09-04 09:07:58 +00:00
it should return whether the call was successfull or not
*/
2004-09-28 22:55:22 +00:00
zend_call_method_with_2_params ( & object , ce , & ce - > __set , ZEND_SET_FUNC_NAME , & retval , member , value ) ;
2002-09-04 09:07:58 +00:00
2005-02-02 07:19:22 +00:00
zval_ptr_dtor ( & member ) ;
2002-09-04 09:07:58 +00:00
zval_ptr_dtor ( & value ) ;
2002-09-15 07:45:26 +00:00
if ( retval ) {
2005-03-19 15:32:18 +00:00
result = i_zend_is_true ( retval ) ? SUCCESS : FAILURE ;
2002-09-04 09:07:58 +00:00
zval_ptr_dtor ( & retval ) ;
2005-03-19 15:32:18 +00:00
return result ;
} else {
return FAILURE ;
2002-09-04 09:07:58 +00:00
}
}
2007-11-02 19:40:39 +00:00
/* }}} */
2002-09-04 09:07:58 +00:00
2007-11-02 19:40:39 +00:00
static void zend_std_call_unsetter ( zval * object , zval * member TSRMLS_DC ) /* { { { */
2005-07-07 16:07:09 +00:00
{
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
2006-05-09 23:53:23 +00:00
2005-07-07 16:07:09 +00:00
/* __unset handler is called with one argument:
property name
*/
2006-05-09 23:53:23 +00:00
2005-07-07 16:07:09 +00: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 ) ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2005-07-07 16:07:09 +00:00
2007-11-02 19:40:39 +00:00
static zval * zend_std_call_issetter ( zval * object , zval * member TSRMLS_DC ) /* { { { */
2005-07-07 16:07:09 +00:00
{
zval * retval = NULL ;
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
2006-05-09 23:53:23 +00:00
2005-07-07 16:07:09 +00:00
/* __isset handler is called with one argument:
property name
it should return whether the property is set or not
*/
2006-05-09 23:53:23 +00:00
2005-07-07 16:07:09 +00: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 ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2003-02-04 12:12:34 +00:00
2010-05-24 14:11:39 +00:00
static zend_always_inline int zend_verify_property_access ( zend_property_info * property_info , zend_class_entry * ce TSRMLS_DC ) /* { { { */
2003-02-04 12:12:34 +00:00
{
switch ( property_info - > flags & ZEND_ACC_PPP_MASK ) {
case ZEND_ACC_PUBLIC :
return 1 ;
2003-02-05 13:35:52 +00:00
case ZEND_ACC_PROTECTED :
2006-05-27 18:39:53 +00:00
return zend_check_protected ( property_info - > ce , EG ( scope ) ) ;
2003-02-10 10:03:19 +00:00
case ZEND_ACC_PRIVATE :
2007-07-24 11:39:56 +00:00
if ( ( ce = = EG ( scope ) | | property_info - > ce = = EG ( scope ) ) & & EG ( scope ) ) {
2003-02-10 10:03:19 +00:00
return 1 ;
} else {
return 0 ;
}
break ;
2003-02-04 12:12:34 +00:00
}
return 0 ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2003-02-04 12:12:34 +00:00
2010-05-24 14:11:39 +00:00
static zend_always_inline zend_bool is_derived_class ( zend_class_entry * child_class , zend_class_entry * parent_class ) /* { { { */
2003-07-21 12:13:16 +00:00
{
child_class = child_class - > parent ;
while ( child_class ) {
if ( child_class = = parent_class ) {
return 1 ;
}
child_class = child_class - > parent ;
}
return 0 ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2003-07-21 12:13:16 +00:00
2010-05-24 14:11:39 +00:00
static zend_always_inline struct _zend_property_info * zend_get_property_info_quick ( zend_class_entry * ce , zval * member , int silent , const zend_literal * key TSRMLS_DC ) /* { { { */
2003-02-07 10:05:36 +00:00
{
2010-05-06 12:52:27 +00:00
zend_property_info * property_info ;
2003-03-18 16:30:23 +00:00
zend_property_info * scope_property_info ;
zend_bool denied_access = 0 ;
2010-05-06 12:52:27 +00:00
ulong h ;
2003-03-18 16:30:23 +00:00
2010-05-24 14:11:39 +00:00
if ( key & & ( property_info = CACHED_POLYMORPHIC_PTR ( key - > cache_slot , ce ) ) ! = NULL ) {
return property_info ;
}
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( Z_STRVAL_P ( member ) [ 0 ] = = ' \0 ' ) ) {
2005-04-28 17:40:11 +00:00
if ( ! silent ) {
if ( Z_STRLEN_P ( member ) = = 0 ) {
2010-05-06 12:52:27 +00:00
zend_error_noreturn ( E_ERROR , " Cannot access empty property " ) ;
2005-04-28 17:40:11 +00:00
} else {
2010-05-06 12:52:27 +00:00
zend_error_noreturn ( E_ERROR , " Cannot access property started with ' \\ 0' " ) ;
2005-04-28 17:40:11 +00:00
}
}
2006-05-27 18:39:53 +00:00
return NULL ;
2005-04-28 17:40:11 +00:00
}
2010-05-06 12:52:27 +00:00
property_info = NULL ;
h = key ? key - > hash_value : zend_get_hash_value ( Z_STRVAL_P ( member ) , Z_STRLEN_P ( member ) + 1 ) ;
2005-04-08 11:35:11 +00:00
if ( zend_hash_quick_find ( & ce - > properties_info , Z_STRVAL_P ( member ) , Z_STRLEN_P ( member ) + 1 , h , ( void * * ) & property_info ) = = SUCCESS ) {
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( ( property_info - > flags & ZEND_ACC_SHADOW ) ! = 0 ) ) {
2005-06-09 17:20:44 +00:00
/* if it's a shadow - go to access it's private */
property_info = NULL ;
} else {
2010-05-06 12:52:27 +00:00
if ( EXPECTED ( zend_verify_property_access ( property_info , ce TSRMLS_CC ) ! = 0 ) ) {
if ( EXPECTED ( ( property_info - > flags & ZEND_ACC_CHANGED ) ! = 0 )
& & EXPECTED ( ! ( property_info - > flags & ZEND_ACC_PRIVATE ) ) ) {
2005-06-09 17:20:44 +00:00
/* 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 {
2010-05-24 14:11:39 +00:00
if ( UNEXPECTED ( ( property_info - > flags & ZEND_ACC_STATIC ) ! = 0 ) & & ! silent ) {
2005-06-09 17:20:44 +00:00
zend_error ( E_STRICT , " Accessing static property %s::$%s as non static " , ce - > name , Z_STRVAL_P ( member ) ) ;
}
2010-05-24 14:11:39 +00:00
if ( key ) {
CACHE_POLYMORPHIC_PTR ( key - > cache_slot , ce , property_info ) ;
}
2005-06-09 17:20:44 +00:00
return property_info ;
2005-06-08 08:08:18 +00:00
}
2005-06-09 17:20:44 +00:00
} else {
/* Try to look in the scope instead */
denied_access = 1 ;
2003-03-18 16:30:23 +00:00
}
2003-02-07 10:05:36 +00:00
}
2003-02-13 22:47:25 +00:00
}
2005-04-08 11:35:11 +00:00
if ( EG ( scope ) ! = ce
2003-03-18 16:30:23 +00:00
& & EG ( scope )
2010-05-24 14:11:39 +00:00
& & is_derived_class ( ce , EG ( scope ) )
2003-03-18 16:30:23 +00:00
& & 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 ) {
2010-05-24 14:11:39 +00:00
if ( key ) {
CACHE_POLYMORPHIC_PTR ( key - > cache_slot , ce , scope_property_info ) ;
}
2003-03-18 16:30:23 +00:00
return scope_property_info ;
} else if ( property_info ) {
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( denied_access ! = 0 ) ) {
2003-03-18 16:30:23 +00:00
/* Information was available, but we were denied access. Error out. */
2010-05-06 12:52:27 +00:00
if ( ! silent ) {
zend_error_noreturn ( E_ERROR , " Cannot access %s property %s::$%s " , zend_visibility_string ( property_info - > flags ) , ce - > name , Z_STRVAL_P ( member ) ) ;
2003-12-18 20:07:30 +00:00
}
2010-05-06 12:52:27 +00:00
return NULL ;
2003-03-18 16:30:23 +00:00
} else {
/* fall through, return property_info... */
2010-05-24 14:11:39 +00:00
if ( key ) {
CACHE_POLYMORPHIC_PTR ( key - > cache_slot , ce , property_info ) ;
}
2003-03-18 16:30:23 +00:00
}
2003-02-07 10:05:36 +00: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 13:35:23 +00:00
EG ( std_property_info ) . h = h ;
2006-05-27 18:39:53 +00:00
EG ( std_property_info ) . ce = ce ;
2010-05-24 14:11:39 +00:00
EG ( std_property_info ) . offset = - 1 ;
2003-02-07 10:05:36 +00:00
property_info = & EG ( std_property_info ) ;
}
return property_info ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2003-02-07 10:05:36 +00:00
2010-04-20 10:57:45 +00:00
ZEND_API struct _zend_property_info * zend_get_property_info ( zend_class_entry * ce , zval * member , int silent TSRMLS_DC ) /* { { { */
{
2010-05-06 12:52:27 +00:00
return zend_get_property_info_quick ( ce , member , silent , NULL TSRMLS_CC ) ;
2010-04-20 10:57:45 +00:00
}
/* }}} */
2011-09-13 13:29:35 +00:00
ZEND_API int zend_check_property_access ( zend_object * zobj , const char * prop_info_name , int prop_info_name_len TSRMLS_DC ) /* { { { */
2003-12-18 20:07:30 +00:00
{
zend_property_info * property_info ;
2011-09-13 13:29:35 +00:00
const char * class_name , * prop_name ;
2003-12-18 20:07:30 +00:00
zval member ;
2013-01-14 09:08:21 +00:00
int prop_name_len ;
2003-12-18 20:07:30 +00:00
2013-01-14 09:08:21 +00:00
zend_unmangle_property_name_ex ( prop_info_name , prop_info_name_len , & class_name , & prop_name , & prop_name_len ) ;
ZVAL_STRINGL ( & member , prop_name , prop_name_len , 0 ) ;
2010-05-06 12:52:27 +00:00
property_info = zend_get_property_info_quick ( zobj - > ce , & member , 1 , NULL TSRMLS_CC ) ;
2003-12-18 20:07:30 +00:00
if ( ! property_info ) {
return FAILURE ;
}
2007-11-02 19:40:39 +00:00
if ( class_name & & class_name [ 0 ] ! = ' * ' ) {
2005-06-06 07:52:08 +00:00
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-18 20:07:30 +00:00
}
return zend_verify_property_access ( property_info , zobj - > ce TSRMLS_CC ) ? SUCCESS : FAILURE ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2003-12-18 20:07:30 +00:00
2007-11-02 19:40:39 +00:00
static int zend_get_property_guard ( zend_object * zobj , zend_property_info * property_info , zval * member , zend_guard * * pguard ) /* { { { */
2005-11-15 13:35:23 +00:00
{
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 ) ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2005-11-15 13:35:23 +00:00
2010-04-20 10:57:45 +00:00
zval * zend_std_read_property ( zval * object , zval * member , int type , const zend_literal * key TSRMLS_DC ) /* { { { */
2002-02-07 14:08:43 +00:00
{
zend_object * zobj ;
2005-06-03 11:16:19 +00:00
zval * tmp_member = NULL ;
2002-02-07 14:08:43 +00:00
zval * * retval ;
2002-09-04 09:07:58 +00:00
zval * rv = NULL ;
2003-02-04 12:12:34 +00:00
zend_property_info * property_info ;
2004-03-21 18:07:27 +00:00
int silent ;
silent = ( type = = BP_VAR_IS ) ;
2002-04-22 14:22:27 +00:00
zobj = Z_OBJ_P ( object ) ;
2002-02-07 14:08:43 +00:00
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( Z_TYPE_P ( member ) ! = IS_STRING ) ) {
ALLOC_ZVAL ( tmp_member ) ;
2005-06-03 11:16:19 +00:00
* tmp_member = * member ;
INIT_PZVAL ( tmp_member ) ;
zval_copy_ctor ( tmp_member ) ;
convert_to_string ( tmp_member ) ;
member = tmp_member ;
2010-04-20 10:57:45 +00:00
key = NULL ;
2002-02-07 14:08:43 +00: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 01:03:19 +00:00
# endif
2003-02-04 12:12:34 +00:00
2004-07-19 14:26:53 +00:00
/* make zend_get_property_info silent if we have getter - we may want to use it */
2013-01-14 01:08:52 +00:00
property_info = zend_get_property_info_quick ( zobj - > ce , member , silent | | ( zobj - > ce - > __get ! = NULL ) , key TSRMLS_CC ) ;
2003-02-04 12:12:34 +00:00
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( ! property_info ) | |
2010-05-24 14:11:39 +00:00
( ( EXPECTED ( ( property_info - > flags & ZEND_ACC_STATIC ) = = 0 ) & &
property_info - > offset > = 0 ) ?
( zobj - > properties ?
( ( retval = ( zval * * ) zobj - > properties_table [ property_info - > offset ] ) = = NULL ) :
( * ( retval = & zobj - > properties_table [ property_info - > offset ] ) = = NULL ) ) :
( UNEXPECTED ( ! zobj - > properties ) | |
UNEXPECTED ( zend_hash_quick_find ( zobj - > properties , property_info - > name , property_info - > name_length + 1 , property_info - > h , ( void * * ) & retval ) = = FAILURE ) ) ) ) {
2010-08-01 13:27:02 +00:00
zend_guard * guard = NULL ;
2005-11-15 13:35:23 +00:00
if ( zobj - > ce - > __get & &
zend_get_property_guard ( zobj , property_info , member , & guard ) = = SUCCESS & &
! guard - > in_get ) {
2002-09-04 09:07:58 +00:00
/* have getter - try with it! */
2008-10-17 10:26:07 +00:00
Z_ADDREF_P ( object ) ;
2010-10-01 09:49:20 +00:00
if ( PZVAL_IS_REF ( object ) ) {
SEPARATE_ZVAL ( & object ) ;
}
2005-11-15 13:35:23 +00:00
guard - > in_get = 1 ; /* prevent circular getting */
2002-09-04 09:07:58 +00:00
rv = zend_std_call_getter ( object , member TSRMLS_CC ) ;
2005-11-15 13:35:23 +00:00
guard - > in_get = 0 ;
2002-09-04 09:07:58 +00:00
2002-09-15 07:45:26 +00:00
if ( rv ) {
2002-09-04 09:07:58 +00:00
retval = & rv ;
2007-10-07 05:22:07 +00:00
if ( ! Z_ISREF_P ( rv ) & &
2007-01-10 15:58:08 +00:00
( type = = BP_VAR_W | | type = = BP_VAR_RW | | type = = BP_VAR_UNSET ) ) {
2007-10-07 05:22:07 +00:00
if ( Z_REFCOUNT_P ( rv ) > 0 ) {
2006-12-08 15:55:31 +00:00
zval * tmp = rv ;
ALLOC_ZVAL ( rv ) ;
* rv = * tmp ;
zval_copy_ctor ( rv ) ;
2007-10-07 05:22:07 +00:00
Z_UNSET_ISREF_P ( rv ) ;
Z_SET_REFCOUNT_P ( rv , 0 ) ;
2006-12-08 15:55:31 +00:00
}
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( Z_TYPE_P ( rv ) ! = IS_OBJECT ) ) {
2006-07-21 10:32:17 +00:00
zend_error ( E_NOTICE , " Indirect modification of overloaded property %s::$%s has no effect " , zobj - > ce - > name , Z_STRVAL_P ( member ) ) ;
}
}
2002-09-04 09:07:58 +00:00
} else {
2006-05-09 23:53:23 +00:00
retval = & EG ( uninitialized_zval_ptr ) ;
2002-09-04 09:07:58 +00:00
}
2011-04-07 13:35:27 +00:00
if ( EXPECTED ( * retval ! = object ) ) {
zval_ptr_dtor ( & object ) ;
} else {
Z_DELREF_P ( object ) ;
}
2002-09-04 09:07:58 +00:00
} else {
2010-08-01 13:27:02 +00:00
if ( zobj - > ce - > __get & & guard & & guard - > in_get = = 1 ) {
if ( Z_STRVAL_P ( member ) [ 0 ] = = ' \0 ' ) {
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' " ) ;
}
}
}
2003-07-22 13:49:33 +00:00
if ( ! silent ) {
2007-11-17 21:52:02 +00:00
zend_error ( E_NOTICE , " Undefined property: %s::$%s " , zobj - > ce - > name , Z_STRVAL_P ( member ) ) ;
2003-07-22 13:49:33 +00:00
}
2003-02-07 10:05:36 +00:00
retval = & EG ( uninitialized_zval_ptr ) ;
2002-02-07 14:08:43 +00:00
}
}
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( tmp_member ! = NULL ) ) {
2007-10-07 05:22:07 +00:00
Z_ADDREF_PP ( retval ) ;
2005-06-03 11:16:19 +00:00
zval_ptr_dtor ( & tmp_member ) ;
2007-10-07 05:22:07 +00:00
Z_DELREF_PP ( retval ) ;
2002-02-07 14:08:43 +00:00
}
return * retval ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2002-02-07 14:08:43 +00:00
2010-05-24 14:11:39 +00:00
ZEND_API void zend_std_write_property ( zval * object , zval * member , zval * value , const zend_literal * key TSRMLS_DC ) /* { { { */
2002-02-07 14:08:43 +00:00
{
zend_object * zobj ;
2005-06-03 11:16:19 +00:00
zval * tmp_member = NULL ;
2002-03-10 13:42:37 +00:00
zval * * variable_ptr ;
2003-02-04 12:12:34 +00:00
zend_property_info * property_info ;
2004-07-19 14:26:53 +00:00
2002-04-22 14:22:27 +00:00
zobj = Z_OBJ_P ( object ) ;
2002-02-07 14:08:43 +00:00
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( Z_TYPE_P ( member ) ! = IS_STRING ) ) {
2005-06-03 11:16:19 +00: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 ;
2010-04-20 10:57:45 +00:00
key = NULL ;
2002-02-07 14:08:43 +00:00
}
2010-05-06 12:52:27 +00:00
property_info = zend_get_property_info_quick ( zobj - > ce , member , ( zobj - > ce - > __set ! = NULL ) , key TSRMLS_CC ) ;
2003-02-04 12:12:34 +00:00
2010-05-06 12:52:27 +00:00
if ( EXPECTED ( property_info ! = NULL ) & &
2010-05-24 14:11:39 +00:00
( ( EXPECTED ( ( property_info - > flags & ZEND_ACC_STATIC ) = = 0 ) & &
property_info - > offset > = 0 ) ?
( zobj - > properties ?
( ( variable_ptr = ( zval * * ) zobj - > properties_table [ property_info - > offset ] ) ! = NULL ) :
( * ( variable_ptr = & zobj - > properties_table [ property_info - > offset ] ) ! = NULL ) ) :
( EXPECTED ( zobj - > properties ! = NULL ) & &
EXPECTED ( zend_hash_quick_find ( zobj - > properties , property_info - > name , property_info - > name_length + 1 , property_info - > h , ( void * * ) & variable_ptr ) = = SUCCESS ) ) ) ) {
2006-07-26 15:29:27 +00:00
/* if we already have this value there, we don't actually need to do anything */
2010-05-06 12:52:27 +00:00
if ( EXPECTED ( * variable_ptr ! = value ) ) {
2002-10-09 17:14:25 +00: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 11:52:27 +00:00
zval garbage = * * variable_ptr ; /* old value should be destroyed */
2002-10-10 10:07:22 +00:00
/* To check: can't *variable_ptr be some system variable like error_zval here? */
2007-11-02 19:40:39 +00:00
Z_TYPE_PP ( variable_ptr ) = Z_TYPE_P ( value ) ;
2002-10-09 17:14:25 +00:00
( * variable_ptr ) - > value = value - > value ;
2007-11-02 19:40:39 +00:00
if ( Z_REFCOUNT_P ( value ) > 0 ) {
2003-01-29 08:55:12 +00:00
zval_copy_ctor ( * variable_ptr ) ;
2012-12-10 12:29:51 +00:00
} else {
efree ( value ) ;
2003-01-29 08:55:12 +00:00
}
2005-11-16 11:52:27 +00:00
zval_dtor ( & garbage ) ;
2006-07-26 15:29:27 +00:00
} else {
zval * garbage = * variable_ptr ;
/* if we assign referenced variable, we should separate it */
2007-10-07 05:22:07 +00:00
Z_ADDREF_P ( value ) ;
2006-07-26 15:29:27 +00:00
if ( PZVAL_IS_REF ( value ) ) {
SEPARATE_ZVAL ( & value ) ;
}
* variable_ptr = value ;
zval_ptr_dtor ( & garbage ) ;
2002-02-07 14:08:43 +00:00
}
}
2006-08-15 20:30:42 +00:00
} else {
2010-08-01 13:27:02 +00:00
zend_guard * guard = NULL ;
2005-11-15 13:35:23 +00:00
if ( zobj - > ce - > __set & &
zend_get_property_guard ( zobj , property_info , member , & guard ) = = SUCCESS & &
! guard - > in_set ) {
2008-10-17 10:26:07 +00:00
Z_ADDREF_P ( object ) ;
2010-10-01 09:49:20 +00:00
if ( PZVAL_IS_REF ( object ) ) {
SEPARATE_ZVAL ( & object ) ;
}
2005-11-15 13:35:23 +00:00
guard - > in_set = 1 ; /* prevent circular setting */
2002-09-15 07:45:26 +00:00
if ( zend_std_call_setter ( object , member , value TSRMLS_CC ) ! = SUCCESS ) {
2002-09-09 08:59:18 +00:00
/* for now, just ignore it - __set should take care of warnings, etc. */
2002-09-04 09:07:58 +00:00
}
2005-11-15 13:35:23 +00:00
guard - > in_set = 0 ;
2008-10-17 10:26:07 +00:00
zval_ptr_dtor ( & object ) ;
2010-10-01 09:49:20 +00:00
} else if ( EXPECTED ( property_info ! = NULL ) ) {
2006-07-26 15:29:27 +00:00
/* if we assign referenced variable, we should separate it */
2007-10-07 05:22:07 +00:00
Z_ADDREF_P ( value ) ;
2006-07-26 15:29:27 +00:00
if ( PZVAL_IS_REF ( value ) ) {
SEPARATE_ZVAL ( & value ) ;
}
2010-05-24 14:11:39 +00:00
if ( EXPECTED ( ( property_info - > flags & ZEND_ACC_STATIC ) = = 0 ) & &
property_info - > offset > = 0 ) {
2010-10-01 09:49:20 +00:00
if ( ! zobj - > properties ) {
zobj - > properties_table [ property_info - > offset ] = value ;
} else if ( zobj - > properties_table [ property_info - > offset ] ) {
* ( zval * * ) zobj - > properties_table [ property_info - > offset ] = value ;
} else {
zend_hash_quick_update ( zobj - > properties , property_info - > name , property_info - > name_length + 1 , property_info - > h , & value , sizeof ( zval * ) , ( void * * ) & zobj - > properties_table [ property_info - > offset ] ) ;
}
2010-05-24 14:11:39 +00:00
} else {
2010-10-01 09:49:20 +00:00
if ( ! zobj - > properties ) {
2010-05-24 14:11:39 +00:00
rebuild_object_properties ( zobj ) ;
}
zend_hash_quick_update ( zobj - > properties , property_info - > name , property_info - > name_length + 1 , property_info - > h , & value , sizeof ( zval * ) , NULL ) ;
}
2010-10-01 09:49:20 +00:00
} else if ( zobj - > ce - > __set & & guard & & guard - > in_set = = 1 ) {
if ( Z_STRVAL_P ( member ) [ 0 ] = = ' \0 ' ) {
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' " ) ;
}
}
2002-10-09 17:14:25 +00:00
}
2002-09-04 09:07:58 +00:00
}
2006-07-26 15:29:27 +00:00
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( tmp_member ! = NULL ) ) {
2005-06-03 11:16:19 +00:00
zval_ptr_dtor ( & tmp_member ) ;
2002-02-07 14:08:43 +00:00
}
}
2007-11-02 19:40:39 +00:00
/* }}} */
2002-02-07 14:08:43 +00:00
2007-11-02 19:40:39 +00:00
zval * zend_std_read_dimension ( zval * object , zval * offset , int type TSRMLS_DC ) /* { { { */
2003-07-07 10:53:27 +00:00
{
2003-11-24 20:57:54 +00:00
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
zval * retval ;
2006-05-09 23:53:23 +00:00
2010-05-06 12:52:27 +00:00
if ( EXPECTED ( instanceof_function_ex ( ce , zend_ce_arrayaccess , 1 TSRMLS_CC ) ! = 0 ) ) {
2004-07-14 09:01:58 +00:00
if ( offset = = NULL ) {
/* [] construct */
2005-02-02 07:19:22 +00:00
ALLOC_INIT_ZVAL ( offset ) ;
} else {
SEPARATE_ARG_IF_REF ( offset ) ;
2004-07-14 09:01:58 +00:00
}
2004-07-14 09:04:13 +00:00
zend_call_method_with_1_params ( & object , ce , NULL , " offsetget " , & retval , offset ) ;
2005-02-02 07:19:22 +00:00
zval_ptr_dtor ( & offset ) ;
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( ! retval ) ) {
if ( UNEXPECTED ( ! EG ( exception ) ) ) {
zend_error_noreturn ( E_ERROR , " Undefined offset for object of type %s used as array " , ce - > name ) ;
2003-12-11 09:56:06 +00:00
}
return 0 ;
}
2004-02-12 13:49:55 +00:00
/* Undo PZVAL_LOCK() */
2007-10-07 05:22:07 +00:00
Z_DELREF_P ( retval ) ;
2004-02-12 13:49:55 +00:00
2003-11-24 20:57:54 +00:00
return retval ;
} else {
2010-05-06 12:52:27 +00:00
zend_error_noreturn ( E_ERROR , " Cannot use object of type %s as array " , ce - > name ) ;
2003-11-24 20:57:54 +00:00
return 0 ;
}
2003-07-07 10:53:27 +00:00
}
2007-11-02 19:40:39 +00:00
/* }}} */
2003-07-07 10:53:27 +00:00
2007-11-02 19:40:39 +00:00
static void zend_std_write_dimension ( zval * object , zval * offset , zval * value TSRMLS_DC ) /* { { { */
2003-07-07 09:00:36 +00:00
{
2003-11-24 20:57:54 +00:00
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
2005-02-02 07:19:22 +00:00
2010-05-06 12:52:27 +00:00
if ( EXPECTED ( instanceof_function_ex ( ce , zend_ce_arrayaccess , 1 TSRMLS_CC ) ! = 0 ) ) {
2003-12-22 16:27:14 +00:00
if ( ! offset ) {
2005-02-02 07:19:22 +00:00
ALLOC_INIT_ZVAL ( offset ) ;
} else {
SEPARATE_ARG_IF_REF ( offset ) ;
2003-12-22 16:27:14 +00:00
}
2003-11-24 20:57:54 +00:00
zend_call_method_with_2_params ( & object , ce , NULL , " offsetset " , NULL , offset , value ) ;
2005-02-02 07:19:22 +00:00
zval_ptr_dtor ( & offset ) ;
2003-11-24 20:57:54 +00:00
} else {
2010-05-06 12:52:27 +00:00
zend_error_noreturn ( E_ERROR , " Cannot use object of type %s as array " , ce - > name ) ;
2003-11-24 20:57:54 +00:00
}
2003-07-07 09:00:36 +00:00
}
2007-11-02 19:40:39 +00:00
/* }}} */
2003-07-07 09:00:36 +00:00
2007-11-02 19:40:39 +00:00
static int zend_std_has_dimension ( zval * object , zval * offset , int check_empty TSRMLS_DC ) /* { { { */
2003-11-10 16:14:44 +00:00
{
2003-11-24 20:57:54 +00:00
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
zval * retval ;
int result ;
2006-05-09 23:53:23 +00:00
2010-05-06 12:52:27 +00:00
if ( EXPECTED ( instanceof_function_ex ( ce , zend_ce_arrayaccess , 1 TSRMLS_CC ) ! = 0 ) ) {
2005-02-02 07:19:22 +00:00
SEPARATE_ARG_IF_REF ( offset ) ;
2003-11-24 20:57:54 +00:00
zend_call_method_with_1_params ( & object , ce , NULL , " offsetexists " , & retval , offset ) ;
2010-05-06 12:52:27 +00:00
if ( EXPECTED ( retval ! = NULL ) ) {
2005-03-19 15:32:18 +00:00
result = i_zend_is_true ( retval ) ;
zval_ptr_dtor ( & retval ) ;
2010-05-06 12:52:27 +00:00
if ( check_empty & & result & & EXPECTED ( ! EG ( exception ) ) ) {
2005-07-07 16:07:09 +00:00
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 15:32:18 +00:00
} else {
2005-07-07 16:07:09 +00:00
result = 0 ;
2005-03-19 15:32:18 +00:00
}
2005-07-07 16:07:09 +00:00
zval_ptr_dtor ( & offset ) ;
2003-11-24 20:57:54 +00:00
} else {
2010-05-06 12:52:27 +00:00
zend_error_noreturn ( E_ERROR , " Cannot use object of type %s as array " , ce - > name ) ;
2003-11-24 20:57:54 +00:00
return 0 ;
}
2005-07-07 16:07:09 +00:00
return result ;
2003-11-10 16:14:44 +00:00
}
2007-11-02 19:40:39 +00:00
/* }}} */
2003-11-10 16:14:44 +00:00
2010-04-20 10:57:45 +00:00
static zval * * zend_std_get_property_ptr_ptr ( zval * object , zval * member , const zend_literal * key TSRMLS_DC ) /* { { { */
2002-02-07 14:08:43 +00:00
{
zend_object * zobj ;
zval tmp_member ;
zval * * retval ;
2003-02-05 09:41:31 +00:00
zend_property_info * property_info ;
2006-05-09 23:53:23 +00:00
2002-04-22 14:22:27 +00:00
zobj = Z_OBJ_P ( object ) ;
2002-02-07 14:08:43 +00:00
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( Z_TYPE_P ( member ) ! = IS_STRING ) ) {
2002-02-07 14:08:43 +00:00
tmp_member = * member ;
zval_copy_ctor ( & tmp_member ) ;
convert_to_string ( & tmp_member ) ;
member = & tmp_member ;
2010-04-20 10:57:45 +00:00
key = NULL ;
2002-02-07 14:08:43 +00:00
}
# if DEBUG_OBJECT_HANDLERS
fprintf ( stderr , " Ptr object #%d property: %s \n " , Z_OBJ_HANDLE_P ( object ) , Z_STRVAL_P ( member ) ) ;
2006-05-09 23:53:23 +00:00
# endif
2002-02-07 14:08:43 +00:00
2010-05-06 12:52:27 +00:00
property_info = zend_get_property_info_quick ( zobj - > ce , member , ( zobj - > ce - > __get ! = NULL ) , key TSRMLS_CC ) ;
2003-02-05 09:41:31 +00:00
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( ! property_info ) | |
2010-05-24 14:11:39 +00:00
( ( EXPECTED ( ( property_info - > flags & ZEND_ACC_STATIC ) = = 0 ) & &
property_info - > offset > = 0 ) ?
( zobj - > properties ?
( ( retval = ( zval * * ) zobj - > properties_table [ property_info - > offset ] ) = = NULL ) :
( * ( retval = & zobj - > properties_table [ property_info - > offset ] ) = = NULL ) ) :
( UNEXPECTED ( ! zobj - > properties ) | |
UNEXPECTED ( zend_hash_quick_find ( zobj - > properties , property_info - > name , property_info - > name_length + 1 , property_info - > h , ( void * * ) & retval ) = = FAILURE ) ) ) ) {
2002-09-04 09:07:58 +00:00
zval * new_zval ;
2005-11-15 13:35:23 +00:00
zend_guard * guard ;
2002-09-04 09:07:58 +00:00
2005-11-15 13:35:23 +00:00
if ( ! zobj - > ce - > __get | |
2009-05-12 22:55:05 +00:00
zend_get_property_guard ( zobj , property_info , member , & guard ) ! = SUCCESS | |
( property_info & & guard - > in_get ) ) {
2004-01-05 11:45:46 +00:00
/* we don't have access controls - will just add it */
2002-09-04 09:07:58 +00:00
new_zval = & EG ( uninitialized_zval ) ;
2002-02-07 14:08:43 +00:00
2002-10-20 19:22:04 +00:00
/* zend_error(E_NOTICE, "Undefined property: %s", Z_STRVAL_P(member)); */
2007-10-07 05:22:07 +00:00
Z_ADDREF_P ( new_zval ) ;
2010-05-24 14:11:39 +00:00
if ( EXPECTED ( ( property_info - > flags & ZEND_ACC_STATIC ) = = 0 ) & &
property_info - > offset > = 0 ) {
if ( ! zobj - > properties ) {
zobj - > properties_table [ property_info - > offset ] = new_zval ;
retval = & zobj - > properties_table [ property_info - > offset ] ;
} else if ( zobj - > properties_table [ property_info - > offset ] ) {
* ( zval * * ) zobj - > properties_table [ property_info - > offset ] = new_zval ;
retval = ( zval * * ) zobj - > properties_table [ property_info - > offset ] ;
} else {
zend_hash_quick_update ( zobj - > properties , property_info - > name , property_info - > name_length + 1 , property_info - > h , & new_zval , sizeof ( zval * ) , ( void * * ) & zobj - > properties_table [ property_info - > offset ] ) ;
retval = ( zval * * ) zobj - > properties_table [ property_info - > offset ] ;
}
} else {
if ( ! zobj - > properties ) {
rebuild_object_properties ( zobj ) ;
}
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 09:07:58 +00:00
} else {
/* we do have getter - fail and let it try again with usual get/set */
retval = NULL ;
}
2002-02-07 14:08:43 +00:00
}
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( member = = & tmp_member ) ) {
2002-02-07 14:08:43 +00:00
zval_dtor ( member ) ;
}
return retval ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2002-02-07 14:08:43 +00:00
2010-04-20 10:57:45 +00:00
static void zend_std_unset_property ( zval * object , zval * member , const zend_literal * key TSRMLS_DC ) /* { { { */
2002-02-07 14:08:43 +00:00
{
zend_object * zobj ;
2005-07-07 16:07:09 +00:00
zval * tmp_member = NULL ;
2003-02-05 14:27:30 +00:00
zend_property_info * property_info ;
2006-05-09 23:53:23 +00:00
2002-04-22 14:22:27 +00:00
zobj = Z_OBJ_P ( object ) ;
2002-02-07 14:08:43 +00:00
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( Z_TYPE_P ( member ) ! = IS_STRING ) ) {
2005-07-07 16:07:09 +00: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 ;
2010-04-20 10:57:45 +00:00
key = NULL ;
2002-02-07 14:08:43 +00:00
}
2003-02-05 14:27:30 +00:00
2010-05-06 12:52:27 +00:00
property_info = zend_get_property_info_quick ( zobj - > ce , member , ( zobj - > ce - > __unset ! = NULL ) , key TSRMLS_CC ) ;
2006-05-09 23:53:23 +00:00
2010-05-24 14:11:39 +00:00
if ( EXPECTED ( property_info ! = NULL ) & &
2012-05-13 05:12:48 +00:00
EXPECTED ( ( property_info - > flags & ZEND_ACC_STATIC ) = = 0 ) & &
2010-05-24 14:11:39 +00:00
! zobj - > properties & &
property_info - > offset > = 0 & &
EXPECTED ( zobj - > properties_table [ property_info - > offset ] ! = NULL ) ) {
zval_ptr_dtor ( & zobj - > properties_table [ property_info - > offset ] ) ;
zobj - > properties_table [ property_info - > offset ] = NULL ;
} else if ( UNEXPECTED ( ! property_info ) | |
! zobj - > properties | |
UNEXPECTED ( zend_hash_quick_del ( zobj - > properties , property_info - > name , property_info - > name_length + 1 , property_info - > h ) = = FAILURE ) ) {
2010-08-01 13:27:02 +00:00
zend_guard * guard = NULL ;
2005-11-15 13:35:23 +00:00
if ( zobj - > ce - > __unset & &
zend_get_property_guard ( zobj , property_info , member , & guard ) = = SUCCESS & &
! guard - > in_unset ) {
2005-07-07 16:07:09 +00:00
/* have unseter - try with it! */
2008-10-17 10:26:07 +00:00
Z_ADDREF_P ( object ) ;
2010-10-01 09:49:20 +00:00
if ( PZVAL_IS_REF ( object ) ) {
SEPARATE_ZVAL ( & object ) ;
}
2006-05-27 18:39:53 +00:00
guard - > in_unset = 1 ; /* prevent circular unsetting */
2005-07-07 16:07:09 +00:00
zend_std_call_unsetter ( object , member TSRMLS_CC ) ;
2005-11-15 13:35:23 +00:00
guard - > in_unset = 0 ;
2008-10-17 10:26:07 +00:00
zval_ptr_dtor ( & object ) ;
2010-08-01 13:27:02 +00:00
} else if ( zobj - > ce - > __unset & & guard & & guard - > in_unset = = 1 ) {
if ( Z_STRVAL_P ( member ) [ 0 ] = = ' \0 ' ) {
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' " ) ;
}
}
2005-07-07 16:07:09 +00:00
}
2012-05-13 05:12:48 +00:00
} else if ( EXPECTED ( property_info ! = NULL ) & &
EXPECTED ( ( property_info - > flags & ZEND_ACC_STATIC ) = = 0 ) & &
2010-05-24 14:11:39 +00:00
property_info - > offset > = 0 ) {
zobj - > properties_table [ property_info - > offset ] = NULL ;
2005-07-07 16:07:09 +00:00
}
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( tmp_member ! = NULL ) ) {
2005-07-07 16:07:09 +00:00
zval_ptr_dtor ( & tmp_member ) ;
2002-02-07 14:08:43 +00:00
}
}
2007-11-02 19:40:39 +00:00
/* }}} */
2002-02-07 14:08:43 +00:00
2007-11-02 19:40:39 +00:00
static void zend_std_unset_dimension ( zval * object , zval * offset TSRMLS_DC ) /* { { { */
2003-07-30 17:12:06 +00:00
{
2003-11-24 20:57:54 +00:00
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
2006-05-09 23:53:23 +00:00
2003-11-24 20:57:54 +00:00
if ( instanceof_function_ex ( ce , zend_ce_arrayaccess , 1 TSRMLS_CC ) ) {
2005-02-02 07:19:22 +00:00
SEPARATE_ARG_IF_REF ( offset ) ;
2005-03-19 15:06:39 +00:00
zend_call_method_with_1_params ( & object , ce , NULL , " offsetunset " , NULL , offset ) ;
2005-02-02 07:19:22 +00:00
zval_ptr_dtor ( & offset ) ;
2003-11-24 20:57:54 +00:00
} else {
2010-05-06 12:52:27 +00:00
zend_error_noreturn ( E_ERROR , " Cannot use object of type %s as array " , ce - > name ) ;
2003-11-24 20:57:54 +00:00
}
2003-07-30 17:12:06 +00:00
}
2007-11-02 19:40:39 +00:00
/* }}} */
2003-07-30 17:12:06 +00:00
2007-11-02 19:40:39 +00:00
ZEND_API void zend_std_call_user_call ( INTERNAL_FUNCTION_PARAMETERS ) /* { { { */
2002-09-04 09:07:58 +00:00
{
2007-11-20 09:51:12 +00:00
zend_internal_function * func = ( zend_internal_function * ) EG ( current_execute_data ) - > function_state . function ;
2002-09-04 15:03:41 +00:00
zval * method_name_ptr , * method_args_ptr ;
zval * method_result_ptr = NULL ;
2004-09-28 22:55:22 +00:00
zend_class_entry * ce = Z_OBJCE_P ( this_ptr ) ;
2006-05-09 23:53:23 +00:00
2004-12-17 22:24:51 +00:00
ALLOC_ZVAL ( method_args_ptr ) ;
2004-09-28 22:55:22 +00:00
INIT_PZVAL ( method_args_ptr ) ;
2008-05-27 10:29:33 +00:00
array_init_size ( method_args_ptr , ZEND_NUM_ARGS ( ) ) ;
2002-09-04 09:07:58 +00:00
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( zend_copy_parameters_array ( ZEND_NUM_ARGS ( ) , method_args_ptr TSRMLS_CC ) = = FAILURE ) ) {
2004-09-28 22:55:22 +00:00
zval_dtor ( method_args_ptr ) ;
2010-05-06 12:52:27 +00:00
zend_error_noreturn ( E_ERROR , " Cannot get arguments for __call " ) ;
2002-09-04 09:07:58 +00:00
RETURN_FALSE ;
}
2004-12-17 22:24:51 +00:00
ALLOC_ZVAL ( method_name_ptr ) ;
2002-09-04 09:07:58 +00:00
INIT_PZVAL ( method_name_ptr ) ;
ZVAL_STRING ( method_name_ptr , func - > function_name , 0 ) ; /* no dup - it's a copy */
2002-09-04 15:03:41 +00:00
/* __call handler is called with two arguments:
2002-09-04 09:07:58 +00:00
method name
array of method parameters
*/
2004-09-28 22:55:22 +00: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 07:45:26 +00:00
if ( method_result_ptr ) {
2007-10-07 05:22:07 +00:00
if ( Z_ISREF_P ( method_result_ptr ) | | Z_REFCOUNT_P ( method_result_ptr ) > 1 ) {
2005-05-03 12:47:27 +00:00
RETVAL_ZVAL ( method_result_ptr , 1 , 1 ) ;
} else {
RETVAL_ZVAL ( method_result_ptr , 0 , 1 ) ;
}
2002-09-04 15:03:41 +00:00
}
2006-05-09 23:53:23 +00:00
2002-09-04 09:07:58 +00:00
/* now destruct all auxiliaries */
2004-12-17 22:24:51 +00:00
zval_ptr_dtor ( & method_args_ptr ) ;
zval_ptr_dtor ( & method_name_ptr ) ;
2002-09-04 09:07:58 +00:00
/* destruct the function also, then - we have allocated it in get_method */
efree ( func ) ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2002-09-04 09:07:58 +00:00
2003-02-02 16:17:25 +00: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 .
*/
2010-04-20 10:57:45 +00:00
static inline zend_function * zend_check_private_int ( zend_function * fbc , zend_class_entry * ce , char * function_name_strval , int function_name_strlen , ulong hash_value TSRMLS_DC ) /* { { { */
2003-02-02 16:17:25 +00: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 ) ) {
2010-04-20 10:57:45 +00:00
if ( zend_hash_quick_find ( & ce - > function_table , function_name_strval , function_name_strlen + 1 , hash_value , ( void * * ) & fbc ) = = SUCCESS
2003-02-02 16:17:25 +00:00
& & fbc - > op_array . fn_flags & ZEND_ACC_PRIVATE
& & fbc - > common . scope = = EG ( scope ) ) {
return fbc ;
}
break ;
}
ce = ce - > parent ;
}
return NULL ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2003-02-02 16:17:25 +00:00
2007-11-02 19:40:39 +00:00
ZEND_API int zend_check_private ( zend_function * fbc , zend_class_entry * ce , char * function_name_strval , int function_name_strlen TSRMLS_DC ) /* { { { */
2005-04-27 15:45:36 +00:00
{
2010-04-20 10:57:45 +00:00
return zend_check_private_int ( fbc , ce , function_name_strval , function_name_strlen , zend_hash_func ( function_name_strval , function_name_strlen + 1 ) TSRMLS_CC ) ! = NULL ;
2005-04-27 15:45:36 +00:00
}
2007-11-02 19:40:39 +00:00
/* }}} */
2005-04-27 15:45:36 +00:00
2003-02-02 16:17:25 +00:00
/* Ensures that we're allowed to call a protected method.
*/
2007-11-02 19:40:39 +00:00
ZEND_API int zend_check_protected ( zend_class_entry * ce , zend_class_entry * scope ) /* { { { */
2003-02-02 16:17:25 +00: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 ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2003-02-02 16:17:25 +00:00
2009-06-12 21:36:53 +00:00
static inline union _zend_function * zend_get_user_call_function ( zend_class_entry * ce , const char * method_name , int method_len ) /* { { { */
2009-01-07 22:12:39 +00:00
{
zend_internal_function * call_user_call = emalloc ( sizeof ( zend_internal_function ) ) ;
call_user_call - > type = ZEND_INTERNAL_FUNCTION ;
2010-09-15 07:38:52 +00:00
call_user_call - > module = ( ce - > type = = ZEND_INTERNAL_CLASS ) ? ce - > info . internal . module : NULL ;
2009-01-07 22:12:39 +00:00
call_user_call - > handler = zend_std_call_user_call ;
call_user_call - > arg_info = NULL ;
call_user_call - > num_args = 0 ;
2009-06-12 01:05:25 +00:00
call_user_call - > scope = ce ;
2009-01-07 22:12:39 +00:00
call_user_call - > fn_flags = ZEND_ACC_CALL_VIA_HANDLER ;
call_user_call - > function_name = estrndup ( method_name , method_len ) ;
return ( union _zend_function * ) call_user_call ;
}
/* }}} */
2010-04-20 10:57:45 +00:00
static union _zend_function * zend_std_get_method ( zval * * object_ptr , char * method_name , int method_len , const zend_literal * key TSRMLS_DC ) /* { { { */
2002-02-07 14:08:43 +00:00
{
2003-02-02 16:17:25 +00:00
zend_function * fbc ;
2004-10-30 19:11:37 +00:00
zval * object = * object_ptr ;
2010-04-20 10:57:45 +00:00
zend_object * zobj = Z_OBJ_P ( object ) ;
ulong hash_value ;
char * lc_method_name ;
2007-11-22 13:27:13 +00:00
ALLOCA_FLAG ( use_heap )
2007-10-11 01:03:19 +00:00
2010-05-06 12:52:27 +00:00
if ( EXPECTED ( key ! = NULL ) ) {
2010-04-20 10:57:45 +00:00
lc_method_name = Z_STRVAL ( key - > constant ) ;
hash_value = key - > hash_value ;
} else {
lc_method_name = do_alloca ( method_len + 1 , use_heap ) ;
/* Create a zend_copy_str_tolower(dest, src, src_length); */
zend_str_tolower_copy ( lc_method_name , method_name , method_len ) ;
hash_value = zend_hash_func ( lc_method_name , method_len + 1 ) ;
}
2007-10-11 01:03:19 +00:00
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( zend_hash_quick_find ( & zobj - > ce - > function_table , lc_method_name , method_len + 1 , hash_value , ( void * * ) & fbc ) = = FAILURE ) ) {
if ( UNEXPECTED ( ! key ) ) {
2010-04-20 10:57:45 +00:00
free_alloca ( lc_method_name , use_heap ) ;
}
2003-01-29 15:02:57 +00:00
if ( zobj - > ce - > __call ) {
2009-06-12 01:05:25 +00:00
return zend_get_user_call_function ( zobj - > ce , method_name , method_len ) ;
2003-01-29 15:02:57 +00:00
} else {
return NULL ;
2002-09-04 09:07:58 +00:00
}
2002-02-07 14:08:43 +00:00
}
2002-06-05 17:34:56 +00:00
2003-02-02 16:17:25 +00:00
/* Check access level */
2006-09-12 11:01:16 +00: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.
2009-01-07 22:12:39 +00:00
* If we ' re not and __call ( ) handler exists , invoke it , otherwise error out .
2006-09-12 11:01:16 +00:00
*/
2010-04-20 10:57:45 +00:00
updated_fbc = zend_check_private_int ( fbc , Z_OBJ_HANDLER_P ( object , get_class_entry ) ( object TSRMLS_CC ) , lc_method_name , method_len , hash_value TSRMLS_CC ) ;
2010-05-06 12:52:27 +00:00
if ( EXPECTED ( updated_fbc ! = NULL ) ) {
2009-01-07 22:12:39 +00:00
fbc = updated_fbc ;
} else {
if ( zobj - > ce - > __call ) {
2009-06-12 01:05:25 +00:00
fbc = zend_get_user_call_function ( zobj - > ce , method_name , method_len ) ;
2009-01-07 22:12:39 +00:00
} else {
2010-05-06 12:52:27 +00:00
zend_error_noreturn ( 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 : " " ) ;
2009-01-07 22:12:39 +00:00
}
2006-09-12 11:01:16 +00:00
}
} else {
2003-02-02 16:17:25 +00:00
/* Ensure that we haven't overridden a private function and end up calling
* the overriding public function . . .
*/
2007-07-12 10:32:09 +00:00
if ( EG ( scope ) & &
is_derived_class ( fbc - > common . scope , EG ( scope ) ) & &
fbc - > op_array . fn_flags & ZEND_ACC_CHANGED ) {
2003-02-02 16:17:25 +00:00
zend_function * priv_fbc ;
2010-04-20 10:57:45 +00:00
if ( zend_hash_quick_find ( & EG ( scope ) - > function_table , lc_method_name , method_len + 1 , hash_value , ( void * * ) & priv_fbc ) = = SUCCESS
2005-06-17 10:50:45 +00:00
& & priv_fbc - > common . fn_flags & ZEND_ACC_PRIVATE
& & priv_fbc - > common . scope = = EG ( scope ) ) {
2003-02-02 16:17:25 +00:00
fbc = priv_fbc ;
}
}
2006-09-12 11:01:16 +00:00
if ( ( fbc - > common . fn_flags & ZEND_ACC_PROTECTED ) ) {
/* Ensure that if we're calling a protected function, we're allowed to do so.
2009-01-07 22:12:39 +00:00
* If we ' re not and __call ( ) handler exists , invoke it , otherwise error out .
2006-09-12 11:01:16 +00:00
*/
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( ! zend_check_protected ( zend_get_function_root_class ( fbc ) , EG ( scope ) ) ) ) {
2009-01-07 22:12:39 +00:00
if ( zobj - > ce - > __call ) {
2009-06-12 01:05:25 +00:00
fbc = zend_get_user_call_function ( zobj - > ce , method_name , method_len ) ;
2009-01-07 22:12:39 +00:00
} else {
2010-05-06 12:52:27 +00:00
zend_error_noreturn ( 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 : " " ) ;
2009-01-07 22:12:39 +00:00
}
2006-09-12 11:01:16 +00:00
}
2003-02-02 16:17:25 +00:00
}
}
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( ! key ) ) {
2010-04-20 10:57:45 +00:00
free_alloca ( lc_method_name , use_heap ) ;
}
2003-02-02 16:17:25 +00:00
return fbc ;
2002-02-07 14:08:43 +00:00
}
2007-11-02 19:40:39 +00:00
/* }}} */
2002-02-07 14:08:43 +00:00
2007-09-29 08:52:40 +00:00
ZEND_API void zend_std_callstatic_user_call ( INTERNAL_FUNCTION_PARAMETERS ) /* { { { */
{
2007-11-20 09:51:12 +00:00
zend_internal_function * func = ( zend_internal_function * ) EG ( current_execute_data ) - > function_state . function ;
2007-09-29 08:52:40 +00:00
zval * method_name_ptr , * method_args_ptr ;
zval * method_result_ptr = NULL ;
zend_class_entry * ce = EG ( scope ) ;
2007-10-11 01:03:19 +00:00
2007-09-29 08:52:40 +00:00
ALLOC_ZVAL ( method_args_ptr ) ;
INIT_PZVAL ( method_args_ptr ) ;
2008-05-27 10:29:33 +00:00
array_init_size ( method_args_ptr , ZEND_NUM_ARGS ( ) ) ;
2007-09-29 08:52:40 +00:00
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( zend_copy_parameters_array ( ZEND_NUM_ARGS ( ) , method_args_ptr TSRMLS_CC ) = = FAILURE ) ) {
2007-09-29 08:52:40 +00:00
zval_dtor ( method_args_ptr ) ;
2010-05-06 12:52:27 +00:00
zend_error_noreturn ( E_ERROR , " Cannot get arguments for " ZEND_CALLSTATIC_FUNC_NAME ) ;
2007-09-29 08:52:40 +00:00
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 05:22:07 +00:00
if ( Z_ISREF_P ( method_result_ptr ) | | Z_REFCOUNT_P ( method_result_ptr ) > 1 ) {
2007-09-29 08:52:40 +00: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-02 16:17:25 +00:00
2009-06-12 21:36:53 +00:00
static inline union _zend_function * zend_get_user_callstatic_function ( zend_class_entry * ce , const char * method_name , int method_len ) /* { { { */
2009-06-12 01:05:25 +00:00
{
zend_internal_function * callstatic_user_call = emalloc ( sizeof ( zend_internal_function ) ) ;
callstatic_user_call - > type = ZEND_INTERNAL_FUNCTION ;
2010-09-15 07:38:52 +00:00
callstatic_user_call - > module = ( ce - > type = = ZEND_INTERNAL_CLASS ) ? ce - > info . internal . module : NULL ;
2009-06-12 01:05:25 +00:00
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 ;
callstatic_user_call - > fn_flags = ZEND_ACC_STATIC | ZEND_ACC_PUBLIC | ZEND_ACC_CALL_VIA_HANDLER ;
callstatic_user_call - > function_name = estrndup ( method_name , method_len ) ;
return ( zend_function * ) callstatic_user_call ;
}
/* }}} */
2003-02-02 16:17:25 +00:00
/* This is not (yet?) in the API, but it belongs in the built-in objects callbacks */
2007-11-02 19:40:39 +00:00
2011-09-13 13:29:35 +00:00
ZEND_API zend_function * zend_std_get_static_method ( zend_class_entry * ce , const char * function_name_strval , int function_name_strlen , const zend_literal * key TSRMLS_DC ) /* { { { */
2003-02-02 16:17:25 +00:00
{
2008-03-17 14:54:42 +00:00
zend_function * fbc = NULL ;
2008-06-03 18:11:12 +00:00
char * lc_class_name , * lc_function_name = NULL ;
2010-04-20 10:57:45 +00:00
ulong hash_value ;
ALLOCA_FLAG ( use_heap )
2003-02-02 16:17:25 +00:00
2010-05-06 12:52:27 +00:00
if ( EXPECTED ( key ! = NULL ) ) {
2010-04-20 10:57:45 +00:00
lc_function_name = Z_STRVAL ( key - > constant ) ;
hash_value = key - > hash_value ;
} else {
lc_function_name = do_alloca ( function_name_strlen + 1 , use_heap ) ;
/* Create a zend_copy_str_tolower(dest, src, src_length); */
zend_str_tolower_copy ( lc_function_name , function_name_strval , function_name_strlen ) ;
hash_value = zend_hash_func ( lc_function_name , function_name_strlen + 1 ) ;
}
2012-05-13 05:12:48 +00:00
2008-03-17 14:54:42 +00:00
if ( function_name_strlen = = ce - > name_length & & ce - > constructor ) {
lc_class_name = zend_str_tolower_dup ( ce - > name , ce - > name_length ) ;
2009-06-19 03:29:47 +00:00
/* Only change the method to the constructor if the constructor isn't called __construct
* we check for __ so we can be binary safe for lowering , we should use ZEND_CONSTRUCTOR_FUNC_NAME
*/
2010-06-12 15:30:21 +00:00
if ( ! memcmp ( lc_class_name , lc_function_name , function_name_strlen ) & & memcmp ( ce - > constructor - > common . function_name , " __ " , sizeof ( " __ " ) - 1 ) ) {
2008-03-17 14:54:42 +00:00
fbc = ce - > constructor ;
}
efree ( lc_class_name ) ;
}
2010-05-06 12:52:27 +00:00
if ( EXPECTED ( ! fbc ) & &
UNEXPECTED ( zend_hash_quick_find ( & ce - > function_table , lc_function_name , function_name_strlen + 1 , hash_value , ( void * * ) & fbc ) = = FAILURE ) ) {
if ( UNEXPECTED ( ! key ) ) {
2010-04-20 10:57:45 +00:00
free_alloca ( lc_function_name , use_heap ) ;
}
2008-06-03 18:11:12 +00:00
2010-11-03 01:35:26 +00:00
if ( ce - > __call & &
2007-11-12 09:12:06 +00:00
EG ( This ) & &
Z_OBJ_HT_P ( EG ( This ) ) - > get_class_entry & &
instanceof_function ( Z_OBJCE_P ( EG ( This ) ) , ce TSRMLS_CC ) ) {
2009-06-12 01:05:25 +00:00
return zend_get_user_call_function ( ce , function_name_strval , function_name_strlen ) ;
2010-11-03 01:35:26 +00:00
} else if ( ce - > __callstatic ) {
return zend_get_user_callstatic_function ( ce , function_name_strval , function_name_strlen ) ;
2007-09-29 08:52:40 +00:00
} else {
2008-07-26 13:14:04 +00:00
return NULL ;
2003-03-11 23:19:45 +00:00
}
2003-02-02 16:17:25 +00:00
}
2007-11-02 19:40:39 +00:00
# if MBO_0
/* right now this function is used for non static method lookup too */
/* Is the function static */
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( ! ( fbc - > common . fn_flags & ZEND_ACC_STATIC ) ) ) {
zend_error_noreturn ( E_ERROR , " Cannot call non static method %s::%s() without object " , ZEND_FN_SCOPE_NAME ( fbc ) , fbc - > common . function_name ) ;
2007-11-02 19:40:39 +00:00
}
2012-05-13 05:12:48 +00:00
# endif
2003-02-02 16:17:25 +00: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.
*/
2010-04-20 10:57:45 +00:00
updated_fbc = zend_check_private_int ( fbc , EG ( scope ) , lc_function_name , function_name_strlen , hash_value TSRMLS_CC ) ;
2010-05-06 12:52:27 +00:00
if ( EXPECTED ( updated_fbc ! = NULL ) ) {
2009-06-12 01:05:25 +00:00
fbc = updated_fbc ;
} else {
if ( ce - > __callstatic ) {
2010-04-20 10:57:45 +00:00
fbc = zend_get_user_callstatic_function ( ce , function_name_strval , function_name_strlen ) ;
} else {
2010-05-06 12:52:27 +00:00
zend_error_noreturn ( 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 : " " ) ;
2009-06-12 01:05:25 +00:00
}
2003-02-02 16:17:25 +00:00
}
} else if ( ( fbc - > common . fn_flags & ZEND_ACC_PROTECTED ) ) {
/* Ensure that if we're calling a protected function, we're allowed to do so.
*/
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( ! zend_check_protected ( zend_get_function_root_class ( fbc ) , EG ( scope ) ) ) ) {
2009-06-12 01:05:25 +00:00
if ( ce - > __callstatic ) {
2010-04-20 10:57:45 +00:00
fbc = zend_get_user_callstatic_function ( ce , function_name_strval , function_name_strlen ) ;
} else {
2010-05-06 12:52:27 +00:00
zend_error_noreturn ( 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 : " " ) ;
2009-06-12 01:05:25 +00:00
}
2003-02-02 16:17:25 +00:00
}
}
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( ! key ) ) {
2010-04-20 10:57:45 +00:00
free_alloca ( lc_function_name , use_heap ) ;
}
2003-02-02 16:17:25 +00:00
return fbc ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2003-02-02 16:17:25 +00:00
2011-09-13 13:29:35 +00:00
ZEND_API zval * * zend_std_get_static_property ( zend_class_entry * ce , const char * property_name , int property_name_len , zend_bool silent , const zend_literal * key TSRMLS_DC ) /* { { { */
2003-02-05 13:35:52 +00:00
{
zend_property_info * property_info ;
2010-04-20 10:57:45 +00:00
ulong hash_value ;
2012-05-13 05:12:48 +00:00
2010-05-24 14:11:39 +00:00
if ( UNEXPECTED ( ! key ) | |
( property_info = CACHED_POLYMORPHIC_PTR ( key - > cache_slot , ce ) ) = = NULL ) {
if ( EXPECTED ( key ! = NULL ) ) {
hash_value = key - > hash_value ;
} else {
hash_value = zend_hash_func ( property_name , property_name_len + 1 ) ;
}
2003-02-05 13:35:52 +00:00
2010-05-24 14:11:39 +00:00
if ( UNEXPECTED ( zend_hash_quick_find ( & ce - > properties_info , property_name , property_name_len + 1 , hash_value , ( void * * ) & property_info ) = = FAILURE ) ) {
if ( ! silent ) {
zend_error_noreturn ( E_ERROR , " Access to undeclared static property: %s::$%s " , ce - > name , property_name ) ;
}
return NULL ;
}
2003-02-05 13:35:52 +00:00
2005-05-18 15:14:36 +00:00
# if DEBUG_OBJECT_HANDLERS
2010-05-24 14:11:39 +00:00
zend_printf ( " Access type for %s::%s is %s \n " , ce - > name , property_name , zend_visibility_string ( property_info - > flags ) ) ;
2003-02-05 13:35:52 +00:00
# endif
2010-05-24 14:11:39 +00:00
if ( UNEXPECTED ( ! zend_verify_property_access ( property_info , ce TSRMLS_CC ) ) ) {
if ( ! silent ) {
zend_error_noreturn ( E_ERROR , " Cannot access %s property %s::$%s " , zend_visibility_string ( property_info - > flags ) , ce - > name , property_name ) ;
}
return NULL ;
2005-02-27 22:22:26 +00:00
}
2003-02-05 13:35:52 +00:00
2010-05-24 14:11:39 +00:00
if ( UNEXPECTED ( ( property_info - > flags & ZEND_ACC_STATIC ) = = 0 ) ) {
if ( ! silent ) {
zend_error_noreturn ( E_ERROR , " Access to undeclared static property: %s::$%s " , ce - > name , property_name ) ;
}
return NULL ;
}
2005-09-01 10:05:32 +00:00
2010-05-24 14:11:39 +00:00
zend_update_class_constants ( ce TSRMLS_CC ) ;
2003-02-05 13:35:52 +00:00
2010-05-24 14:11:39 +00:00
if ( EXPECTED ( key ! = NULL ) ) {
CACHE_POLYMORPHIC_PTR ( key - > cache_slot , ce , property_info ) ;
2003-02-05 13:35:52 +00:00
}
}
2006-05-09 23:53:23 +00:00
2010-05-24 14:11:39 +00:00
return & CE_STATIC_MEMBERS ( ce ) [ property_info - > offset ] ;
2003-02-05 13:35:52 +00:00
}
2007-11-02 19:40:39 +00:00
/* }}} */
2003-02-05 13:35:52 +00:00
2011-09-13 13:29:35 +00:00
ZEND_API zend_bool zend_std_unset_static_property ( zend_class_entry * ce , const char * property_name , int property_name_len , const zend_literal * key TSRMLS_DC ) /* { { { */
2003-02-17 14:06:39 +00:00
{
2010-05-06 12:52:27 +00:00
zend_error_noreturn ( E_ERROR , " Attempt to unset static property %s::$%s " , ce - > name , property_name ) ;
2003-02-17 14:06:39 +00:00
return 0 ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2003-02-17 14:06:39 +00:00
2007-11-02 19:40:39 +00:00
ZEND_API union _zend_function * zend_std_get_constructor ( zval * object TSRMLS_DC ) /* { { { */
2002-02-07 14:08:43 +00:00
{
2003-02-02 16:17:25 +00: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.
*/
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( constructor - > common . scope ! = EG ( scope ) ) ) {
2006-07-05 11:39:00 +00:00
if ( EG ( scope ) ) {
2010-05-06 12:52:27 +00:00
zend_error_noreturn ( E_ERROR , " Call to private %s::%s() from context '%s' " , constructor - > common . scope - > name , constructor - > common . function_name , EG ( scope ) - > name ) ;
2006-07-05 11:39:00 +00:00
} else {
2010-05-06 12:52:27 +00:00
zend_error_noreturn ( E_ERROR , " Call to private %s::%s() from invalid context " , constructor - > common . scope - > name , constructor - > common . function_name ) ;
2006-07-05 11:39:00 +00:00
}
2003-02-02 16:17:25 +00: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.
2007-11-02 19:40:39 +00:00
* Constructors only have prototype if they are defined by an interface but
* it is the compilers responsibility to take care of the prototype .
2003-02-02 16:17:25 +00:00
*/
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( ! zend_check_protected ( zend_get_function_root_class ( constructor ) , EG ( scope ) ) ) ) {
2006-07-05 11:39:00 +00:00
if ( EG ( scope ) ) {
2010-05-06 12:52:27 +00:00
zend_error_noreturn ( E_ERROR , " Call to protected %s::%s() from context '%s' " , constructor - > common . scope - > name , constructor - > common . function_name , EG ( scope ) - > name ) ;
2006-07-05 11:39:00 +00:00
} else {
2010-05-06 12:52:27 +00:00
zend_error_noreturn ( E_ERROR , " Call to protected %s::%s() from invalid context " , constructor - > common . scope - > name , constructor - > common . function_name ) ;
2006-07-05 11:39:00 +00:00
}
2003-02-02 16:17:25 +00:00
}
}
}
return constructor ;
2002-02-07 14:08:43 +00:00
}
2007-11-02 19:40:39 +00:00
/* }}} */
2003-02-05 14:27:30 +00:00
2002-02-07 14:08:43 +00:00
int zend_compare_symbol_tables_i ( HashTable * ht1 , HashTable * ht2 TSRMLS_DC ) ;
2007-11-02 19:40:39 +00:00
static int zend_std_compare_objects ( zval * o1 , zval * o2 TSRMLS_DC ) /* { { { */
2002-02-07 14:08:43 +00:00
{
zend_object * zobj1 , * zobj2 ;
2006-05-09 23:53:23 +00:00
2002-04-22 14:22:27 +00:00
zobj1 = Z_OBJ_P ( o1 ) ;
zobj2 = Z_OBJ_P ( o2 ) ;
2002-02-07 14:08:43 +00:00
2002-09-15 07:45:26 +00:00
if ( zobj1 - > ce ! = zobj2 - > ce ) {
2002-02-07 14:08:43 +00:00
return 1 ; /* different classes */
}
2010-05-24 14:11:39 +00:00
if ( ! zobj1 - > properties & & ! zobj2 - > properties ) {
int i ;
2013-01-09 07:30:50 +00:00
Z_OBJ_PROTECT_RECURSION ( o1 ) ;
Z_OBJ_PROTECT_RECURSION ( o2 ) ;
2010-05-24 14:11:39 +00:00
for ( i = 0 ; i < zobj1 - > ce - > default_properties_count ; i + + ) {
if ( zobj1 - > properties_table [ i ] ) {
if ( zobj2 - > properties_table [ i ] ) {
zval result ;
if ( compare_function ( & result , zobj1 - > properties_table [ i ] , zobj2 - > properties_table [ i ] TSRMLS_CC ) = = FAILURE ) {
2013-01-09 07:30:50 +00:00
Z_OBJ_UNPROTECT_RECURSION ( o1 ) ;
Z_OBJ_UNPROTECT_RECURSION ( o2 ) ;
2010-05-24 14:11:39 +00:00
return 1 ;
}
if ( Z_LVAL ( result ) ! = 0 ) {
2013-01-09 07:30:50 +00:00
Z_OBJ_UNPROTECT_RECURSION ( o1 ) ;
Z_OBJ_UNPROTECT_RECURSION ( o2 ) ;
2010-05-24 14:11:39 +00:00
return Z_LVAL ( result ) ;
}
} else {
2013-01-09 07:30:50 +00:00
Z_OBJ_UNPROTECT_RECURSION ( o1 ) ;
Z_OBJ_UNPROTECT_RECURSION ( o2 ) ;
2010-05-24 14:11:39 +00:00
return 1 ;
}
} else {
if ( zobj2 - > properties_table [ i ] ) {
2013-01-09 07:30:50 +00:00
Z_OBJ_UNPROTECT_RECURSION ( o1 ) ;
Z_OBJ_UNPROTECT_RECURSION ( o2 ) ;
2010-05-24 14:11:39 +00:00
return 1 ;
} else {
2013-01-09 07:30:50 +00:00
Z_OBJ_UNPROTECT_RECURSION ( o1 ) ;
Z_OBJ_UNPROTECT_RECURSION ( o2 ) ;
2010-05-24 14:11:39 +00:00
return 0 ;
}
}
}
2013-01-09 07:30:50 +00:00
Z_OBJ_UNPROTECT_RECURSION ( o1 ) ;
Z_OBJ_UNPROTECT_RECURSION ( o2 ) ;
2010-05-24 14:11:39 +00:00
return 0 ;
} else {
if ( ! zobj1 - > properties ) {
rebuild_object_properties ( zobj1 ) ;
}
if ( ! zobj2 - > properties ) {
rebuild_object_properties ( zobj2 ) ;
}
return zend_compare_symbol_tables_i ( zobj1 - > properties , zobj2 - > properties TSRMLS_CC ) ;
}
2002-02-07 14:08:43 +00:00
}
2007-11-02 19:40:39 +00:00
/* }}} */
2002-02-07 14:08:43 +00:00
2010-04-20 10:57:45 +00:00
static int zend_std_has_property ( zval * object , zval * member , int has_set_exists , const zend_literal * key TSRMLS_DC ) /* { { { */
2002-02-07 14:08:43 +00:00
{
zend_object * zobj ;
int result ;
2010-05-24 14:11:39 +00:00
zval * * value = NULL ;
2005-07-07 16:07:09 +00:00
zval * tmp_member = NULL ;
2003-02-05 14:27:30 +00:00
zend_property_info * property_info ;
2006-05-09 23:53:23 +00:00
2003-02-05 14:27:30 +00:00
zobj = Z_OBJ_P ( object ) ;
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( Z_TYPE_P ( member ) ! = IS_STRING ) ) {
2006-05-09 23:53:23 +00:00
ALLOC_ZVAL ( tmp_member ) ;
2005-07-07 16:07:09 +00:00
* tmp_member = * member ;
INIT_PZVAL ( tmp_member ) ;
zval_copy_ctor ( tmp_member ) ;
convert_to_string ( tmp_member ) ;
member = tmp_member ;
2010-04-20 10:57:45 +00:00
key = NULL ;
2002-02-07 14:08:43 +00:00
}
2003-02-05 14:27:30 +00:00
# if DEBUG_OBJECT_HANDLERS
fprintf ( stderr , " Read object #%d property: %s \n " , Z_OBJ_HANDLE_P ( object ) , Z_STRVAL_P ( member ) ) ;
2006-05-09 23:53:23 +00:00
# endif
2003-02-05 14:27:30 +00:00
2010-05-06 12:52:27 +00:00
property_info = zend_get_property_info_quick ( zobj - > ce , member , 1 , key TSRMLS_CC ) ;
2005-07-07 16:07:09 +00:00
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( ! property_info ) | |
2010-05-24 14:11:39 +00:00
( ( EXPECTED ( ( property_info - > flags & ZEND_ACC_STATIC ) = = 0 ) & &
property_info - > offset > = 0 ) ?
( zobj - > properties ?
( ( value = ( zval * * ) zobj - > properties_table [ property_info - > offset ] ) = = NULL ) :
( * ( value = & zobj - > properties_table [ property_info - > offset ] ) = = NULL ) ) :
( UNEXPECTED ( ! zobj - > properties ) | |
UNEXPECTED ( zend_hash_quick_find ( zobj - > properties , property_info - > name , property_info - > name_length + 1 , property_info - > h , ( void * * ) & value ) = = FAILURE ) ) ) ) {
2005-11-15 13:35:23 +00:00
zend_guard * guard ;
2005-07-07 16:07:09 +00:00
result = 0 ;
2005-11-15 13:35:23 +00:00
if ( ( has_set_exists ! = 2 ) & &
zobj - > ce - > __isset & &
zend_get_property_guard ( zobj , property_info , member , & guard ) = = SUCCESS & &
! guard - > in_isset ) {
2005-07-07 16:07:09 +00:00
zval * rv ;
2003-02-05 14:27:30 +00:00
2005-07-07 16:07:09 +00:00
/* have issetter - try with it! */
2008-10-17 10:26:07 +00:00
Z_ADDREF_P ( object ) ;
2010-10-01 09:49:20 +00:00
if ( PZVAL_IS_REF ( object ) ) {
SEPARATE_ZVAL ( & object ) ;
}
2005-11-15 13:35:23 +00:00
guard - > in_isset = 1 ; /* prevent circular getting */
2005-07-07 16:07:09 +00:00
rv = zend_std_call_issetter ( object , member TSRMLS_CC ) ;
if ( rv ) {
result = zend_is_true ( rv ) ;
zval_ptr_dtor ( & rv ) ;
2008-05-03 00:38:55 +00:00
if ( has_set_exists & & result ) {
2010-05-06 12:52:27 +00:00
if ( EXPECTED ( ! EG ( exception ) ) & & zobj - > ce - > __get & & ! guard - > in_get ) {
2008-05-03 00:38:55 +00:00
guard - > in_get = 1 ;
rv = zend_std_call_getter ( object , member TSRMLS_CC ) ;
guard - > in_get = 0 ;
if ( rv ) {
Z_ADDREF_P ( rv ) ;
result = i_zend_is_true ( rv ) ;
zval_ptr_dtor ( & rv ) ;
} else {
result = 0 ;
}
} else {
result = 0 ;
2005-07-07 16:07:09 +00:00
}
}
}
2005-11-15 13:35:23 +00:00
guard - > in_isset = 0 ;
2008-10-17 10:26:07 +00:00
zval_ptr_dtor ( & object ) ;
2005-07-07 16:07:09 +00:00
}
} else {
2005-05-02 16:18:02 +00:00
switch ( has_set_exists ) {
case 0 :
2005-04-25 20:41:26 +00:00
result = ( Z_TYPE_PP ( value ) ! = IS_NULL ) ;
2005-05-02 16:18:02 +00:00
break ;
default :
result = zend_is_true ( * value ) ;
break ;
case 2 :
result = 1 ;
break ;
2002-02-07 14:08:43 +00:00
}
}
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( tmp_member ! = NULL ) ) {
2005-07-07 16:07:09 +00:00
zval_ptr_dtor ( & tmp_member ) ;
2002-02-07 14:08:43 +00:00
}
return result ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2002-02-07 14:08:43 +00:00
2008-08-12 17:20:25 +00:00
zend_class_entry * zend_std_object_get_class ( const zval * object TSRMLS_DC ) /* { { { */
2002-04-30 09:56:48 +00:00
{
zend_object * zobj ;
zobj = Z_OBJ_P ( object ) ;
return zobj - > ce ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2002-04-30 09:56:48 +00:00
2011-09-13 13:29:35 +00:00
int zend_std_object_get_class_name ( const zval * object , const char * * class_name , zend_uint * class_name_len , int parent TSRMLS_DC ) /* { { { */
2003-01-12 13:56:51 +00:00
{
zend_object * zobj ;
2003-04-21 17:01:34 +00:00
zend_class_entry * ce ;
2003-01-12 13:56:51 +00:00
zobj = Z_OBJ_P ( object ) ;
2003-01-14 12:13:51 +00:00
if ( parent ) {
if ( ! zobj - > ce - > parent ) {
2003-01-12 13:56:51 +00:00
return FAILURE ;
}
2003-04-21 17:01:34 +00:00
ce = zobj - > ce - > parent ;
2003-01-12 13:56:51 +00:00
} else {
2003-04-21 17:01:34 +00:00
ce = zobj - > ce ;
2003-01-12 13:56:51 +00:00
}
2003-04-21 17:01:34 +00:00
2003-06-04 08:16:55 +00:00
* class_name_len = ce - > name_length ;
* class_name = estrndup ( ce - > name , ce - > name_length ) ;
2003-01-12 13:56:51 +00:00
return SUCCESS ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2003-01-12 13:56:51 +00:00
2007-11-02 19:40:39 +00:00
ZEND_API int zend_std_cast_object_tostring ( zval * readobj , zval * writeobj , int type TSRMLS_DC ) /* { { { */
2003-12-15 16:59:21 +00:00
{
2006-05-09 23:53:23 +00:00
zval * retval ;
zend_class_entry * ce ;
2003-12-15 16:59:21 +00:00
switch ( type ) {
case IS_STRING :
2006-05-09 23:53:23 +00:00
ce = Z_OBJCE_P ( readobj ) ;
if ( ce - > __tostring & &
2007-10-18 20:44:41 +00:00
( zend_call_method_with_0_params ( & readobj , ce , & ce - > __tostring , " __tostring " , & retval ) | | EG ( exception ) ) ) {
2010-05-06 12:52:27 +00:00
if ( UNEXPECTED ( EG ( exception ) ! = NULL ) ) {
2007-10-18 20:44:41 +00:00
if ( retval ) {
zval_ptr_dtor ( & retval ) ;
}
2012-09-06 07:26:40 +00:00
EG ( exception ) = NULL ;
2010-05-06 12:52:27 +00:00
zend_error_noreturn ( E_ERROR , " Method %s::__toString() must not throw an exception " , ce - > name ) ;
2007-10-18 20:44:41 +00:00
return FAILURE ;
}
2010-05-06 12:52:27 +00:00
if ( EXPECTED ( Z_TYPE_P ( retval ) = = IS_STRING ) ) {
2006-05-09 23:53:23 +00:00
INIT_PZVAL ( writeobj ) ;
2007-12-21 20:56:33 +00:00
if ( readobj = = writeobj ) {
zval_dtor ( readobj ) ;
}
2006-05-09 23:53:23 +00:00
ZVAL_ZVAL ( writeobj , retval , 1 , 1 ) ;
if ( Z_TYPE_P ( writeobj ) ! = type ) {
convert_to_explicit_type ( writeobj , type ) ;
2003-12-15 16:59:21 +00:00
}
2006-05-09 23:53:23 +00:00
return SUCCESS ;
2003-12-15 16:59:21 +00:00
} else {
2006-05-09 23:53:23 +00:00
zval_ptr_dtor ( & retval ) ;
INIT_PZVAL ( writeobj ) ;
2007-12-21 20:56:33 +00:00
if ( readobj = = writeobj ) {
zval_dtor ( readobj ) ;
}
2006-05-09 23:53:23 +00:00
ZVAL_EMPTY_STRING ( writeobj ) ;
zend_error ( E_RECOVERABLE_ERROR , " Method %s::__toString() must return a string value " , ce - > name ) ;
return SUCCESS ;
2003-12-15 16:59:21 +00:00
}
}
2006-05-09 23:53:23 +00: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 ) ;
2007-12-21 20:56:33 +00:00
if ( readobj = = writeobj ) {
zval_dtor ( readobj ) ;
}
2006-05-09 23:53:23 +00:00
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 ) ;
2007-12-21 20:56:33 +00:00
if ( readobj = = writeobj ) {
zval_dtor ( readobj ) ;
}
2006-05-09 23:53:23 +00:00
ZVAL_DOUBLE ( writeobj , 1 ) ;
return SUCCESS ;
2003-12-15 16:59:21 +00:00
default :
2007-12-21 20:56:33 +00:00
INIT_PZVAL ( writeobj ) ;
Z_TYPE_P ( writeobj ) = IS_NULL ;
2003-12-15 16:59:21 +00:00
break ;
}
return FAILURE ;
}
2007-11-02 19:40:39 +00:00
/* }}} */
2003-09-18 11:38:33 +00:00
2008-11-27 19:01:23 +00:00
int zend_std_get_closure ( zval * obj , zend_class_entry * * ce_ptr , zend_function * * fptr_ptr , zval * * zobj_ptr TSRMLS_DC ) /* { { { */
2008-08-14 21:36:56 +00:00
{
zend_class_entry * ce ;
if ( Z_TYPE_P ( obj ) ! = IS_OBJECT ) {
return FAILURE ;
}
ce = Z_OBJCE_P ( obj ) ;
if ( zend_hash_find ( & ce - > function_table , ZEND_INVOKE_FUNC_NAME , sizeof ( ZEND_INVOKE_FUNC_NAME ) , ( void * * ) fptr_ptr ) = = FAILURE ) {
return FAILURE ;
}
* ce_ptr = ce ;
if ( ( * fptr_ptr ) - > common . fn_flags & ZEND_ACC_STATIC ) {
if ( zobj_ptr ) {
* zobj_ptr = NULL ;
}
} else {
if ( zobj_ptr ) {
* zobj_ptr = obj ;
}
}
return SUCCESS ;
}
/* }}} */
2003-12-22 13:09:15 +00:00
ZEND_API zend_object_handlers std_object_handlers = {
2003-07-07 09:12:15 +00:00
zend_objects_store_add_ref , /* add_ref */
zend_objects_store_del_ref , /* del_ref */
zend_objects_clone_obj , /* clone_obj */
2006-05-09 23:53:23 +00:00
2003-07-07 09:12:15 +00:00
zend_std_read_property , /* read_property */
zend_std_write_property , /* write_property */
2003-07-07 10:53:27 +00:00
zend_std_read_dimension , /* read_dimension */
2003-07-07 09:12:15 +00:00
zend_std_write_dimension , /* write_dimension */
2003-10-05 07:52:28 +00:00
zend_std_get_property_ptr_ptr , /* get_property_ptr_ptr */
2003-07-07 09:12:15 +00:00
NULL , /* get */
NULL , /* set */
zend_std_has_property , /* has_property */
zend_std_unset_property , /* unset_property */
2003-11-10 16:14:44 +00:00
zend_std_has_dimension , /* has_dimension */
2003-07-30 17:12:06 +00:00
zend_std_unset_dimension , /* unset_dimension */
2003-07-07 09:12:15 +00: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-09 23:53:23 +00:00
zend_std_cast_object_tostring , /* cast_object */
2004-05-04 15:03:28 +00:00
NULL , /* count_elements */
2008-08-14 21:36:56 +00:00
NULL , /* get_debug_info */
zend_std_get_closure , /* get_closure */
2011-11-02 06:31:33 +00:00
zend_std_get_gc , /* get_gc */
2002-02-07 14:08:43 +00:00
} ;
2003-02-01 01:49:15 +00:00
/*
* Local variables :
* tab - width : 4
* c - basic - offset : 4
* indent - tabs - mode : t
* End :
*/