2006-05-10 07:53:23 +08:00
/*
2003-02-01 09:49:15 +08:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| Zend Engine |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2015-01-15 23:27:30 +08:00
| Copyright ( c ) 1998 - 2015 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"
2008-08-15 05:36:56 +08:00
# include "zend_closures.h"
2009-06-18 21:46:16 +08:00
# include "zend_compile.h"
2013-12-13 03:25:10 +08:00
# include "zend_hash.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
2014-02-10 14:04:30 +08:00
/* guard flags */
# define IN_GET (1<<0)
# define IN_SET (1<<1)
# define IN_UNSET (1<<2)
# define IN_ISSET (1<<3)
2003-01-12 22:39:45 +08:00
2013-01-09 15:30:50 +08:00
# define Z_OBJ_PROTECT_RECURSION(zval_p) \
do { \
2014-02-12 22:08:11 +08:00
if ( Z_OBJ_APPLY_COUNT_P ( zval_p ) > = 3 ) { \
2013-01-09 15:30:50 +08:00
zend_error ( E_ERROR , " Nesting level too deep - recursive dependency? " ) ; \
} \
2014-02-12 22:08:11 +08:00
Z_OBJ_INC_APPLY_COUNT_P ( zval_p ) ; \
2013-01-09 15:30:50 +08:00
} while ( 0 )
# define Z_OBJ_UNPROTECT_RECURSION(zval_p) \
2014-02-12 22:08:11 +08:00
Z_OBJ_DEC_APPLY_COUNT_P ( zval_p )
2013-01-09 15:30:50 +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
*/
2010-05-24 22:11:39 +08:00
ZEND_API void rebuild_object_properties ( zend_object * zobj ) /* { { { */
{
if ( ! zobj - > properties ) {
zend_property_info * prop_info ;
zend_class_entry * ce = zobj - > ce ;
ALLOC_HASHTABLE ( zobj - > properties ) ;
2014-07-08 17:46:03 +08:00
zend_hash_init ( zobj - > properties , ce - > default_properties_count , NULL , ZVAL_PTR_DTOR , 0 ) ;
2010-05-24 22:11:39 +08:00
if ( ce - > default_properties_count ) {
2014-04-18 23:18:11 +08:00
ZEND_HASH_FOREACH_PTR ( & ce - > properties_info , prop_info ) {
2010-05-24 22:11:39 +08:00
if ( /*prop_info->ce == ce &&*/
2012-05-13 13:12:48 +08:00
( prop_info - > flags & ZEND_ACC_STATIC ) = = 0 & &
2014-11-06 19:50:03 +08:00
Z_TYPE_P ( OBJ_PROP ( zobj , prop_info - > offset ) ) ! = IS_UNDEF ) {
2014-03-26 22:07:31 +08:00
zval zv ;
2014-11-06 19:50:03 +08:00
ZVAL_INDIRECT ( & zv , OBJ_PROP ( zobj , prop_info - > offset ) ) ;
2014-07-08 17:46:03 +08:00
zend_hash_add_new ( zobj - > properties , prop_info - > name , & zv ) ;
2012-05-13 13:12:48 +08:00
}
2014-04-18 23:18:11 +08:00
} ZEND_HASH_FOREACH_END ( ) ;
2010-05-24 22:11:39 +08:00
while ( ce - > parent & & ce - > parent - > default_properties_count ) {
ce = ce - > parent ;
2014-04-18 23:18:11 +08:00
ZEND_HASH_FOREACH_PTR ( & ce - > properties_info , prop_info ) {
2010-05-24 22:11:39 +08:00
if ( prop_info - > ce = = ce & &
2012-05-13 13:12:48 +08:00
( prop_info - > flags & ZEND_ACC_STATIC ) = = 0 & &
( prop_info - > flags & ZEND_ACC_PRIVATE ) ! = 0 & &
2014-11-06 19:50:03 +08:00
Z_TYPE_P ( OBJ_PROP ( zobj , prop_info - > offset ) ) ! = IS_UNDEF ) {
2014-03-26 22:07:31 +08:00
zval zv ;
2015-01-03 17:22:58 +08:00
2014-11-06 19:50:03 +08:00
ZVAL_INDIRECT ( & zv , OBJ_PROP ( zobj , prop_info - > offset ) ) ;
2014-03-26 22:07:31 +08:00
zend_hash_add ( zobj - > properties , prop_info - > name , & zv ) ;
2012-05-13 13:12:48 +08:00
}
2014-04-18 23:18:11 +08:00
} ZEND_HASH_FOREACH_END ( ) ;
2010-05-24 22:11:39 +08:00
}
}
}
}
2011-09-15 22:50:38 +08:00
/* }}} */
2010-05-24 22:11:39 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API HashTable * zend_std_get_properties ( zval * object ) /* { { { */
2002-02-07 22:08:43 +08:00
{
zend_object * zobj ;
2002-04-22 22:22:27 +08:00
zobj = Z_OBJ_P ( object ) ;
2010-05-24 22:11:39 +08:00
if ( ! zobj - > properties ) {
rebuild_object_properties ( zobj ) ;
}
2002-02-07 22:08:43 +08:00
return zobj - > properties ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API HashTable * zend_std_get_gc ( zval * object , zval * * table , int * n ) /* { { { */
2011-11-02 14:31:33 +08:00
{
if ( Z_OBJ_HANDLER_P ( object , get_properties ) ! = zend_std_get_properties ) {
* table = NULL ;
* n = 0 ;
2014-12-14 06:06:14 +08:00
return Z_OBJ_HANDLER_P ( object , get_properties ) ( object ) ;
2011-11-02 14:31:33 +08:00
} else {
zend_object * zobj = Z_OBJ_P ( object ) ;
2014-03-26 22:07:31 +08:00
* table = zobj - > properties_table ;
* n = zobj - > ce - > default_properties_count ;
return zobj - > properties ;
2011-11-02 14:31:33 +08:00
}
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API HashTable * zend_std_get_debug_info ( zval * object , int * is_temp ) /* { { { */
2007-11-03 03:40:39 +08:00
{
2014-02-18 11:13:00 +08:00
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
2014-04-26 04:32:51 +08:00
zval retval ;
HashTable * ht ;
2014-02-18 11:13:00 +08:00
if ( ! ce - > __debugInfo ) {
* is_temp = 0 ;
return Z_OBJ_HANDLER_P ( object , get_properties )
2014-12-14 06:06:14 +08:00
? Z_OBJ_HANDLER_P ( object , get_properties ) ( object )
2014-02-18 11:13:00 +08:00
: NULL ;
}
2014-04-26 04:32:51 +08:00
zend_call_method_with_0_params ( object , ce , & ce - > __debugInfo , ZEND_DEBUGINFO_FUNC_NAME , & retval ) ;
if ( Z_TYPE ( retval ) = = IS_ARRAY ) {
2014-06-03 06:43:53 +08:00
if ( Z_IMMUTABLE ( retval ) ) {
* is_temp = 1 ;
ALLOC_HASHTABLE ( ht ) ;
zend_array_dup ( ht , Z_ARRVAL ( retval ) ) ;
return ht ;
} else if ( Z_REFCOUNT ( retval ) < = 1 ) {
2014-02-18 11:13:00 +08:00
* is_temp = 1 ;
2014-04-26 04:32:51 +08:00
ALLOC_HASHTABLE ( ht ) ;
* ht = * Z_ARRVAL ( retval ) ;
2014-08-28 00:49:56 +08:00
efree_size ( Z_ARR ( retval ) , sizeof ( zend_array ) ) ;
2014-02-18 11:13:00 +08:00
return ht ;
} else {
* is_temp = 0 ;
zval_ptr_dtor ( & retval ) ;
2014-06-03 06:43:53 +08:00
return Z_ARRVAL ( retval ) ;
2014-02-18 11:13:00 +08:00
}
2014-04-26 04:32:51 +08:00
} else if ( Z_TYPE ( retval ) = = IS_NULL ) {
2014-02-18 11:13:00 +08:00
* is_temp = 1 ;
2014-04-26 04:32:51 +08:00
ALLOC_HASHTABLE ( ht ) ;
zend_hash_init ( ht , 0 , NULL , ZVAL_PTR_DTOR , 0 ) ;
return ht ;
2014-02-18 11:13:00 +08:00
}
zend_error_noreturn ( E_ERROR , ZEND_DEBUGINFO_FUNC_NAME " () must return an array " ) ;
2014-04-12 01:33:56 +08:00
return NULL ; /* Compilers are dumb and don't understand that noreturn means that the function does NOT need a return value... */
2007-11-03 03:40:39 +08:00
}
/* }}} */
2002-02-07 22:08:43 +08:00
2014-12-14 06:06:14 +08:00
static void zend_std_call_getter ( zval * object , zval * member , zval * retval ) /* { { { */
2002-09-04 17:07:58 +08:00
{
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
2014-11-20 03:59:31 +08:00
it should return whether the call was successful or not
2002-09-04 17:07:58 +08:00
*/
2014-06-05 20:04:11 +08:00
if ( Z_REFCOUNTED_P ( member ) ) Z_ADDREF_P ( member ) ;
2005-02-02 15:19:22 +08:00
2014-02-10 14:04:30 +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
2014-02-10 14:04:30 +08:00
zval_ptr_dtor ( member ) ;
2002-09-04 17:07:58 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2002-09-04 17:07:58 +08:00
2014-12-14 06:06:14 +08:00
static int zend_std_call_setter ( zval * object , zval * member , zval * value ) /* { { { */
2002-09-04 17:07:58 +08:00
{
2014-02-10 14:04:30 +08:00
zval retval ;
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
2014-06-05 20:04:11 +08:00
if ( Z_REFCOUNTED_P ( member ) ) Z_ADDREF_P ( member ) ;
2014-02-22 00:35:40 +08:00
if ( Z_REFCOUNTED_P ( value ) ) 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
2014-11-20 03:59:31 +08:00
it should return whether the call was successful or not
2002-09-04 17:07:58 +08:00
*/
2014-02-10 14:04:30 +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
2014-02-10 14:04:30 +08:00
zval_ptr_dtor ( member ) ;
zval_ptr_dtor ( value ) ;
2002-09-04 17:07:58 +08:00
2014-02-10 14:04:30 +08:00
if ( Z_TYPE ( retval ) ! = IS_UNDEF ) {
2014-12-14 06:06:14 +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
}
}
2007-11-03 03:40:39 +08:00
/* }}} */
2002-09-04 17:07:58 +08:00
2014-12-14 06:06:14 +08:00
static void zend_std_call_unsetter ( zval * object , zval * member ) /* { { { */
2005-07-08 00:07:09 +08:00
{
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
2014-06-05 20:04:11 +08:00
if ( Z_REFCOUNTED_P ( member ) ) Z_ADDREF_P ( member ) ;
2005-07-08 00:07:09 +08:00
2014-02-10 14:04:30 +08:00
zend_call_method_with_1_params ( object , ce , & ce - > __unset , ZEND_UNSET_FUNC_NAME , NULL , member ) ;
2005-07-08 00:07:09 +08:00
2014-02-10 14:04:30 +08:00
zval_ptr_dtor ( member ) ;
2005-07-08 00:07:09 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-07-08 00:07:09 +08:00
2014-12-14 06:06:14 +08:00
static void zend_std_call_issetter ( zval * object , zval * member , zval * retval ) /* { { { */
2005-07-08 00:07:09 +08:00
{
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
2014-06-05 20:04:11 +08:00
if ( Z_REFCOUNTED_P ( member ) ) Z_ADDREF_P ( member ) ;
2005-07-08 00:07:09 +08:00
2014-02-10 14:04:30 +08:00
zend_call_method_with_1_params ( object , ce , & ce - > __isset , ZEND_ISSET_FUNC_NAME , retval , member ) ;
2005-07-08 00:07:09 +08:00
2014-02-10 14:04:30 +08:00
zval_ptr_dtor ( member ) ;
2005-07-08 00:07:09 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-02-04 20:12:34 +08:00
2014-12-14 06:06:14 +08:00
static zend_always_inline int zend_verify_property_access ( zend_property_info * property_info , zend_class_entry * ce ) /* { { { */
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 :
2014-10-21 00:33:35 +08:00
return ( ce = = EG ( scope ) | | property_info - > ce = = EG ( scope ) ) ;
2003-02-04 20:12:34 +08:00
}
return 0 ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-02-04 20:12:34 +08:00
2010-05-24 22:11:39 +08:00
static zend_always_inline zend_bool is_derived_class ( zend_class_entry * child_class , zend_class_entry * parent_class ) /* { { { */
2003-07-21 20:13:16 +08: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-03 03:40:39 +08:00
/* }}} */
2003-07-21 20:13:16 +08:00
2015-01-13 16:33:00 +08:00
static zend_always_inline uint32_t zend_get_property_offset ( zend_class_entry * ce , zend_string * member , int silent , void * * cache_slot ) /* { { { */
2003-02-07 18:05:36 +08:00
{
2014-10-21 00:33:35 +08:00
zval * zv ;
zend_property_info * property_info = NULL ;
uint32_t flags ;
2003-03-19 00:30:23 +08:00
2014-07-08 00:54:31 +08:00
if ( cache_slot & & EXPECTED ( ce = = CACHED_PTR_EX ( cache_slot ) ) ) {
2015-01-13 16:33:00 +08:00
return ( uint32_t ) ( intptr_t ) CACHED_PTR_EX ( cache_slot + 1 ) ;
2010-05-24 22:11:39 +08:00
}
2014-04-02 03:27:51 +08:00
if ( UNEXPECTED ( member - > val [ 0 ] = = ' \0 ' ) ) {
2005-04-29 01:40:11 +08:00
if ( ! silent ) {
2014-04-02 03:27:51 +08:00
if ( member - > len = = 0 ) {
2010-05-06 20:52:27 +08:00
zend_error_noreturn ( E_ERROR , " Cannot access empty property " ) ;
2005-04-29 01:40:11 +08:00
} else {
2010-05-06 20:52:27 +08:00
zend_error_noreturn ( E_ERROR , " Cannot access property started with ' \\ 0' " ) ;
2005-04-29 01:40:11 +08:00
}
}
2015-01-13 16:33:00 +08:00
return ZEND_WRONG_PROPERTY_OFFSET ;
2005-04-29 01:40:11 +08:00
}
2014-10-21 00:33:35 +08:00
if ( UNEXPECTED ( zend_hash_num_elements ( & ce - > properties_info ) = = 0 ) ) {
goto exit_dynamic ;
}
zv = zend_hash_find ( & ce - > properties_info , member ) ;
if ( EXPECTED ( zv ! = NULL ) ) {
property_info = ( zend_property_info * ) Z_PTR_P ( zv ) ;
flags = property_info - > flags ;
if ( UNEXPECTED ( ( flags & ZEND_ACC_SHADOW ) ! = 0 ) ) {
2005-06-10 01:20:44 +08:00
/* if it's a shadow - go to access it's private */
property_info = NULL ;
} else {
2014-12-14 06:06:14 +08:00
if ( EXPECTED ( zend_verify_property_access ( property_info , ce ) ! = 0 ) ) {
2014-10-21 00:33:35 +08:00
if ( UNEXPECTED ( ! ( flags & ZEND_ACC_CHANGED ) )
| | UNEXPECTED ( ( flags & ZEND_ACC_PRIVATE ) ) ) {
2014-11-06 19:50:03 +08:00
if ( UNEXPECTED ( ( flags & ZEND_ACC_STATIC ) ! = 0 ) ) {
if ( ! silent ) {
zend_error ( E_STRICT , " Accessing static property %s::$%s as non static " , ce - > name - > val , member - > val ) ;
}
2015-01-13 16:33:00 +08:00
return ZEND_DYNAMIC_PROPERTY_OFFSET ;
2005-06-10 01:20:44 +08:00
}
2014-10-21 00:33:35 +08:00
goto exit ;
2005-06-08 16:08:18 +08:00
}
2005-06-10 01:20:44 +08:00
} else {
/* Try to look in the scope instead */
2014-10-21 00:33:35 +08:00
property_info = ZEND_WRONG_PROPERTY_INFO ;
2003-03-19 00:30:23 +08:00
}
2003-02-07 18:05:36 +08:00
}
2003-02-14 06:47:25 +08:00
}
2015-01-03 17:22:58 +08:00
2005-04-08 19:35:11 +08:00
if ( EG ( scope ) ! = ce
2003-03-19 00:30:23 +08:00
& & EG ( scope )
2010-05-24 22:11:39 +08:00
& & is_derived_class ( ce , EG ( scope ) )
2014-10-21 00:33:35 +08:00
& & ( zv = zend_hash_find ( & EG ( scope ) - > properties_info , member ) ) ! = NULL
& & ( ( zend_property_info * ) Z_PTR_P ( zv ) ) - > flags & ZEND_ACC_PRIVATE ) {
property_info = ( zend_property_info * ) Z_PTR_P ( zv ) ;
2015-01-13 16:33:00 +08:00
if ( UNEXPECTED ( ( property_info - > flags & ZEND_ACC_STATIC ) ! = 0 ) ) {
return ZEND_DYNAMIC_PROPERTY_OFFSET ;
2014-11-06 19:50:03 +08:00
}
2014-10-21 00:33:35 +08:00
} else if ( UNEXPECTED ( property_info = = NULL ) ) {
exit_dynamic :
2014-07-08 00:54:31 +08:00
if ( cache_slot ) {
2015-01-13 16:33:00 +08:00
CACHE_POLYMORPHIC_PTR_EX ( cache_slot , ce , ( void * ) ( intptr_t ) ZEND_DYNAMIC_PROPERTY_OFFSET ) ;
2010-05-24 22:11:39 +08:00
}
2015-01-13 16:33:00 +08:00
return ZEND_DYNAMIC_PROPERTY_OFFSET ;
2014-10-21 00:33:35 +08:00
} else if ( UNEXPECTED ( property_info = = ZEND_WRONG_PROPERTY_INFO ) ) {
/* Information was available, but we were denied access. Error out. */
if ( ! silent ) {
zend_error_noreturn ( E_ERROR , " Cannot access %s property %s::$%s " , zend_visibility_string ( flags ) , ce - > name - > val , member - > val ) ;
2003-03-19 00:30:23 +08:00
}
2015-01-13 16:33:00 +08:00
return ZEND_WRONG_PROPERTY_OFFSET ;
2014-10-21 00:33:35 +08:00
}
exit :
if ( cache_slot ) {
2015-01-13 16:33:00 +08:00
CACHE_POLYMORPHIC_PTR_EX ( cache_slot , ce , ( void * ) ( intptr_t ) property_info - > offset ) ;
2003-02-07 18:05:36 +08:00
}
2015-01-13 16:33:00 +08:00
return property_info - > offset ;
2003-02-07 18:05:36 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-02-07 18:05:36 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API zend_property_info * zend_get_property_info ( zend_class_entry * ce , zend_string * member , int silent ) /* { { { */
2010-04-20 18:57:45 +08:00
{
2015-01-13 16:33:00 +08:00
zval * zv ;
zend_property_info * property_info = NULL ;
uint32_t flags ;
if ( UNEXPECTED ( member - > val [ 0 ] = = ' \0 ' ) ) {
if ( ! silent ) {
if ( member - > len = = 0 ) {
zend_error_noreturn ( E_ERROR , " Cannot access empty property " ) ;
} else {
zend_error_noreturn ( E_ERROR , " Cannot access property started with ' \\ 0' " ) ;
}
}
return ZEND_WRONG_PROPERTY_INFO ;
}
if ( UNEXPECTED ( zend_hash_num_elements ( & ce - > properties_info ) = = 0 ) ) {
goto exit_dynamic ;
}
zv = zend_hash_find ( & ce - > properties_info , member ) ;
if ( EXPECTED ( zv ! = NULL ) ) {
property_info = ( zend_property_info * ) Z_PTR_P ( zv ) ;
flags = property_info - > flags ;
if ( UNEXPECTED ( ( flags & ZEND_ACC_SHADOW ) ! = 0 ) ) {
/* if it's a shadow - go to access it's private */
property_info = NULL ;
} else {
if ( EXPECTED ( zend_verify_property_access ( property_info , ce ) ! = 0 ) ) {
if ( UNEXPECTED ( ! ( flags & ZEND_ACC_CHANGED ) )
| | UNEXPECTED ( ( flags & ZEND_ACC_PRIVATE ) ) ) {
if ( UNEXPECTED ( ( flags & ZEND_ACC_STATIC ) ! = 0 ) ) {
if ( ! silent ) {
zend_error ( E_STRICT , " Accessing static property %s::$%s as non static " , ce - > name - > val , member - > val ) ;
}
}
goto exit ;
}
} else {
/* Try to look in the scope instead */
property_info = ZEND_WRONG_PROPERTY_INFO ;
}
}
}
if ( EG ( scope ) ! = ce
& & EG ( scope )
& & is_derived_class ( ce , EG ( scope ) )
& & ( zv = zend_hash_find ( & EG ( scope ) - > properties_info , member ) ) ! = NULL
& & ( ( zend_property_info * ) Z_PTR_P ( zv ) ) - > flags & ZEND_ACC_PRIVATE ) {
property_info = ( zend_property_info * ) Z_PTR_P ( zv ) ;
} else if ( UNEXPECTED ( property_info = = NULL ) ) {
exit_dynamic :
return NULL ;
} else if ( UNEXPECTED ( property_info = = ZEND_WRONG_PROPERTY_INFO ) ) {
/* Information was available, but we were denied access. Error out. */
if ( ! silent ) {
zend_error_noreturn ( E_ERROR , " Cannot access %s property %s::$%s " , zend_visibility_string ( flags ) , ce - > name - > val , member - > val ) ;
}
return ZEND_WRONG_PROPERTY_INFO ;
}
exit :
return property_info ;
2010-04-20 18:57:45 +08:00
}
/* }}} */
2014-12-14 06:06:14 +08:00
ZEND_API int zend_check_property_access ( zend_object * zobj , zend_string * prop_info_name ) /* { { { */
2003-12-19 04:07:30 +08:00
{
zend_property_info * property_info ;
2014-04-02 03:27:51 +08:00
const char * class_name = NULL ;
const char * prop_name ;
zend_string * member ;
2014-09-16 06:23:58 +08:00
size_t prop_name_len ;
2003-12-19 04:07:30 +08:00
2014-04-02 03:27:51 +08:00
if ( prop_info_name - > val [ 0 ] = = 0 ) {
2014-09-16 06:23:58 +08:00
zend_unmangle_property_name_ex ( prop_info_name , & class_name , & prop_name , & prop_name_len ) ;
2014-08-26 01:24:55 +08:00
member = zend_string_init ( prop_name , prop_name_len , 0 ) ;
2014-04-02 03:27:51 +08:00
} else {
2014-08-26 01:24:55 +08:00
member = zend_string_copy ( prop_info_name ) ;
2014-04-02 03:27:51 +08:00
}
2015-01-13 16:33:00 +08:00
property_info = zend_get_property_info ( zobj - > ce , member , 1 ) ;
2014-08-26 01:24:55 +08:00
zend_string_release ( member ) ;
2014-10-17 23:10:05 +08:00
if ( property_info = = NULL ) {
/* undefined public property */
if ( class_name & & class_name [ 0 ] ! = ' * ' ) {
/* we we're looking for a private prop */
return FAILURE ;
}
return SUCCESS ;
} else if ( property_info = = ZEND_WRONG_PROPERTY_INFO ) {
2003-12-19 04:07:30 +08:00
return FAILURE ;
}
2007-11-03 03:40:39 +08:00
if ( class_name & & class_name [ 0 ] ! = ' * ' ) {
2005-06-06 15:52:08 +08: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 ;
2014-02-10 14:04:30 +08:00
} else if ( strcmp ( prop_info_name - > val + 1 , property_info - > name - > val + 1 ) ) {
2005-06-06 15:52:08 +08:00
/* 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
}
2014-12-14 06:06:14 +08:00
return zend_verify_property_access ( property_info , zobj - > ce ) ? SUCCESS : FAILURE ;
2003-12-19 04:07:30 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-12-19 04:07:30 +08:00
2015-01-31 18:12:31 +08:00
static void zend_property_guard_dtor ( zval * el ) /* { { { */ {
efree ( Z_PTR_P ( el ) ) ;
}
/* }}} */
2014-10-17 23:10:05 +08:00
static zend_long * zend_get_property_guard ( zend_object * zobj , zend_string * member ) /* { { { */
2005-11-15 21:35:23 +08:00
{
2015-01-31 18:12:31 +08:00
zend_long stub , * guard ;
2005-11-15 21:35:23 +08:00
if ( ! zobj - > guards ) {
ALLOC_HASHTABLE ( zobj - > guards ) ;
2015-01-31 18:12:31 +08:00
zend_hash_init ( zobj - > guards , 8 , NULL , zend_property_guard_dtor , 0 ) ;
} else if ( ( guard = ( zend_long * ) zend_hash_find_ptr ( zobj - > guards , member ) ) ! = NULL ) {
return guard ;
2014-02-10 14:04:30 +08:00
}
2015-01-31 18:12:31 +08:00
stub = 0 ;
return ( zend_long * ) zend_hash_add_mem ( zobj - > guards , member , & stub , sizeof ( zend_ulong ) ) ;
2005-11-15 21:35:23 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-11-15 21:35:23 +08:00
2014-12-14 06:06:14 +08:00
zval * zend_std_read_property ( zval * object , zval * member , int type , void * * cache_slot , zval * rv ) /* { { { */
2002-02-07 22:08:43 +08:00
{
zend_object * zobj ;
2014-02-10 14:04:30 +08:00
zval tmp_member ;
zval * retval ;
2015-01-13 16:33:00 +08:00
uint32_t property_offset ;
2004-03-22 02:07:27 +08:00
2002-04-22 22:22:27 +08:00
zobj = Z_OBJ_P ( object ) ;
2002-02-07 22:08:43 +08:00
2014-02-10 14:04:30 +08:00
ZVAL_UNDEF ( & tmp_member ) ;
2010-05-06 20:52:27 +08:00
if ( UNEXPECTED ( Z_TYPE_P ( member ) ! = IS_STRING ) ) {
2014-10-07 00:45:08 +08:00
ZVAL_STR ( & tmp_member , zval_get_string ( member ) ) ;
2014-02-10 14:04:30 +08:00
member = & tmp_member ;
2014-07-08 00:54:31 +08:00
cache_slot = NULL ;
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 */
2015-01-13 16:33:00 +08:00
property_offset = zend_get_property_offset ( zobj - > ce , Z_STR_P ( member ) , ( type = = BP_VAR_IS ) | | ( zobj - > ce - > __get ! = NULL ) , cache_slot ) ;
2003-02-04 20:12:34 +08:00
2015-01-13 16:33:00 +08:00
if ( EXPECTED ( property_offset ! = ZEND_WRONG_PROPERTY_OFFSET ) ) {
if ( EXPECTED ( property_offset ! = ZEND_DYNAMIC_PROPERTY_OFFSET ) ) {
retval = OBJ_PROP ( zobj , property_offset ) ;
2014-10-21 00:33:35 +08:00
if ( EXPECTED ( Z_TYPE_P ( retval ) ! = IS_UNDEF ) ) {
2014-03-26 22:07:31 +08:00
goto exit ;
2014-02-22 02:59:51 +08:00
}
2014-10-21 00:33:35 +08:00
} else if ( EXPECTED ( zobj - > properties ! = NULL ) ) {
2014-10-17 23:10:05 +08:00
retval = zend_hash_find ( zobj - > properties , Z_STR_P ( member ) ) ;
2014-10-21 00:33:35 +08:00
if ( EXPECTED ( retval ) ) goto exit ;
2014-02-10 14:04:30 +08:00
}
}
2014-03-26 22:07:31 +08:00
/* magic get */
2014-02-10 14:04:30 +08:00
if ( zobj - > ce - > __get ) {
2014-10-17 23:10:05 +08:00
zend_long * guard = zend_get_property_guard ( zobj , Z_STR_P ( member ) ) ;
2014-02-10 14:04:30 +08:00
if ( ! ( ( * guard ) & IN_GET ) ) {
2014-04-16 22:06:03 +08:00
zval tmp_object ;
2002-09-04 17:07:58 +08:00
/* have getter - try with it! */
2014-04-16 22:06:03 +08:00
ZVAL_COPY ( & tmp_object , object ) ;
2014-02-10 14:04:30 +08:00
* guard | = IN_GET ; /* prevent circular getting */
2014-12-14 06:06:14 +08:00
zend_std_call_getter ( & tmp_object , member , rv ) ;
2014-02-10 14:04:30 +08:00
* guard & = ~ IN_GET ;
2002-09-04 17:07:58 +08:00
2014-02-27 19:40:13 +08:00
if ( Z_TYPE_P ( rv ) ! = IS_UNDEF ) {
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 ) ) {
2014-04-16 05:45:40 +08:00
SEPARATE_ZVAL ( rv ) ;
2010-05-06 20:52:27 +08:00
if ( UNEXPECTED ( Z_TYPE_P ( rv ) ! = IS_OBJECT ) ) {
2014-02-24 17:19:32 +08:00
zend_error ( E_NOTICE , " Indirect modification of overloaded property %s::$%s has no effect " , zobj - > ce - > name - > val , Z_STRVAL_P ( member ) ) ;
2006-07-21 18:32:17 +08:00
}
}
2002-09-04 17:07:58 +08:00
} else {
2014-02-27 19:40:13 +08:00
retval = & EG ( uninitialized_zval ) ;
2002-09-04 17:07:58 +08:00
}
2014-04-16 22:06:03 +08:00
zval_ptr_dtor ( & tmp_object ) ;
2014-10-17 23:10:05 +08:00
goto exit ;
2002-09-04 17:07:58 +08:00
} else {
2014-02-10 14:04:30 +08:00
if ( Z_STRVAL_P ( member ) [ 0 ] = = ' \0 ' ) {
2014-08-26 01:24:55 +08:00
if ( Z_STRLEN_P ( member ) = = 0 ) {
2014-02-10 14:04:30 +08:00
zend_error ( E_ERROR , " Cannot access empty property " ) ;
} else {
zend_error ( E_ERROR , " Cannot access property started with ' \\ 0' " ) ;
2010-08-01 21:27:02 +08:00
}
}
2014-02-10 14:04:30 +08:00
}
2002-02-07 22:08:43 +08:00
}
2014-10-17 23:10:05 +08:00
if ( ( type ! = BP_VAR_IS ) ) {
zend_error ( E_NOTICE , " Undefined property: %s::$%s " , zobj - > ce - > name - > val , Z_STRVAL_P ( member ) ) ;
}
retval = & EG ( uninitialized_zval ) ;
2014-03-26 22:07:31 +08:00
2014-02-10 14:04:30 +08:00
exit :
if ( UNEXPECTED ( Z_TYPE ( tmp_member ) ! = IS_UNDEF ) ) {
2014-02-27 22:10:42 +08:00
if ( Z_REFCOUNTED_P ( retval ) ) Z_ADDREF_P ( retval ) ;
2005-06-03 19:16:19 +08:00
zval_ptr_dtor ( & tmp_member ) ;
2014-02-27 22:10:42 +08:00
if ( Z_REFCOUNTED_P ( retval ) ) Z_DELREF_P ( retval ) ;
2002-02-07 22:08:43 +08:00
}
2014-02-10 14:04:30 +08:00
return retval ;
2002-02-07 22:08:43 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2002-02-07 22:08:43 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API void zend_std_write_property ( zval * object , zval * member , zval * value , void * * cache_slot ) /* { { { */
2002-02-07 22:08:43 +08:00
{
zend_object * zobj ;
2014-02-10 14:04:30 +08:00
zval tmp_member ;
zval * variable_ptr ;
2015-01-13 16:33:00 +08:00
uint32_t property_offset ;
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
2014-02-10 14:04:30 +08:00
ZVAL_UNDEF ( & tmp_member ) ;
2010-05-06 20:52:27 +08:00
if ( UNEXPECTED ( Z_TYPE_P ( member ) ! = IS_STRING ) ) {
2014-10-07 00:45:08 +08:00
ZVAL_STR ( & tmp_member , zval_get_string ( member ) ) ;
2014-02-10 14:04:30 +08:00
member = & tmp_member ;
2014-07-08 00:54:31 +08:00
cache_slot = NULL ;
2002-02-07 22:08:43 +08:00
}
2015-01-13 16:33:00 +08:00
property_offset = zend_get_property_offset ( zobj - > ce , Z_STR_P ( member ) , ( zobj - > ce - > __set ! = NULL ) , cache_slot ) ;
2003-02-04 20:12:34 +08:00
2015-01-13 16:33:00 +08:00
if ( EXPECTED ( property_offset ! = ZEND_WRONG_PROPERTY_OFFSET ) ) {
if ( EXPECTED ( property_offset ! = ZEND_DYNAMIC_PROPERTY_OFFSET ) ) {
variable_ptr = OBJ_PROP ( zobj , property_offset ) ;
2014-03-26 22:07:31 +08:00
if ( Z_TYPE_P ( variable_ptr ) ! = IS_UNDEF ) {
goto found ;
2014-02-22 02:59:51 +08:00
}
2014-03-26 22:07:31 +08:00
} else if ( EXPECTED ( zobj - > properties ! = NULL ) ) {
2014-10-17 23:10:05 +08:00
if ( ( variable_ptr = zend_hash_find ( zobj - > properties , Z_STR_P ( member ) ) ) ! = NULL ) {
2014-02-10 14:04:30 +08:00
found :
2014-12-14 06:06:14 +08:00
zend_assign_to_variable ( variable_ptr , value , ( IS_VAR | IS_TMP_VAR ) ) ;
2014-03-26 22:07:31 +08:00
goto exit ;
2002-02-07 22:08:43 +08:00
}
}
2014-02-10 14:04:30 +08:00
}
2014-03-26 22:07:31 +08:00
/* magic set */
2014-02-10 14:04:30 +08:00
if ( zobj - > ce - > __set ) {
2014-10-17 23:10:05 +08:00
zend_long * guard = zend_get_property_guard ( zobj , Z_STR_P ( member ) ) ;
2005-11-15 21:35:23 +08:00
2014-02-10 14:04:30 +08:00
if ( ! ( ( * guard ) & IN_SET ) ) {
2014-04-16 22:06:03 +08:00
zval tmp_object ;
ZVAL_COPY ( & tmp_object , object ) ;
2014-02-10 14:04:30 +08:00
( * guard ) | = IN_SET ; /* prevent circular setting */
2014-12-14 06:06:14 +08:00
if ( zend_std_call_setter ( & tmp_object , member , value ) ! = 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
}
2014-02-10 14:04:30 +08:00
( * guard ) & = ~ IN_SET ;
2014-04-16 22:06:03 +08:00
zval_ptr_dtor ( & tmp_object ) ;
2015-01-13 16:33:00 +08:00
} else if ( EXPECTED ( property_offset ! = ZEND_WRONG_PROPERTY_OFFSET ) ) {
2014-03-07 06:03:25 +08:00
goto write_std_property ;
2014-02-10 14:04:30 +08:00
} else {
2010-10-01 17:49:20 +08:00
if ( Z_STRVAL_P ( member ) [ 0 ] = = ' \0 ' ) {
2014-08-26 01:24:55 +08:00
if ( Z_STRLEN_P ( member ) = = 0 ) {
2010-10-01 17:49:20 +08:00
zend_error ( E_ERROR , " Cannot access empty property " ) ;
} else {
zend_error ( E_ERROR , " Cannot access property started with ' \\ 0' " ) ;
}
}
2002-10-10 01:14:25 +08:00
}
2015-01-13 16:33:00 +08:00
} else if ( EXPECTED ( property_offset ! = ZEND_WRONG_PROPERTY_OFFSET ) ) {
2014-09-14 05:30:32 +08:00
zval tmp ;
2014-03-07 06:03:25 +08:00
write_std_property :
2014-03-05 17:55:56 +08:00
if ( Z_REFCOUNTED_P ( value ) ) {
2014-02-19 16:03:01 +08:00
if ( Z_ISREF_P ( value ) ) {
2014-09-14 05:30:32 +08:00
/* if we assign referenced variable, we should separate it */
2014-03-18 16:37:51 +08:00
ZVAL_DUP ( & tmp , Z_REFVAL_P ( value ) ) ;
value = & tmp ;
2014-03-05 04:28:01 +08:00
} else {
Z_ADDREF_P ( value ) ;
2014-02-19 16:03:01 +08:00
}
2014-02-10 14:04:30 +08:00
}
2015-01-13 16:33:00 +08:00
if ( EXPECTED ( property_offset ! = ZEND_DYNAMIC_PROPERTY_OFFSET ) ) {
ZVAL_COPY_VALUE ( OBJ_PROP ( zobj , property_offset ) , value ) ;
2014-02-10 14:04:30 +08:00
} else {
if ( ! zobj - > properties ) {
rebuild_object_properties ( zobj ) ;
}
2014-11-06 22:45:14 +08:00
zend_hash_add_new ( zobj - > properties , Z_STR_P ( member ) , value ) ;
2014-02-10 14:04:30 +08:00
}
2002-09-04 17:07:58 +08:00
}
2006-07-26 23:29:27 +08:00
2014-03-26 22:07:31 +08:00
exit :
2014-02-10 14:04:30 +08:00
if ( UNEXPECTED ( Z_TYPE ( tmp_member ) ! = IS_UNDEF ) ) {
2005-06-03 19:16:19 +08:00
zval_ptr_dtor ( & tmp_member ) ;
2002-02-07 22:08:43 +08:00
}
}
2007-11-03 03:40:39 +08:00
/* }}} */
2002-02-07 22:08:43 +08:00
2014-12-14 06:06:14 +08:00
zval * zend_std_read_dimension ( zval * object , zval * offset , int type , zval * rv ) /* { { { */
2003-07-07 18:53:27 +08:00
{
2003-11-25 04:57:54 +08:00
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
2014-02-27 19:40:13 +08:00
zval tmp ;
2006-05-10 07:53:23 +08:00
2014-12-14 06:06:14 +08:00
if ( EXPECTED ( instanceof_function_ex ( ce , zend_ce_arrayaccess , 1 ) ! = 0 ) ) {
2004-07-14 17:01:58 +08:00
if ( offset = = NULL ) {
/* [] construct */
2014-02-10 14:04:30 +08:00
ZVAL_UNDEF ( & tmp ) ;
offset = & tmp ;
2005-02-02 15:19:22 +08:00
} else {
SEPARATE_ARG_IF_REF ( offset ) ;
2004-07-14 17:01:58 +08:00
}
2014-02-27 19:40:13 +08:00
zend_call_method_with_1_params ( object , ce , NULL , " offsetget " , rv , offset ) ;
2004-07-14 17:04:13 +08:00
2014-02-10 14:04:30 +08:00
zval_ptr_dtor ( offset ) ;
2005-02-02 15:19:22 +08:00
2014-02-27 19:40:13 +08:00
if ( UNEXPECTED ( Z_TYPE_P ( rv ) = = IS_UNDEF ) ) {
2010-05-06 20:52:27 +08:00
if ( UNEXPECTED ( ! EG ( exception ) ) ) {
2014-02-10 14:04:30 +08:00
zend_error_noreturn ( E_ERROR , " Undefined offset for object of type %s used as array " , ce - > name - > val ) ;
2003-12-11 17:56:06 +08:00
}
2014-02-10 14:04:30 +08:00
return NULL ;
2003-12-11 17:56:06 +08:00
}
2014-02-27 19:40:13 +08:00
return rv ;
2003-11-25 04:57:54 +08:00
} else {
2014-02-10 14:04:30 +08:00
zend_error_noreturn ( E_ERROR , " Cannot use object of type %s as array " , ce - > name - > val ) ;
return NULL ;
2003-11-25 04:57:54 +08:00
}
2003-07-07 18:53:27 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-07-07 18:53:27 +08:00
2014-12-14 06:06:14 +08:00
static void zend_std_write_dimension ( zval * object , zval * offset , zval * value ) /* { { { */
2003-07-07 17:00:36 +08:00
{
2003-11-25 04:57:54 +08:00
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
2014-02-10 14:04:30 +08:00
zval tmp ;
2005-02-02 15:19:22 +08:00
2014-12-14 06:06:14 +08:00
if ( EXPECTED ( instanceof_function_ex ( ce , zend_ce_arrayaccess , 1 ) ! = 0 ) ) {
2003-12-23 00:27:14 +08:00
if ( ! offset ) {
2014-03-04 20:07:42 +08:00
ZVAL_NULL ( & tmp ) ;
2014-02-10 14:04:30 +08:00
offset = & tmp ;
2005-02-02 15:19:22 +08:00
} else {
SEPARATE_ARG_IF_REF ( offset ) ;
2003-12-23 00:27:14 +08:00
}
2014-02-10 14:04:30 +08:00
zend_call_method_with_2_params ( object , ce , NULL , " offsetset " , NULL , offset , value ) ;
zval_ptr_dtor ( offset ) ;
2003-11-25 04:57:54 +08:00
} else {
2014-02-10 14:04:30 +08:00
zend_error_noreturn ( E_ERROR , " Cannot use object of type %s as array " , ce - > name - > val ) ;
2003-11-25 04:57:54 +08:00
}
2003-07-07 17:00:36 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-07-07 17:00:36 +08:00
2014-12-14 06:06:14 +08:00
static int zend_std_has_dimension ( zval * object , zval * offset , int check_empty ) /* { { { */
2003-11-11 00:14:44 +08:00
{
2003-11-25 04:57:54 +08:00
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
2014-02-10 14:04:30 +08:00
zval retval ;
2003-11-25 04:57:54 +08:00
int result ;
2006-05-10 07:53:23 +08:00
2014-12-14 06:06:14 +08:00
if ( EXPECTED ( instanceof_function_ex ( ce , zend_ce_arrayaccess , 1 ) ! = 0 ) ) {
2005-02-02 15:19:22 +08:00
SEPARATE_ARG_IF_REF ( offset ) ;
2014-02-10 14:04:30 +08:00
zend_call_method_with_1_params ( object , ce , NULL , " offsetexists " , & retval , offset ) ;
if ( EXPECTED ( Z_TYPE ( retval ) ! = IS_UNDEF ) ) {
2014-12-14 06:06:14 +08:00
result = i_zend_is_true ( & retval ) ;
2005-03-19 23:32:18 +08:00
zval_ptr_dtor ( & retval ) ;
2010-05-06 20:52:27 +08:00
if ( check_empty & & result & & EXPECTED ( ! EG ( exception ) ) ) {
2014-02-10 14:04:30 +08:00
zend_call_method_with_1_params ( object , ce , NULL , " offsetget " , & retval , offset ) ;
if ( EXPECTED ( Z_TYPE ( retval ) ! = IS_UNDEF ) ) {
2014-12-14 06:06:14 +08:00
result = i_zend_is_true ( & retval ) ;
2005-07-08 00:07:09 +08:00
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
}
2014-02-10 14:04:30 +08:00
zval_ptr_dtor ( offset ) ;
2003-11-25 04:57:54 +08:00
} else {
2014-02-10 14:04:30 +08:00
zend_error_noreturn ( E_ERROR , " Cannot use object of type %s as array " , ce - > name - > val ) ;
2003-11-25 04:57:54 +08:00
return 0 ;
}
2005-07-08 00:07:09 +08:00
return result ;
2003-11-11 00:14:44 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-11-11 00:14:44 +08:00
2014-12-14 06:06:14 +08:00
static zval * zend_std_get_property_ptr_ptr ( zval * object , zval * member , int type , void * * cache_slot ) /* { { { */
2002-02-07 22:08:43 +08:00
{
zend_object * zobj ;
2014-10-17 23:10:05 +08:00
zend_string * name ;
zval * retval = NULL ;
2015-01-13 16:33:00 +08:00
uint32_t property_offset ;
2006-05-10 07:53:23 +08:00
2002-04-22 22:22:27 +08:00
zobj = Z_OBJ_P ( object ) ;
2014-10-17 23:10:05 +08:00
if ( EXPECTED ( Z_TYPE_P ( member ) = = IS_STRING ) ) {
name = Z_STR_P ( member ) ;
} else {
name = zval_get_string ( member ) ;
2002-02-07 22:08:43 +08:00
}
# if DEBUG_OBJECT_HANDLERS
2014-10-17 23:10:05 +08:00
fprintf ( stderr , " Ptr object #%d property: %s \n " , Z_OBJ_HANDLE_P ( object ) , name - > val ) ;
2006-05-10 07:53:23 +08:00
# endif
2002-02-07 22:08:43 +08:00
2015-01-13 16:33:00 +08:00
property_offset = zend_get_property_offset ( zobj - > ce , name , ( zobj - > ce - > __get ! = NULL ) , cache_slot ) ;
2003-02-05 17:41:31 +08:00
2015-01-13 16:33:00 +08:00
if ( EXPECTED ( property_offset ! = ZEND_WRONG_PROPERTY_OFFSET ) ) {
if ( EXPECTED ( property_offset ! = ZEND_DYNAMIC_PROPERTY_OFFSET ) ) {
retval = OBJ_PROP ( zobj , property_offset ) ;
2014-10-17 23:10:05 +08:00
if ( UNEXPECTED ( Z_TYPE_P ( retval ) = = IS_UNDEF ) ) {
if ( EXPECTED ( ! zobj - > ce - > __get ) | |
UNEXPECTED ( ( * zend_get_property_guard ( zobj , name ) ) & IN_GET ) ) {
ZVAL_NULL ( retval ) ;
/* Notice is thrown after creation of the property, to avoid EG(std_property_info)
* being overwritten in an error handler . */
if ( UNEXPECTED ( type = = BP_VAR_RW | | type = = BP_VAR_R ) ) {
zend_error ( E_NOTICE , " Undefined property: %s::$%s " , zobj - > ce - > name - > val , name - > val ) ;
}
} else {
/* we do have getter - fail and let it try again with usual get/set */
retval = NULL ;
}
}
2002-09-04 17:07:58 +08:00
} else {
2014-10-17 23:10:05 +08:00
if ( UNEXPECTED ( ! zobj - > properties ) | |
UNEXPECTED ( ( retval = zend_hash_find ( zobj - > properties , name ) ) = = NULL ) ) {
if ( EXPECTED ( ! zobj - > ce - > __get ) | |
UNEXPECTED ( ( * zend_get_property_guard ( zobj , name ) ) & IN_GET ) ) {
if ( UNEXPECTED ( ! zobj - > properties ) ) {
rebuild_object_properties ( zobj ) ;
}
retval = zend_hash_update ( zobj - > properties , name , & EG ( uninitialized_zval ) ) ;
/* Notice is thrown after creation of the property, to avoid EG(std_property_info)
* being overwritten in an error handler . */
if ( UNEXPECTED ( type = = BP_VAR_RW | | type = = BP_VAR_R ) ) {
zend_error ( E_NOTICE , " Undefined property: %s::$%s " , zobj - > ce - > name - > val , name - > val ) ;
}
}
2014-02-10 14:04:30 +08:00
}
2002-09-04 17:07:58 +08:00
}
2002-02-07 22:08:43 +08:00
}
2014-02-10 14:04:30 +08:00
2014-10-17 23:10:05 +08:00
if ( UNEXPECTED ( Z_TYPE_P ( member ) ! = IS_STRING ) ) {
zend_string_release ( name ) ;
2002-02-07 22:08:43 +08:00
}
return retval ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2002-02-07 22:08:43 +08:00
2014-12-14 06:06:14 +08:00
static void zend_std_unset_property ( zval * object , zval * member , void * * cache_slot ) /* { { { */
2002-02-07 22:08:43 +08:00
{
zend_object * zobj ;
2014-02-10 14:04:30 +08:00
zval tmp_member ;
2015-01-13 16:33:00 +08:00
uint32_t property_offset ;
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
2014-02-10 14:04:30 +08:00
ZVAL_UNDEF ( & tmp_member ) ;
2010-05-06 20:52:27 +08:00
if ( UNEXPECTED ( Z_TYPE_P ( member ) ! = IS_STRING ) ) {
2014-10-07 00:45:08 +08:00
ZVAL_STR ( & tmp_member , zval_get_string ( member ) ) ;
2014-02-10 14:04:30 +08:00
member = & tmp_member ;
2014-07-08 00:54:31 +08:00
cache_slot = NULL ;
2002-02-07 22:08:43 +08:00
}
2003-02-05 22:27:30 +08:00
2015-01-13 16:33:00 +08:00
property_offset = zend_get_property_offset ( zobj - > ce , Z_STR_P ( member ) , ( zobj - > ce - > __unset ! = NULL ) , cache_slot ) ;
2006-05-10 07:53:23 +08:00
2015-01-13 16:33:00 +08:00
if ( EXPECTED ( property_offset ! = ZEND_WRONG_PROPERTY_OFFSET ) ) {
if ( EXPECTED ( property_offset ! = ZEND_DYNAMIC_PROPERTY_OFFSET ) ) {
zval * slot = OBJ_PROP ( zobj , property_offset ) ;
2014-10-17 23:10:05 +08:00
2014-11-06 19:50:03 +08:00
if ( Z_TYPE_P ( slot ) ! = IS_UNDEF ) {
zval_ptr_dtor ( slot ) ;
ZVAL_UNDEF ( slot ) ;
2014-03-26 22:07:31 +08:00
goto exit ;
}
2014-10-21 00:33:35 +08:00
} else if ( EXPECTED ( zobj - > properties ! = NULL ) & &
2014-10-17 23:10:05 +08:00
EXPECTED ( zend_hash_del ( zobj - > properties , Z_STR_P ( member ) ) ! = FAILURE ) ) {
2014-03-26 22:07:31 +08:00
goto exit ;
}
2014-02-10 14:04:30 +08:00
}
2015-01-03 17:22:58 +08:00
2014-03-26 22:07:31 +08:00
/* magic unset */
if ( zobj - > ce - > __unset ) {
2014-10-17 23:10:05 +08:00
zend_long * guard = zend_get_property_guard ( zobj , Z_STR_P ( member ) ) ;
2014-03-26 22:07:31 +08:00
if ( ! ( ( * guard ) & IN_UNSET ) ) {
2014-04-16 22:06:03 +08:00
zval tmp_object ;
2014-03-26 22:07:31 +08:00
/* have unseter - try with it! */
2014-04-16 22:06:03 +08:00
ZVAL_COPY ( & tmp_object , object ) ;
2014-03-26 22:07:31 +08:00
( * guard ) | = IN_UNSET ; /* prevent circular unsetting */
2014-12-14 06:06:14 +08:00
zend_std_call_unsetter ( & tmp_object , member ) ;
2014-03-26 22:07:31 +08:00
( * guard ) & = ~ IN_UNSET ;
2014-04-16 22:06:03 +08:00
zval_ptr_dtor ( & tmp_object ) ;
2014-03-26 22:07:31 +08:00
} else {
if ( Z_STRVAL_P ( member ) [ 0 ] = = ' \0 ' ) {
2014-08-26 01:24:55 +08:00
if ( Z_STRLEN_P ( member ) = = 0 ) {
2014-03-26 22:07:31 +08:00
zend_error ( E_ERROR , " Cannot access empty property " ) ;
} else {
zend_error ( E_ERROR , " Cannot access property started with ' \\ 0' " ) ;
2010-08-01 21:27:02 +08:00
}
}
2005-07-08 00:07:09 +08:00
}
}
2014-02-10 14:04:30 +08:00
exit :
if ( UNEXPECTED ( Z_TYPE ( tmp_member ) ! = IS_NULL ) ) {
2005-07-08 00:07:09 +08:00
zval_ptr_dtor ( & tmp_member ) ;
2002-02-07 22:08:43 +08:00
}
}
2007-11-03 03:40:39 +08:00
/* }}} */
2002-02-07 22:08:43 +08:00
2014-12-14 06:06:14 +08:00
static void zend_std_unset_dimension ( zval * object , zval * offset ) /* { { { */
2003-07-31 01:12:06 +08:00
{
2003-11-25 04:57:54 +08:00
zend_class_entry * ce = Z_OBJCE_P ( object ) ;
2006-05-10 07:53:23 +08:00
2014-12-14 06:06:14 +08:00
if ( instanceof_function_ex ( ce , zend_ce_arrayaccess , 1 ) ) {
2005-02-02 15:19:22 +08:00
SEPARATE_ARG_IF_REF ( offset ) ;
2014-02-10 14:04:30 +08:00
zend_call_method_with_1_params ( object , ce , NULL , " offsetunset " , NULL , offset ) ;
zval_ptr_dtor ( offset ) ;
2003-11-25 04:57:54 +08:00
} else {
2014-02-10 14:04:30 +08:00
zend_error_noreturn ( E_ERROR , " Cannot use object of type %s as array " , ce - > name - > val ) ;
2003-11-25 04:57:54 +08:00
}
2003-07-31 01:12:06 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-07-31 01:12:06 +08:00
2007-11-03 03:40:39 +08:00
ZEND_API void zend_std_call_user_call ( INTERNAL_FUNCTION_PARAMETERS ) /* { { { */
2002-09-04 17:07:58 +08:00
{
2014-10-03 23:32:46 +08:00
zend_internal_function * func = ( zend_internal_function * ) EX ( func ) ;
2014-02-10 14:04:30 +08:00
zval method_name , method_args ;
zval method_result ;
2014-03-28 06:11:22 +08:00
zend_class_entry * ce = Z_OBJCE_P ( getThis ( ) ) ;
2006-05-10 07:53:23 +08:00
2014-02-10 14:04:30 +08:00
array_init_size ( & method_args , ZEND_NUM_ARGS ( ) ) ;
2002-09-04 17:07:58 +08:00
2014-12-14 06:06:14 +08:00
if ( UNEXPECTED ( zend_copy_parameters_array ( ZEND_NUM_ARGS ( ) , & method_args ) = = FAILURE ) ) {
2014-02-10 14:04:30 +08:00
zval_dtor ( & method_args ) ;
2010-05-06 20:52:27 +08:00
zend_error_noreturn ( E_ERROR , " Cannot get arguments for __call " ) ;
2002-09-04 17:07:58 +08:00
RETURN_FALSE ;
}
2014-02-10 14:04:30 +08:00
ZVAL_STR ( & method_name , func - > function_name ) ; /* no dup - it's a copy */
2002-09-04 17:07:58 +08:00
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
*/
2014-03-28 06:11:22 +08:00
zend_call_method_with_2_params ( getThis ( ) , ce , & ce - > __call , ZEND_CALL_FUNC_NAME , & method_result , & method_name , & method_args ) ;
2004-09-29 06:55:22 +08:00
2014-02-10 14:04:30 +08:00
if ( Z_TYPE ( method_result ) ! = IS_UNDEF ) {
RETVAL_ZVAL_FAST ( & method_result ) ;
zval_ptr_dtor ( & method_result ) ;
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 */
2014-02-10 14:04:30 +08:00
zval_ptr_dtor ( & method_args ) ;
zval_ptr_dtor ( & method_name ) ;
2002-09-04 17:07:58 +08:00
/* destruct the function also, then - we have allocated it in get_method */
2014-08-28 00:49:56 +08:00
efree_size ( func , sizeof ( zend_internal_function ) ) ;
2002-09-04 17:07:58 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2002-09-04 17:07:58 +08:00
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 .
*/
2014-12-14 06:06:14 +08:00
static inline zend_function * zend_check_private_int ( zend_function * fbc , zend_class_entry * ce , zend_string * function_name ) /* { { { */
2003-02-03 00:17:25 +08:00
{
2014-02-10 14:04:30 +08:00
zval * func ;
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 ) ) {
2014-02-10 14:04:30 +08:00
if ( ( func = zend_hash_find ( & ce - > function_table , function_name ) ) ) {
fbc = Z_FUNC_P ( func ) ;
if ( fbc - > common . fn_flags & ZEND_ACC_PRIVATE
& & fbc - > common . scope = = EG ( scope ) ) {
return fbc ;
}
2003-02-03 00:17:25 +08:00
}
break ;
}
ce = ce - > parent ;
}
return NULL ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-02-03 00:17:25 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_check_private ( zend_function * fbc , zend_class_entry * ce , zend_string * function_name ) /* { { { */
2005-04-27 23:45:36 +08:00
{
2014-12-14 06:06:14 +08:00
return zend_check_private_int ( fbc , ce , function_name ) ! = NULL ;
2005-04-27 23:45:36 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2005-04-27 23:45:36 +08:00
2003-02-03 00:17:25 +08:00
/* Ensures that we're allowed to call a protected method.
*/
2007-11-03 03:40:39 +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 ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-02-03 00:17:25 +08:00
2014-02-10 14:04:30 +08:00
static inline union _zend_function * zend_get_user_call_function ( zend_class_entry * ce , zend_string * method_name ) /* { { { */
2009-01-08 06:12:39 +08:00
{
zend_internal_function * call_user_call = emalloc ( sizeof ( zend_internal_function ) ) ;
call_user_call - > type = ZEND_INTERNAL_FUNCTION ;
2010-09-15 15:38:52 +08:00
call_user_call - > module = ( ce - > type = = ZEND_INTERNAL_CLASS ) ? ce - > info . internal . module : NULL ;
2009-01-08 06:12:39 +08: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 09:05:25 +08:00
call_user_call - > scope = ce ;
2009-01-08 06:12:39 +08:00
call_user_call - > fn_flags = ZEND_ACC_CALL_VIA_HANDLER ;
2014-04-12 04:50:36 +08:00
//??? keep compatibility for "\0" characters
//??? see: Zend/tests/bug46238.phpt
if ( UNEXPECTED ( strlen ( method_name - > val ) ! = method_name - > len ) ) {
2014-08-26 01:24:55 +08:00
call_user_call - > function_name = zend_string_init ( method_name - > val , strlen ( method_name - > val ) , 0 ) ;
2014-04-12 04:50:36 +08:00
} else {
2014-08-26 01:24:55 +08:00
call_user_call - > function_name = zend_string_copy ( method_name ) ;
2014-04-12 04:50:36 +08:00
}
2009-01-08 06:12:39 +08:00
return ( union _zend_function * ) call_user_call ;
}
/* }}} */
2014-12-14 06:06:14 +08:00
static union _zend_function * zend_std_get_method ( zend_object * * obj_ptr , zend_string * method_name , const zval * key ) /* { { { */
2002-02-07 22:08:43 +08:00
{
2014-03-28 06:11:22 +08:00
zend_object * zobj = * obj_ptr ;
2014-02-10 14:04:30 +08:00
zval * func ;
2003-02-03 00:17:25 +08:00
zend_function * fbc ;
2014-02-10 14:04:30 +08:00
zend_string * lc_method_name ;
2014-05-02 23:01:36 +08:00
ALLOCA_FLAG ( use_heap ) ;
2007-10-11 09:03:19 +08:00
2010-05-06 20:52:27 +08:00
if ( EXPECTED ( key ! = NULL ) ) {
2014-04-17 19:40:45 +08:00
lc_method_name = Z_STR_P ( key ) ;
2015-01-16 02:43:17 +08:00
# ifdef ZEND_ALLOCA_MAX_SIZE
2015-01-16 02:08:21 +08:00
use_heap = 0 ;
2015-01-16 02:43:17 +08:00
# endif
2010-04-20 18:57:45 +08:00
} else {
2014-05-02 23:01:36 +08:00
STR_ALLOCA_ALLOC ( lc_method_name , method_name - > len , use_heap ) ;
2014-02-10 14:04:30 +08:00
zend_str_tolower_copy ( lc_method_name - > val , method_name - > val , method_name - > len ) ;
2010-04-20 18:57:45 +08:00
}
2007-10-11 09:03:19 +08:00
2014-02-10 14:04:30 +08:00
if ( UNEXPECTED ( ( func = zend_hash_find ( & zobj - > ce - > function_table , lc_method_name ) ) = = NULL ) ) {
2015-01-16 07:21:27 +08:00
if ( UNEXPECTED ( ! key ) ) {
STR_ALLOCA_FREE ( lc_method_name , use_heap ) ;
}
2003-01-29 23:02:57 +08:00
if ( zobj - > ce - > __call ) {
2014-02-10 14:04:30 +08:00
return zend_get_user_call_function ( zobj - > ce , method_name ) ;
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
2014-02-10 14:04:30 +08:00
fbc = Z_FUNC_P ( func ) ;
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.
2009-01-08 06:12:39 +08:00
* If we ' re not and __call ( ) handler exists , invoke it , otherwise error out .
2006-09-12 19:01:16 +08:00
*/
2014-12-14 06:06:14 +08:00
updated_fbc = zend_check_private_int ( fbc , zobj - > ce , lc_method_name ) ;
2010-05-06 20:52:27 +08:00
if ( EXPECTED ( updated_fbc ! = NULL ) ) {
2009-01-08 06:12:39 +08:00
fbc = updated_fbc ;
} else {
if ( zobj - > ce - > __call ) {
2014-02-10 14:04:30 +08:00
fbc = zend_get_user_call_function ( zobj - > ce , method_name ) ;
2009-01-08 06:12:39 +08:00
} else {
2014-02-10 14:04:30 +08: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 - > val , EG ( scope ) ? EG ( scope ) - > name - > val : " " ) ;
2009-01-08 06:12:39 +08:00
}
2006-09-12 19:01:16 +08:00
}
} 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 ) {
2014-05-18 17:28:06 +08:00
if ( ( func = zend_hash_find ( & EG ( scope ) - > function_table , lc_method_name ) ) ! = NULL ) {
2014-02-10 14:04:30 +08:00
zend_function * priv_fbc = Z_FUNC_P ( func ) ;
if ( priv_fbc - > common . fn_flags & ZEND_ACC_PRIVATE
& & priv_fbc - > common . scope = = EG ( scope ) ) {
fbc = priv_fbc ;
}
2003-02-03 00:17:25 +08:00
}
}
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.
2009-01-08 06:12:39 +08:00
* If we ' re not and __call ( ) handler exists , invoke it , otherwise error out .
2006-09-12 19:01:16 +08:00
*/
2010-05-06 20:52:27 +08:00
if ( UNEXPECTED ( ! zend_check_protected ( zend_get_function_root_class ( fbc ) , EG ( scope ) ) ) ) {
2009-01-08 06:12:39 +08:00
if ( zobj - > ce - > __call ) {
2014-02-10 14:04:30 +08:00
fbc = zend_get_user_call_function ( zobj - > ce , method_name ) ;
2009-01-08 06:12:39 +08:00
} else {
2014-02-10 14:04:30 +08: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 - > val , EG ( scope ) ? EG ( scope ) - > name - > val : " " ) ;
2009-01-08 06:12:39 +08:00
}
2006-09-12 19:01:16 +08:00
}
2003-02-03 00:17:25 +08:00
}
}
2015-01-16 07:21:27 +08:00
if ( UNEXPECTED ( ! key ) ) {
STR_ALLOCA_FREE ( lc_method_name , use_heap ) ;
}
2003-02-03 00:17:25 +08:00
return fbc ;
2002-02-07 22:08:43 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
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 ) /* { { { */
{
2014-10-03 23:32:46 +08:00
zend_internal_function * func = ( zend_internal_function * ) EX ( func ) ;
2014-02-10 14:04:30 +08:00
zval method_name , method_args ;
zval method_result ;
2007-09-29 16:52:40 +08:00
zend_class_entry * ce = EG ( scope ) ;
2007-10-11 09:03:19 +08:00
2014-02-10 14:04:30 +08:00
array_init_size ( & method_args , ZEND_NUM_ARGS ( ) ) ;
2007-09-29 16:52:40 +08:00
2014-12-14 06:06:14 +08:00
if ( UNEXPECTED ( zend_copy_parameters_array ( ZEND_NUM_ARGS ( ) , & method_args ) = = FAILURE ) ) {
2014-02-10 14:04:30 +08:00
zval_dtor ( & method_args ) ;
2010-05-06 20:52:27 +08:00
zend_error_noreturn ( E_ERROR , " Cannot get arguments for " ZEND_CALLSTATIC_FUNC_NAME ) ;
2007-09-29 16:52:40 +08:00
RETURN_FALSE ;
}
2014-02-10 14:04:30 +08:00
ZVAL_STR ( & method_name , func - > function_name ) ; /* no dup - it's a copy */
2007-09-29 16:52:40 +08:00
/* __callStatic handler is called with two arguments:
method name
array of method parameters
*/
2014-02-10 14:04:30 +08:00
zend_call_method_with_2_params ( NULL , ce , & ce - > __callstatic , ZEND_CALLSTATIC_FUNC_NAME , & method_result , & method_name , & method_args ) ;
2007-09-29 16:52:40 +08:00
2014-02-10 14:04:30 +08:00
if ( Z_TYPE ( method_result ) ! = IS_UNDEF ) {
RETVAL_ZVAL_FAST ( & method_result ) ;
zval_ptr_dtor ( & method_result ) ;
2007-09-29 16:52:40 +08:00
}
/* now destruct all auxiliaries */
2014-02-10 14:04:30 +08:00
zval_ptr_dtor ( & method_args ) ;
zval_ptr_dtor ( & method_name ) ;
2007-09-29 16:52:40 +08:00
/* destruct the function also, then - we have allocated it in get_method */
2014-08-28 00:49:56 +08:00
efree_size ( func , sizeof ( zend_internal_function ) ) ;
2007-09-29 16:52:40 +08:00
}
/* }}} */
2003-02-03 00:17:25 +08:00
2014-02-10 14:04:30 +08:00
static inline union _zend_function * zend_get_user_callstatic_function ( zend_class_entry * ce , zend_string * method_name ) /* { { { */
2009-06-12 09:05:25 +08:00
{
zend_internal_function * callstatic_user_call = emalloc ( sizeof ( zend_internal_function ) ) ;
callstatic_user_call - > type = ZEND_INTERNAL_FUNCTION ;
2010-09-15 15:38:52 +08:00
callstatic_user_call - > module = ( ce - > type = = ZEND_INTERNAL_CLASS ) ? ce - > info . internal . module : NULL ;
2009-06-12 09:05:25 +08: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 ;
2014-04-12 04:50:36 +08:00
//??? keep compatibility for "\0" characters
//??? see: Zend/tests/bug46238.phpt
if ( UNEXPECTED ( strlen ( method_name - > val ) ! = method_name - > len ) ) {
2014-08-26 01:24:55 +08:00
callstatic_user_call - > function_name = zend_string_init ( method_name - > val , strlen ( method_name - > val ) , 0 ) ;
2014-04-12 04:50:36 +08:00
} else {
2014-08-26 01:24:55 +08:00
callstatic_user_call - > function_name = zend_string_copy ( method_name ) ;
2014-04-12 04:50:36 +08:00
}
2009-06-12 09:05:25 +08:00
return ( zend_function * ) callstatic_user_call ;
}
/* }}} */
2003-02-03 00:17:25 +08:00
/* This is not (yet?) in the API, but it belongs in the built-in objects callbacks */
2007-11-03 03:40:39 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API zend_function * zend_std_get_static_method ( zend_class_entry * ce , zend_string * function_name , const zval * key ) /* { { { */
2003-02-03 00:17:25 +08:00
{
2008-03-17 22:54:42 +08:00
zend_function * fbc = NULL ;
2014-02-10 14:04:30 +08:00
char * lc_class_name ;
zend_string * lc_function_name ;
2003-02-03 00:17:25 +08:00
2010-05-06 20:52:27 +08:00
if ( EXPECTED ( key ! = NULL ) ) {
2014-04-17 19:40:45 +08:00
lc_function_name = Z_STR_P ( key ) ;
2010-04-20 18:57:45 +08:00
} else {
2014-12-24 20:04:51 +08:00
lc_function_name = zend_string_tolower ( function_name ) ;
2010-04-20 18:57:45 +08:00
}
2012-05-13 13:12:48 +08:00
2014-02-10 14:04:30 +08:00
if ( function_name - > len = = ce - > name - > len & & ce - > constructor ) {
lc_class_name = zend_str_tolower_dup ( ce - > name - > val , ce - > name - > len ) ;
2009-06-19 11:29:47 +08: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
*/
2014-02-10 14:04:30 +08:00
if ( ! memcmp ( lc_class_name , lc_function_name - > val , function_name - > len ) & & memcmp ( ce - > constructor - > common . function_name - > val , " __ " , sizeof ( " __ " ) - 1 ) ) {
2008-03-17 22:54:42 +08:00
fbc = ce - > constructor ;
}
efree ( lc_class_name ) ;
}
2008-06-04 02:11:12 +08:00
2014-02-10 14:04:30 +08:00
if ( EXPECTED ( ! fbc ) ) {
zval * func = zend_hash_find ( & ce - > function_table , lc_function_name ) ;
if ( EXPECTED ( func ! = NULL ) ) {
fbc = Z_FUNC_P ( func ) ;
2007-09-29 16:52:40 +08:00
} else {
2014-02-10 14:04:30 +08:00
if ( UNEXPECTED ( ! key ) ) {
2014-12-24 20:04:51 +08:00
zend_string_release ( lc_function_name ) ;
2014-02-10 14:04:30 +08:00
}
if ( ce - > __call & &
2014-10-03 23:32:46 +08:00
Z_OBJ ( EG ( current_execute_data ) - > This ) & &
2014-12-14 06:06:14 +08:00
instanceof_function ( Z_OBJCE ( EG ( current_execute_data ) - > This ) , ce ) ) {
2014-02-10 14:04:30 +08:00
return zend_get_user_call_function ( ce , function_name ) ;
} else if ( ce - > __callstatic ) {
return zend_get_user_callstatic_function ( ce , function_name ) ;
} else {
return NULL ;
}
2003-03-12 07:19:45 +08:00
}
2003-02-03 00:17:25 +08:00
}
2007-11-03 03:40:39 +08:00
# if MBO_0
/* right now this function is used for non static method lookup too */
/* Is the function static */
2010-05-06 20:52:27 +08:00
if ( UNEXPECTED ( ! ( fbc - > common . fn_flags & ZEND_ACC_STATIC ) ) ) {
2014-02-24 17:19:32 +08:00
zend_error_noreturn ( E_ERROR , " Cannot call non static method %s::%s() without object " , ZEND_FN_SCOPE_NAME ( fbc ) , fbc - > common . function_name - > val ) ;
2007-11-03 03:40:39 +08:00
}
2012-05-13 13:12:48 +08:00
# endif
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.
*/
2014-12-14 06:06:14 +08:00
updated_fbc = zend_check_private_int ( fbc , EG ( scope ) , lc_function_name ) ;
2010-05-06 20:52:27 +08:00
if ( EXPECTED ( updated_fbc ! = NULL ) ) {
2009-06-12 09:05:25 +08:00
fbc = updated_fbc ;
} else {
if ( ce - > __callstatic ) {
2014-02-10 14:04:30 +08:00
fbc = zend_get_user_callstatic_function ( ce , function_name ) ;
2010-04-20 18:57:45 +08:00
} else {
2014-02-10 14:04:30 +08: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 - > val , EG ( scope ) ? EG ( scope ) - > name - > val : " " ) ;
2009-06-12 09:05:25 +08:00
}
2003-02-03 00:17:25 +08: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 20:52:27 +08:00
if ( UNEXPECTED ( ! zend_check_protected ( zend_get_function_root_class ( fbc ) , EG ( scope ) ) ) ) {
2009-06-12 09:05:25 +08:00
if ( ce - > __callstatic ) {
2014-02-10 14:04:30 +08:00
fbc = zend_get_user_callstatic_function ( ce , function_name ) ;
2010-04-20 18:57:45 +08:00
} else {
2014-02-10 14:04:30 +08: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 - > val , EG ( scope ) ? EG ( scope ) - > name - > val : " " ) ;
2009-06-12 09:05:25 +08:00
}
2003-02-03 00:17:25 +08:00
}
}
2010-05-06 20:52:27 +08:00
if ( UNEXPECTED ( ! key ) ) {
2014-12-24 20:04:51 +08:00
zend_string_release ( lc_function_name ) ;
2010-04-20 18:57:45 +08:00
}
2003-02-03 00:17:25 +08:00
return fbc ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-02-03 00:17:25 +08:00
2015-01-13 14:33:15 +08:00
ZEND_API zval * zend_std_get_static_property ( zend_class_entry * ce , zend_string * property_name , zend_bool silent ) /* { { { */
2003-02-05 21:35:52 +08:00
{
2015-01-13 14:33:15 +08:00
zend_property_info * property_info = zend_hash_find_ptr ( & ce - > properties_info , property_name ) ;
2015-01-13 08:32:51 +08:00
zval * ret ;
2012-05-13 13:12:48 +08:00
2015-01-13 14:33:15 +08:00
if ( UNEXPECTED ( property_info = = NULL ) ) {
goto undeclared_property ;
}
2003-02-05 21:35:52 +08:00
2015-01-13 14:33:15 +08:00
if ( UNEXPECTED ( ! zend_verify_property_access ( property_info , ce ) ) ) {
if ( ! silent ) {
zend_error_noreturn ( E_ERROR , " Cannot access %s property %s::$%s " , zend_visibility_string ( property_info - > flags ) , ce - > name - > val , property_name - > val ) ;
2010-05-24 22:11:39 +08:00
}
2015-01-13 14:33:15 +08:00
return NULL ;
}
2005-09-01 18:05:32 +08:00
2015-01-13 14:33:15 +08:00
if ( UNEXPECTED ( ( property_info - > flags & ZEND_ACC_STATIC ) = = 0 ) ) {
goto undeclared_property ;
}
2003-02-05 21:35:52 +08:00
2015-01-13 14:33:15 +08:00
zend_update_class_constants ( ce ) ;
ret = CE_STATIC_MEMBERS ( ce ) + property_info - > offset ;
2006-05-10 07:53:23 +08:00
2015-01-13 14:33:15 +08:00
/* check if static properties were destoyed */
if ( UNEXPECTED ( CE_STATIC_MEMBERS ( ce ) = = NULL ) ) {
2015-01-13 08:32:51 +08:00
undeclared_property :
2015-01-13 14:33:15 +08:00
if ( ! silent ) {
zend_error_noreturn ( E_ERROR , " Access to undeclared static property: %s::$%s " , ce - > name - > val , property_name - > val ) ;
2013-05-21 13:58:11 +08:00
}
2015-01-13 14:33:15 +08:00
ret = NULL ;
2013-05-21 13:58:11 +08:00
}
2015-01-03 17:22:58 +08:00
2015-01-13 08:32:51 +08:00
return ret ;
2003-02-05 21:35:52 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-02-05 21:35:52 +08:00
2015-01-13 14:33:15 +08:00
ZEND_API zend_bool zend_std_unset_static_property ( zend_class_entry * ce , zend_string * property_name ) /* { { { */
2003-02-17 22:06:39 +08:00
{
2014-02-10 14:04:30 +08:00
zend_error_noreturn ( E_ERROR , " Attempt to unset static property %s::$%s " , ce - > name - > val , property_name - > val ) ;
2003-02-17 22:06:39 +08:00
return 0 ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-02-17 22:06:39 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API union _zend_function * zend_std_get_constructor ( zend_object * zobj ) /* { { { */
2002-02-07 22:08:43 +08:00
{
2003-02-03 00:17:25 +08:00
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 20:52:27 +08:00
if ( UNEXPECTED ( constructor - > common . scope ! = EG ( scope ) ) ) {
2006-07-05 19:39:00 +08:00
if ( EG ( scope ) ) {
2014-02-22 04:41:06 +08:00
zend_error_noreturn ( E_ERROR , " Call to private %s::%s() from context '%s' " , constructor - > common . scope - > name - > val , constructor - > common . function_name - > val , EG ( scope ) - > name - > val ) ;
2006-07-05 19:39:00 +08:00
} else {
2014-02-22 04:41:06 +08:00
zend_error_noreturn ( E_ERROR , " Call to private %s::%s() from invalid context " , constructor - > common . scope - > name - > val , constructor - > common . function_name - > val ) ;
2006-07-05 19:39:00 +08:00
}
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.
2007-11-03 03:40:39 +08: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-03 00:17:25 +08:00
*/
2010-05-06 20:52:27 +08:00
if ( UNEXPECTED ( ! zend_check_protected ( zend_get_function_root_class ( constructor ) , EG ( scope ) ) ) ) {
2006-07-05 19:39:00 +08:00
if ( EG ( scope ) ) {
2014-02-22 04:41:06 +08:00
zend_error_noreturn ( E_ERROR , " Call to protected %s::%s() from context '%s' " , constructor - > common . scope - > name - > val , constructor - > common . function_name - > val , EG ( scope ) - > name - > val ) ;
2006-07-05 19:39:00 +08:00
} else {
2014-02-22 04:41:06 +08:00
zend_error_noreturn ( E_ERROR , " Call to protected %s::%s() from invalid context " , constructor - > common . scope - > name - > val , constructor - > common . function_name - > val ) ;
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
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-02-05 22:27:30 +08:00
2014-12-14 06:06:14 +08:00
static int zend_std_compare_objects ( zval * o1 , zval * o2 ) /* { { { */
2002-02-07 22:08:43 +08:00
{
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 */
}
2010-05-24 22:11:39 +08:00
if ( ! zobj1 - > properties & & ! zobj2 - > properties ) {
int i ;
2013-01-09 15:30:50 +08:00
2014-02-12 22:08:11 +08:00
Z_OBJ_PROTECT_RECURSION ( o1 ) ;
Z_OBJ_PROTECT_RECURSION ( o2 ) ;
2010-05-24 22:11:39 +08:00
for ( i = 0 ; i < zobj1 - > ce - > default_properties_count ; i + + ) {
2014-02-10 14:04:30 +08:00
if ( Z_TYPE ( zobj1 - > properties_table [ i ] ) ! = IS_UNDEF ) {
if ( Z_TYPE ( zobj2 - > properties_table [ i ] ) ! = IS_UNDEF ) {
2010-05-24 22:11:39 +08:00
zval result ;
2014-02-22 02:59:51 +08:00
zval * p1 = & zobj1 - > properties_table [ i ] ;
zval * p2 = & zobj2 - > properties_table [ i ] ;
2010-05-24 22:11:39 +08:00
2014-12-14 06:06:14 +08:00
if ( compare_function ( & result , p1 , p2 ) = = FAILURE ) {
2014-02-12 22:08:11 +08:00
Z_OBJ_UNPROTECT_RECURSION ( o1 ) ;
Z_OBJ_UNPROTECT_RECURSION ( o2 ) ;
2010-05-24 22:11:39 +08:00
return 1 ;
}
2014-08-26 01:24:55 +08:00
if ( Z_LVAL ( result ) ! = 0 ) {
2014-02-12 22:08:11 +08:00
Z_OBJ_UNPROTECT_RECURSION ( o1 ) ;
Z_OBJ_UNPROTECT_RECURSION ( o2 ) ;
2014-08-26 01:24:55 +08:00
return Z_LVAL ( result ) ;
2010-05-24 22:11:39 +08:00
}
} else {
2014-02-12 22:08:11 +08:00
Z_OBJ_UNPROTECT_RECURSION ( o1 ) ;
Z_OBJ_UNPROTECT_RECURSION ( o2 ) ;
2010-05-24 22:11:39 +08:00
return 1 ;
}
} else {
2014-02-10 14:04:30 +08:00
if ( Z_TYPE ( zobj2 - > properties_table [ i ] ) ! = IS_UNDEF ) {
2014-02-12 22:08:11 +08:00
Z_OBJ_UNPROTECT_RECURSION ( o1 ) ;
Z_OBJ_UNPROTECT_RECURSION ( o2 ) ;
2010-05-24 22:11:39 +08:00
return 1 ;
}
}
}
2014-02-12 22:08:11 +08:00
Z_OBJ_UNPROTECT_RECURSION ( o1 ) ;
Z_OBJ_UNPROTECT_RECURSION ( o2 ) ;
2010-05-24 22:11:39 +08:00
return 0 ;
} else {
if ( ! zobj1 - > properties ) {
rebuild_object_properties ( zobj1 ) ;
}
if ( ! zobj2 - > properties ) {
rebuild_object_properties ( zobj2 ) ;
}
2014-12-22 12:16:25 +08:00
return zend_compare_symbol_tables ( zobj1 - > properties , zobj2 - > properties ) ;
2010-05-24 22:11:39 +08:00
}
2002-02-07 22:08:43 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2002-02-07 22:08:43 +08:00
2014-12-14 06:06:14 +08:00
static int zend_std_has_property ( zval * object , zval * member , int has_set_exists , void * * cache_slot ) /* { { { */
2002-02-07 22:08:43 +08:00
{
zend_object * zobj ;
int result ;
2014-02-10 14:04:30 +08:00
zval * value = NULL ;
zval tmp_member ;
2015-01-13 16:33:00 +08:00
uint32_t property_offset ;
2006-05-10 07:53:23 +08:00
2003-02-05 22:27:30 +08:00
zobj = Z_OBJ_P ( object ) ;
2014-02-10 14:04:30 +08:00
ZVAL_UNDEF ( & tmp_member ) ;
2010-05-06 20:52:27 +08:00
if ( UNEXPECTED ( Z_TYPE_P ( member ) ! = IS_STRING ) ) {
2014-10-07 00:45:08 +08:00
ZVAL_STR ( & tmp_member , zval_get_string ( member ) ) ;
2014-02-10 14:04:30 +08:00
member = & tmp_member ;
2014-07-08 00:54:31 +08:00
cache_slot = NULL ;
2002-02-07 22:08:43 +08:00
}
2003-02-05 22:27:30 +08:00
2015-01-13 16:33:00 +08:00
property_offset = zend_get_property_offset ( zobj - > ce , Z_STR_P ( member ) , 1 , cache_slot ) ;
2005-07-08 00:07:09 +08:00
2015-01-13 16:33:00 +08:00
if ( EXPECTED ( property_offset ! = ZEND_WRONG_PROPERTY_OFFSET ) ) {
if ( EXPECTED ( property_offset ! = ZEND_DYNAMIC_PROPERTY_OFFSET ) ) {
value = OBJ_PROP ( zobj , property_offset ) ;
2014-03-26 22:07:31 +08:00
if ( Z_TYPE_P ( value ) ! = IS_UNDEF ) {
goto found ;
2014-02-22 02:59:51 +08:00
}
2014-10-21 00:33:35 +08:00
} else if ( EXPECTED ( zobj - > properties ! = NULL ) & &
2014-10-17 23:10:05 +08:00
( value = zend_hash_find ( zobj - > properties , Z_STR_P ( member ) ) ) ! = NULL ) {
2014-02-10 14:04:30 +08:00
found :
2014-03-26 22:07:31 +08:00
switch ( has_set_exists ) {
case 0 :
2014-08-15 01:54:57 +08:00
ZVAL_DEREF ( value ) ;
2014-03-26 22:07:31 +08:00
result = ( Z_TYPE_P ( value ) ! = IS_NULL ) ;
break ;
default :
2014-12-14 06:06:14 +08:00
result = zend_is_true ( value ) ;
2014-03-26 22:07:31 +08:00
break ;
case 2 :
result = 1 ;
break ;
2014-02-10 14:04:30 +08:00
}
2014-03-26 22:07:31 +08:00
goto exit ;
2014-02-10 14:04:30 +08:00
}
}
result = 0 ;
if ( ( has_set_exists ! = 2 ) & & zobj - > ce - > __isset ) {
2014-10-17 23:10:05 +08:00
zend_long * guard = zend_get_property_guard ( zobj , Z_STR_P ( member ) ) ;
2014-02-10 14:04:30 +08:00
if ( ! ( ( * guard ) & IN_ISSET ) ) {
zval rv ;
2014-04-16 22:06:03 +08:00
zval tmp_object ;
2003-02-05 22:27:30 +08:00
2005-07-08 00:07:09 +08:00
/* have issetter - try with it! */
2014-04-16 22:06:03 +08:00
ZVAL_COPY ( & tmp_object , object ) ;
2014-02-10 14:04:30 +08:00
( * guard ) | = IN_ISSET ; /* prevent circular getting */
2014-12-14 06:06:14 +08:00
zend_std_call_issetter ( & tmp_object , member , & rv ) ;
2014-02-10 14:04:30 +08:00
if ( Z_TYPE ( rv ) ! = IS_UNDEF ) {
2014-12-14 06:06:14 +08:00
result = zend_is_true ( & rv ) ;
2005-07-08 00:07:09 +08:00
zval_ptr_dtor ( & rv ) ;
2008-05-03 08:38:55 +08:00
if ( has_set_exists & & result ) {
2014-02-10 14:04:30 +08:00
if ( EXPECTED ( ! EG ( exception ) ) & & zobj - > ce - > __get & & ! ( ( * guard ) & IN_GET ) ) {
( * guard ) | = IN_GET ;
2014-12-14 06:06:14 +08:00
zend_std_call_getter ( & tmp_object , member , & rv ) ;
2014-02-10 14:04:30 +08:00
( * guard ) & = ~ IN_GET ;
if ( Z_TYPE ( rv ) ! = IS_UNDEF ) {
2014-12-14 06:06:14 +08:00
result = i_zend_is_true ( & rv ) ;
2008-05-03 08:38:55 +08:00
zval_ptr_dtor ( & rv ) ;
} else {
result = 0 ;
}
} else {
result = 0 ;
2005-07-08 00:07:09 +08:00
}
}
}
2014-02-10 14:04:30 +08:00
( * guard ) & = ~ IN_ISSET ;
2014-04-16 22:06:03 +08:00
zval_ptr_dtor ( & tmp_object ) ;
2002-02-07 22:08:43 +08:00
}
}
2014-02-10 14:04:30 +08:00
exit :
if ( UNEXPECTED ( Z_TYPE ( tmp_member ) ! = IS_UNDEF ) ) {
2005-07-08 00:07:09 +08:00
zval_ptr_dtor ( & tmp_member ) ;
2002-02-07 22:08:43 +08:00
}
return result ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2002-02-07 22:08:43 +08:00
2014-12-14 06:06:14 +08:00
zend_string * zend_std_object_get_class_name ( const zend_object * zobj ) /* { { { */
2003-01-12 21:56:51 +08:00
{
2014-10-10 01:15:07 +08:00
return zend_string_copy ( zobj - > ce - > name ) ;
2003-01-12 21:56:51 +08:00
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-01-12 21:56:51 +08:00
2014-12-14 06:06:14 +08:00
ZEND_API int zend_std_cast_object_tostring ( zval * readobj , zval * writeobj , int type ) /* { { { */
2003-12-16 00:59:21 +08:00
{
2014-02-10 14:04:30 +08:00
zval retval ;
2006-05-10 07:53:23 +08:00
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 & &
2014-02-10 14:04:30 +08:00
( zend_call_method_with_0_params ( readobj , ce , & ce - > __tostring , " __tostring " , & retval ) | | EG ( exception ) ) ) {
2010-05-06 20:52:27 +08:00
if ( UNEXPECTED ( EG ( exception ) ! = NULL ) ) {
2014-02-24 17:49:53 +08:00
zval_ptr_dtor ( & retval ) ;
2012-09-06 15:26:40 +08:00
EG ( exception ) = NULL ;
2014-02-10 14:04:30 +08:00
zend_error_noreturn ( E_ERROR , " Method %s::__toString() must not throw an exception " , ce - > name - > val ) ;
2007-10-19 04:44:41 +08:00
return FAILURE ;
}
2014-02-10 14:04:30 +08:00
if ( EXPECTED ( Z_TYPE ( retval ) = = IS_STRING ) ) {
2007-12-22 04:56:33 +08:00
if ( readobj = = writeobj ) {
2014-02-21 16:56:23 +08:00
zval_ptr_dtor ( readobj ) ;
2007-12-22 04:56:33 +08:00
}
2014-02-21 16:56:23 +08:00
ZVAL_COPY_VALUE ( writeobj , & retval ) ;
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 ) ;
2007-12-22 04:56:33 +08:00
if ( readobj = = writeobj ) {
2014-02-21 16:56:23 +08:00
zval_ptr_dtor ( readobj ) ;
2007-12-22 04:56:33 +08:00
}
2006-05-10 07:53:23 +08:00
ZVAL_EMPTY_STRING ( writeobj ) ;
2014-02-10 14:04:30 +08:00
zend_error ( E_RECOVERABLE_ERROR , " Method %s::__toString() must return a string value " , ce - > name - > val ) ;
2006-05-10 07:53:23 +08:00
return SUCCESS ;
2003-12-16 00:59:21 +08:00
}
}
2006-05-10 07:53:23 +08:00
return FAILURE ;
2014-04-30 22:32:42 +08:00
case _IS_BOOL :
2006-05-10 07:53:23 +08:00
ZVAL_BOOL ( writeobj , 1 ) ;
return SUCCESS ;
2014-08-26 01:24:55 +08:00
case IS_LONG :
2006-05-10 07:53:23 +08:00
ce = Z_OBJCE_P ( readobj ) ;
2014-02-10 14:04:30 +08:00
zend_error ( E_NOTICE , " Object of class %s could not be converted to int " , ce - > name - > val ) ;
2007-12-22 04:56:33 +08:00
if ( readobj = = writeobj ) {
zval_dtor ( readobj ) ;
}
2014-08-26 01:24:55 +08:00
ZVAL_LONG ( writeobj , 1 ) ;
2006-05-10 07:53:23 +08:00
return SUCCESS ;
case IS_DOUBLE :
ce = Z_OBJCE_P ( readobj ) ;
2014-12-15 02:20:23 +08:00
zend_error ( E_NOTICE , " Object of class %s could not be converted to float " , ce - > name - > val ) ;
2007-12-22 04:56:33 +08:00
if ( readobj = = writeobj ) {
zval_dtor ( readobj ) ;
}
2006-05-10 07:53:23 +08:00
ZVAL_DOUBLE ( writeobj , 1 ) ;
return SUCCESS ;
2003-12-16 00:59:21 +08:00
default :
2014-02-10 14:04:30 +08:00
ZVAL_NULL ( writeobj ) ;
2003-12-16 00:59:21 +08:00
break ;
}
return FAILURE ;
}
2007-11-03 03:40:39 +08:00
/* }}} */
2003-09-18 19:38:33 +08:00
2014-12-14 06:06:14 +08:00
int zend_std_get_closure ( zval * obj , zend_class_entry * * ce_ptr , zend_function * * fptr_ptr , zend_object * * obj_ptr ) /* { { { */
2008-08-15 05:36:56 +08:00
{
2014-02-10 14:04:30 +08:00
zval * func ;
2008-08-15 05:36:56 +08:00
zend_class_entry * ce ;
2014-02-10 14:04:30 +08:00
2008-08-15 05:36:56 +08:00
if ( Z_TYPE_P ( obj ) ! = IS_OBJECT ) {
return FAILURE ;
}
ce = Z_OBJCE_P ( obj ) ;
2014-02-10 14:04:30 +08:00
if ( ( func = zend_hash_str_find ( & ce - > function_table , ZEND_INVOKE_FUNC_NAME , sizeof ( ZEND_INVOKE_FUNC_NAME ) - 1 ) ) = = NULL ) {
2008-08-15 05:36:56 +08:00
return FAILURE ;
}
2014-02-10 14:04:30 +08:00
* fptr_ptr = Z_FUNC_P ( func ) ;
2008-08-15 05:36:56 +08:00
* ce_ptr = ce ;
if ( ( * fptr_ptr ) - > common . fn_flags & ZEND_ACC_STATIC ) {
2014-03-28 06:11:22 +08:00
if ( obj_ptr ) {
* obj_ptr = NULL ;
2008-08-15 05:36:56 +08:00
}
} else {
2014-03-28 06:11:22 +08:00
if ( obj_ptr ) {
* obj_ptr = Z_OBJ_P ( obj ) ;
2008-08-15 05:36:56 +08:00
}
}
return SUCCESS ;
}
/* }}} */
2003-12-22 21:09:15 +08:00
ZEND_API zend_object_handlers std_object_handlers = {
2014-04-09 05:50:15 +08:00
0 , /* offset */
zend_object_std_dtor , /* free_obj */
2014-02-21 19:48:56 +08:00
zend_objects_destroy_object , /* dtor_obj */
2003-07-07 17:12:15 +08:00
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_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 */
2014-02-18 11:13:00 +08:00
zend_std_get_debug_info , /* get_debug_info */
2008-08-15 05:36:56 +08:00
zend_std_get_closure , /* get_closure */
2011-11-02 14:31:33 +08:00
zend_std_get_gc , /* get_gc */
2013-06-17 23:48:13 +08:00
NULL , /* do_operation */
NULL , /* compare */
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 :
*/