2
+----------------------------------------------------------------------+
4
+----------------------------------------------------------------------+
5
| Copyright (c) 1998-2004 Zend Technologies Ltd. (http://www.zend.com) |
6
+----------------------------------------------------------------------+
7
| This source file is subject to version 2.00 of the Zend license, |
8
| that is bundled with this package in the file LICENSE, and is |
9
| available through the world-wide-web at the following url: |
10
| http://www.zend.com/license/2_00.txt. |
11
| If you did not receive a copy of the Zend license and are unable to |
12
| obtain it through the world-wide-web, please send a note to |
13
| license@zend.com so we can mail you a copy immediately. |
14
+----------------------------------------------------------------------+
15
| Authors: Andi Gutmans <andi@zend.com> |
16
| Zeev Suraski <zeev@zend.com> |
17
| Andrei Zmievski <andrei@php.net> |
18
+----------------------------------------------------------------------+
21
/* $Id: zend_API.c,v 1.256.2.18 2005/07/25 20:26:49 helly Exp $ */
24
#include "zend_execute.h"
26
#include "zend_modules.h"
27
#include "zend_constants.h"
33
/* these variables are true statics/globals, and have to be mutex'ed on every access */
34
static int module_count=0;
35
ZEND_API HashTable module_registry;
37
/* this function doesn't check for too many parameters */
38
ZEND_API int zend_get_parameters(int ht, int param_count, ...)
43
zval **param, *param_ptr;
46
p = EG(argument_stack).top_element-2;
47
arg_count = (ulong) *p;
49
if (param_count>arg_count) {
53
va_start(ptr, param_count);
55
while (param_count-->0) {
56
param = va_arg(ptr, zval **);
57
param_ptr = *(p-arg_count);
58
if (!PZVAL_IS_REF(param_ptr) && param_ptr->refcount>1) {
62
*new_tmp = *param_ptr;
63
zval_copy_ctor(new_tmp);
66
((zval *) *(p-arg_count))->refcount--;
67
*(p-arg_count) = param_ptr;
78
ZEND_API int _zend_get_parameters_array(int ht, int param_count, zval **argument_array TSRMLS_DC)
84
p = EG(argument_stack).top_element-2;
85
arg_count = (ulong) *p;
87
if (param_count>arg_count) {
91
while (param_count-->0) {
92
param_ptr = *(p-arg_count);
93
if (!PZVAL_IS_REF(param_ptr) && param_ptr->refcount>1) {
97
*new_tmp = *param_ptr;
98
zval_copy_ctor(new_tmp);
101
((zval *) *(p-arg_count))->refcount--;
102
*(p-arg_count) = param_ptr;
104
*(argument_array++) = param_ptr;
114
/* Zend-optimized Extended functions */
115
/* this function doesn't check for too many parameters */
116
ZEND_API int zend_get_parameters_ex(int param_count, ...)
124
p = EG(argument_stack).top_element-2;
125
arg_count = (ulong) *p;
127
if (param_count>arg_count) {
131
va_start(ptr, param_count);
132
while (param_count-->0) {
133
param = va_arg(ptr, zval ***);
134
*param = (zval **) p-(arg_count--);
142
ZEND_API int _zend_get_parameters_array_ex(int param_count, zval ***argument_array TSRMLS_DC)
147
p = EG(argument_stack).top_element-2;
148
arg_count = (ulong) *p;
150
if (param_count>arg_count) {
154
while (param_count-->0) {
155
zval **value = (zval**)(p-arg_count);
157
if (EG(ze1_compatibility_mode) && Z_TYPE_PP(value) == IS_OBJECT) {
160
zend_uint class_name_len;
163
dup = zend_get_object_classname(*value, &class_name, &class_name_len TSRMLS_CC);
165
ALLOC_ZVAL(value_ptr);
166
*value_ptr = **value;
167
INIT_PZVAL(value_ptr);
168
zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name);
172
value_ptr->value.obj = Z_OBJ_HANDLER_PP(value, clone_obj)(*value TSRMLS_CC);
173
zval_ptr_dtor(value);
176
*(argument_array++) = value;
184
ZEND_API void zend_wrong_param_count(TSRMLS_D)
187
char *class_name = get_active_class_name(&space TSRMLS_CC);
189
zend_error(E_WARNING, "Wrong parameter count for %s%s%s()", class_name, space, get_active_function_name(TSRMLS_C));
193
/* Argument parsing API -- andrei */
195
ZEND_API char *zend_zval_type_name(zval *arg)
197
switch (Z_TYPE_P(arg)) {
227
ZEND_API zend_class_entry *zend_get_class_entry(zval *zobject TSRMLS_DC)
229
if (Z_OBJ_HT_P(zobject)->get_class_entry) {
230
return Z_OBJ_HT_P(zobject)->get_class_entry(zobject TSRMLS_CC);
232
zend_error(E_ERROR, "Class entry requested for an object without PHP class");
237
/* returns 1 if you need to copy result, 0 if it's already a copy */
238
ZEND_API int zend_get_object_classname(zval *object, char **class_name, zend_uint *class_name_len TSRMLS_DC)
240
if (Z_OBJ_HT_P(object)->get_class_name == NULL ||
241
Z_OBJ_HT_P(object)->get_class_name(object, class_name, class_name_len, 0 TSRMLS_CC) != SUCCESS) {
242
zend_class_entry *ce = Z_OBJCE_P(object);
244
*class_name = ce->name;
245
*class_name_len = ce->name_length;
252
static char *zend_parse_arg_impl(zval **arg, va_list *va, char **spec TSRMLS_DC)
254
char *spec_walk = *spec;
255
char c = *spec_walk++;
258
while (*spec_walk == '/' || *spec_walk == '!') {
259
if (*spec_walk == '/') {
260
SEPARATE_ZVAL_IF_NOT_REF(arg);
261
} else if (*spec_walk == '!' && Z_TYPE_PP(arg) == IS_NULL) {
270
long *p = va_arg(*va, long *);
271
switch (Z_TYPE_PP(arg)) {
277
if ((type = is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), p, &d, 0)) == 0) {
279
} else if (type == IS_DOUBLE) {
289
convert_to_long_ex(arg);
304
double *p = va_arg(*va, double *);
305
switch (Z_TYPE_PP(arg)) {
311
if ((type = is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), &l, p, 0)) == 0) {
313
} else if (type == IS_LONG) {
323
convert_to_double_ex(arg);
338
char **p = va_arg(*va, char **);
339
int *pl = va_arg(*va, int *);
340
switch (Z_TYPE_PP(arg)) {
347
/* break omitted intentionally */
353
convert_to_string_ex(arg);
354
*p = Z_STRVAL_PP(arg);
355
*pl = Z_STRLEN_PP(arg);
358
if (Z_OBJ_HANDLER_PP(arg, cast_object)) {
359
SEPARATE_ZVAL_IF_NOT_REF(arg);
360
if (Z_OBJ_HANDLER_PP(arg, cast_object)(*arg, *arg, IS_STRING, 0 TSRMLS_CC) == SUCCESS) {
361
*pl = Z_STRLEN_PP(arg);
362
*p = Z_STRVAL_PP(arg);
378
zend_bool *p = va_arg(*va, zend_bool *);
379
switch (Z_TYPE_PP(arg)) {
385
convert_to_boolean_ex(arg);
400
zval **p = va_arg(*va, zval **);
401
if (Z_TYPE_PP(arg) != IS_RESOURCE) {
402
if (Z_TYPE_PP(arg) == IS_NULL && return_null) {
414
zval **p = va_arg(*va, zval **);
415
if (Z_TYPE_PP(arg) != IS_ARRAY) {
416
if (Z_TYPE_PP(arg) == IS_NULL && return_null) {
428
zval **p = va_arg(*va, zval **);
429
if (Z_TYPE_PP(arg) != IS_OBJECT) {
430
if (Z_TYPE_PP(arg) == IS_NULL && return_null) {
442
zval **p = va_arg(*va, zval **);
443
zend_class_entry *ce = va_arg(*va, zend_class_entry *);
445
if (Z_TYPE_PP(arg) == IS_OBJECT &&
446
(!ce || instanceof_function(Z_OBJCE_PP(arg), ce TSRMLS_CC))) {
449
if (Z_TYPE_PP(arg) == IS_NULL && return_null) {
452
return ce ? ce->name : "object";
460
zval **p = va_arg(*va, zval **);
461
if (Z_TYPE_PP(arg) == IS_NULL && return_null) {
470
zval ***p = va_arg(*va, zval ***);
471
if (Z_TYPE_PP(arg) == IS_NULL && return_null) {
487
static int zend_parse_arg(int arg_num, zval **arg, va_list *va, char **spec, int quiet TSRMLS_DC)
489
char *expected_type = NULL;
491
expected_type = zend_parse_arg_impl(arg, va, spec TSRMLS_CC);
495
char *class_name = get_active_class_name(&space TSRMLS_CC);
496
zend_error(E_WARNING, "%s%s%s() expects parameter %d to be %s, %s given",
497
class_name, space, get_active_function_name(TSRMLS_C), arg_num, expected_type,
498
zend_zval_type_name(*arg));
506
static int zend_parse_va_args(int num_args, char *type_spec, va_list *va, int flags TSRMLS_DC)
510
int min_num_args = -1;
511
int max_num_args = 0;
515
int quiet = flags & ZEND_PARSE_PARAMS_QUIET;
517
for (spec_walk = type_spec; *spec_walk; spec_walk++) {
529
min_num_args = max_num_args;
539
zend_function *active_function = EG(function_state_ptr)->function;
540
char *class_name = active_function->common.scope ? active_function->common.scope->name : "";
541
zend_error(E_WARNING, "%s%s%s(): bad type specifier while parsing parameters",
543
class_name[0] ? "::" : "",
544
get_active_function_name(TSRMLS_C));
550
if (min_num_args < 0) {
551
min_num_args = max_num_args;
554
if (num_args < min_num_args || num_args > max_num_args) {
556
zend_function *active_function = EG(function_state_ptr)->function;
557
char *class_name = active_function->common.scope ? active_function->common.scope->name : "";
558
zend_error(E_WARNING, "%s%s%s() expects %s %d parameter%s, %d given",
560
class_name[0] ? "::" : "",
561
get_active_function_name(TSRMLS_C),
562
min_num_args == max_num_args ? "exactly" : num_args < min_num_args ? "at least" : "at most",
563
num_args < min_num_args ? min_num_args : max_num_args,
564
(num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
570
p = EG(argument_stack).top_element-2;
571
arg_count = (ulong) *p;
573
if (num_args > arg_count) {
574
zend_error(E_WARNING, "%s(): could not obtain parameters for parsing",
575
get_active_function_name(TSRMLS_C));
580
while (num_args-- > 0) {
581
arg = (zval **) p - (arg_count-i);
582
if (*type_spec == '|') {
585
if (zend_parse_arg(i+1, arg, va, &type_spec, quiet TSRMLS_CC) == FAILURE) {
594
ZEND_API int zend_parse_parameters_ex(int flags, int num_args TSRMLS_DC, char *type_spec, ...)
599
va_start(va, type_spec);
600
retval = zend_parse_va_args(num_args, type_spec, &va, flags TSRMLS_CC);
606
ZEND_API int zend_parse_parameters(int num_args TSRMLS_DC, char *type_spec, ...)
611
va_start(va, type_spec);
612
retval = zend_parse_va_args(num_args, type_spec, &va, 0 TSRMLS_CC);
618
ZEND_API int zend_parse_method_parameters(int num_args TSRMLS_DC, zval *this_ptr, char *type_spec, ...)
624
zend_class_entry *ce;
627
va_start(va, type_spec);
628
retval = zend_parse_va_args(num_args, type_spec, &va, 0 TSRMLS_CC);
632
va_start(va, type_spec);
634
object = va_arg(va, zval **);
635
ce = va_arg(va, zend_class_entry *);
637
if (ce && !instanceof_function(Z_OBJCE_P(this_ptr), ce TSRMLS_CC)) {
638
zend_error(E_CORE_ERROR, "%s::%s() must be derived from %s::%s",
639
ce->name, get_active_function_name(TSRMLS_C), Z_OBJCE_P(this_ptr)->name, get_active_function_name(TSRMLS_C));
642
retval = zend_parse_va_args(num_args, p, &va, 0 TSRMLS_CC);
649
ZEND_API int zend_parse_method_parameters_ex(int flags, int num_args TSRMLS_DC, zval *this_ptr, char *type_spec, ...)
655
zend_class_entry *ce;
656
int quiet = flags & ZEND_PARSE_PARAMS_QUIET;
659
va_start(va, type_spec);
660
retval = zend_parse_va_args(num_args, type_spec, &va, 0 TSRMLS_CC);
664
va_start(va, type_spec);
666
object = va_arg(va, zval **);
667
ce = va_arg(va, zend_class_entry *);
669
if (ce && !instanceof_function(Z_OBJCE_P(this_ptr), ce TSRMLS_CC)) {
671
zend_error(E_CORE_ERROR, "%s::%s() must be derived from %s::%s",
672
ce->name, get_active_function_name(TSRMLS_C), Z_OBJCE_P(this_ptr)->name, get_active_function_name(TSRMLS_C));
677
retval = zend_parse_va_args(num_args, p, &va, flags TSRMLS_CC);
684
/* Argument parsing API -- andrei */
687
ZEND_API int _array_init(zval *arg ZEND_FILE_LINE_DC)
689
ALLOC_HASHTABLE_REL(arg->value.ht);
691
_zend_hash_init(arg->value.ht, 0, NULL, ZVAL_PTR_DTOR, 0 ZEND_FILE_LINE_RELAY_CC);
692
arg->type = IS_ARRAY;
697
static int zend_merge_property(zval **value, int num_args, va_list args, zend_hash_key *hash_key)
699
/* which name should a numeric property have ? */
700
if (hash_key->nKeyLength) {
701
zval *obj = va_arg(args, zval *);
702
zend_object_handlers *obj_ht = va_arg(args, zend_object_handlers *);
706
ZVAL_STRINGL(&member, hash_key->arKey, hash_key->nKeyLength-1, 0);
707
obj_ht->write_property(obj, &member, *value TSRMLS_CC);
709
return ZEND_HASH_APPLY_KEEP;
713
/* This function should be called after the constructor has been called
714
* because it may call __set from the uninitialized object otherwise. */
715
ZEND_API void zend_merge_properties(zval *obj, HashTable *properties, int destroy_ht TSRMLS_DC)
717
zend_object_handlers *obj_ht = Z_OBJ_HT_P(obj);
718
zend_class_entry *old_scope = EG(scope);
720
EG(scope) = Z_OBJCE_P(obj);
721
zend_hash_apply_with_arguments(properties, (apply_func_args_t)zend_merge_property, 2, obj, obj_ht);
722
EG(scope) = old_scope;
725
zend_hash_destroy(properties);
726
FREE_HASHTABLE(properties);
731
ZEND_API void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC)
733
if (!class_type->constants_updated) {
734
zend_class_entry **scope = EG(in_execution)?&EG(scope):&CG(active_class_entry);
735
zend_class_entry *old_scope = *scope;
738
zend_hash_apply_with_argument(&class_type->default_properties, (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
739
zend_hash_apply_with_argument(class_type->static_members, (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
741
class_type->constants_updated = 1;
746
/* This function requires 'properties' to contain all props declared in the
747
* class and all props being public. If only a subset is given or the class
748
* has protected members then you need to merge the properties seperately by
749
* calling zend_merge_properties(). */
750
ZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *class_type, HashTable *properties ZEND_FILE_LINE_DC TSRMLS_DC)
755
if (class_type->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
756
char *what = class_type->ce_flags & ZEND_ACC_INTERFACE ? "interface" : "abstract class";
757
zend_error(E_ERROR, "Cannot instantiate %s %s", what, class_type->name);
760
zend_update_class_constants(class_type TSRMLS_CC);
762
arg->type = IS_OBJECT;
763
if (class_type->create_object == NULL) {
764
arg->value.obj = zend_objects_new(&object, class_type TSRMLS_CC);
766
object->properties = properties;
768
ALLOC_HASHTABLE_REL(object->properties);
769
zend_hash_init(object->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
770
zend_hash_copy(object->properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
773
arg->value.obj = class_type->create_object(class_type TSRMLS_CC);
778
ZEND_API int _object_init_ex(zval *arg, zend_class_entry *class_type ZEND_FILE_LINE_DC TSRMLS_DC)
780
return _object_and_properties_init(arg, class_type, 0 ZEND_FILE_LINE_RELAY_CC TSRMLS_CC);
783
ZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC TSRMLS_DC)
785
return _object_init_ex(arg, zend_standard_class_def ZEND_FILE_LINE_RELAY_CC TSRMLS_CC);
789
ZEND_API int add_assoc_function(zval *arg, char *key, void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS))
791
zend_error(E_WARNING, "add_assoc_function() is no longer supported");
796
ZEND_API int add_assoc_long_ex(zval *arg, char *key, uint key_len, long n)
803
return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
806
ZEND_API int add_assoc_null_ex(zval *arg, char *key, uint key_len)
813
return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
816
ZEND_API int add_assoc_bool_ex(zval *arg, char *key, uint key_len, int b)
823
return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
826
ZEND_API int add_assoc_resource_ex(zval *arg, char *key, uint key_len, int r)
831
ZVAL_RESOURCE(tmp, r);
833
return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
837
ZEND_API int add_assoc_double_ex(zval *arg, char *key, uint key_len, double d)
844
return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
848
ZEND_API int add_assoc_string_ex(zval *arg, char *key, uint key_len, char *str, int duplicate)
853
ZVAL_STRING(tmp, str, duplicate);
855
return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
859
ZEND_API int add_assoc_stringl_ex(zval *arg, char *key, uint key_len, char *str, uint length, int duplicate)
864
ZVAL_STRINGL(tmp, str, length, duplicate);
866
return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), NULL);
869
ZEND_API int add_assoc_zval_ex(zval *arg, char *key, uint key_len, zval *value)
871
return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &value, sizeof(zval *), NULL);
875
ZEND_API int add_index_long(zval *arg, uint index, long n)
882
return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
886
ZEND_API int add_index_null(zval *arg, uint index)
893
return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
896
ZEND_API int add_index_bool(zval *arg, uint index, int b)
903
return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
907
ZEND_API int add_index_resource(zval *arg, uint index, int r)
912
ZVAL_RESOURCE(tmp, r);
914
return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
918
ZEND_API int add_index_double(zval *arg, uint index, double d)
925
return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
929
ZEND_API int add_index_string(zval *arg, uint index, char *str, int duplicate)
934
ZVAL_STRING(tmp, str, duplicate);
936
return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
940
ZEND_API int add_index_stringl(zval *arg, uint index, char *str, uint length, int duplicate)
945
ZVAL_STRINGL(tmp, str, length, duplicate);
947
return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), NULL);
951
ZEND_API int add_index_zval(zval *arg, uint index, zval *value)
953
return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &value, sizeof(zval *), NULL);
957
ZEND_API int add_next_index_long(zval *arg, long n)
964
return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
968
ZEND_API int add_next_index_null(zval *arg)
975
return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
979
ZEND_API int add_next_index_bool(zval *arg, int b)
986
return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
990
ZEND_API int add_next_index_resource(zval *arg, int r)
995
ZVAL_RESOURCE(tmp, r);
997
return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
1001
ZEND_API int add_next_index_double(zval *arg, double d)
1006
ZVAL_DOUBLE(tmp, d);
1008
return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
1012
ZEND_API int add_next_index_string(zval *arg, char *str, int duplicate)
1017
ZVAL_STRING(tmp, str, duplicate);
1019
return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
1023
ZEND_API int add_next_index_stringl(zval *arg, char *str, uint length, int duplicate)
1028
ZVAL_STRINGL(tmp, str, length, duplicate);
1030
return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &tmp, sizeof(zval *), NULL);
1034
ZEND_API int add_next_index_zval(zval *arg, zval *value)
1036
return zend_hash_next_index_insert(Z_ARRVAL_P(arg), &value, sizeof(zval *), NULL);
1040
ZEND_API int add_get_assoc_string_ex(zval *arg, char *key, uint key_len, char *str, void **dest, int duplicate)
1045
ZVAL_STRING(tmp, str, duplicate);
1047
return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), dest);
1051
ZEND_API int add_get_assoc_stringl_ex(zval *arg, char *key, uint key_len, char *str, uint length, void **dest, int duplicate)
1056
ZVAL_STRINGL(tmp, str, length, duplicate);
1058
return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &tmp, sizeof(zval *), dest);
1062
ZEND_API int add_get_index_long(zval *arg, uint index, long l, void **dest)
1069
return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), dest);
1073
ZEND_API int add_get_index_double(zval *arg, uint index, double d, void **dest)
1078
ZVAL_DOUBLE(tmp, d);
1080
return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), dest);
1084
ZEND_API int add_get_index_string(zval *arg, uint index, char *str, void **dest, int duplicate)
1089
ZVAL_STRING(tmp, str, duplicate);
1091
return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), dest);
1095
ZEND_API int add_get_index_stringl(zval *arg, uint index, char *str, uint length, void **dest, int duplicate)
1100
ZVAL_STRINGL(tmp, str, length, duplicate);
1102
return zend_hash_index_update(Z_ARRVAL_P(arg), index, (void *) &tmp, sizeof(zval *), dest);
1106
ZEND_API int add_property_long_ex(zval *arg, char *key, uint key_len, long n TSRMLS_DC)
1113
ZVAL_STRINGL(&z_key, key, key_len-1, 0);
1115
Z_OBJ_HANDLER_P(arg, write_property)(arg, &z_key, tmp TSRMLS_CC);
1116
zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
1120
ZEND_API int add_property_bool_ex(zval *arg, char *key, uint key_len, int b TSRMLS_DC)
1128
ZVAL_STRINGL(&z_key, key, key_len-1, 0);
1130
Z_OBJ_HANDLER_P(arg, write_property)(arg, &z_key, tmp TSRMLS_CC);
1131
zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
1135
ZEND_API int add_property_null_ex(zval *arg, char *key, uint key_len TSRMLS_DC)
1143
ZVAL_STRINGL(&z_key, key, key_len-1, 0);
1145
Z_OBJ_HANDLER_P(arg, write_property)(arg, &z_key, tmp TSRMLS_CC);
1146
zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
1150
ZEND_API int add_property_resource_ex(zval *arg, char *key, uint key_len, long n TSRMLS_DC)
1156
ZVAL_RESOURCE(tmp, n);
1157
ZVAL_STRINGL(&z_key, key, key_len-1, 0);
1159
Z_OBJ_HANDLER_P(arg, write_property)(arg, &z_key, tmp TSRMLS_CC);
1160
zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
1165
ZEND_API int add_property_double_ex(zval *arg, char *key, uint key_len, double d TSRMLS_DC)
1171
ZVAL_DOUBLE(tmp, d);
1172
ZVAL_STRINGL(&z_key, key, key_len-1, 0);
1174
Z_OBJ_HANDLER_P(arg, write_property)(arg, &z_key, tmp TSRMLS_CC);
1175
zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
1180
ZEND_API int add_property_string_ex(zval *arg, char *key, uint key_len, char *str, int duplicate TSRMLS_DC)
1186
ZVAL_STRING(tmp, str, duplicate);
1188
ZVAL_STRINGL(&z_key, key, key_len-1, 0);
1190
Z_OBJ_HANDLER_P(arg, write_property)(arg, &z_key, tmp TSRMLS_CC);
1191
zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
1195
ZEND_API int add_property_stringl_ex(zval *arg, char *key, uint key_len, char *str, uint length, int duplicate TSRMLS_DC)
1201
ZVAL_STRINGL(tmp, str, length, duplicate);
1203
ZVAL_STRINGL(&z_key, key, key_len-1, 0);
1205
Z_OBJ_HANDLER_P(arg, write_property)(arg, &z_key, tmp TSRMLS_CC);
1206
zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */
1210
ZEND_API int add_property_zval_ex(zval *arg, char *key, uint key_len, zval *value TSRMLS_DC)
1214
ZVAL_STRINGL(&z_key, key, key_len-1, 0);
1216
Z_OBJ_HANDLER_P(arg, write_property)(arg, &z_key, value TSRMLS_CC);
1220
ZEND_API int zend_register_module_ex(zend_module_entry *module TSRMLS_DC)
1224
zend_module_entry *module_ptr;
1231
zend_printf("%s: Registering module %d\n", module->name, module->module_number);
1233
name_len = strlen(module->name);
1234
lcname = zend_str_tolower_dup(module->name, name_len);
1236
if (zend_hash_add(&module_registry, lcname, name_len+1, (void *)module, sizeof(zend_module_entry), (void**)&module_ptr)==FAILURE) {
1237
zend_error(E_CORE_WARNING, "Module '%s' already loaded", module->name);
1242
module = module_ptr;
1244
if (module->functions && zend_register_functions(NULL, module->functions, NULL, module->type TSRMLS_CC)==FAILURE) {
1245
zend_error(E_CORE_WARNING,"%s: Unable to register functions, unable to load", module->name);
1249
if (!module->module_started && module->module_startup_func) {
1250
EG(current_module) = module;
1251
if (module->module_startup_func(module->type, module->module_number TSRMLS_CC)==FAILURE) {
1252
zend_error(E_CORE_ERROR,"Unable to start %s module", module->name);
1253
EG(current_module) = NULL;
1256
EG(current_module) = NULL;
1259
module->module_started=1;
1264
ZEND_API int zend_startup_module(zend_module_entry *module)
1268
module->module_number = zend_next_free_module();
1269
module->type = MODULE_PERSISTENT;
1270
return zend_register_module_ex(module TSRMLS_CC);
1273
void zend_check_magic_method_implementation(zend_class_entry *ce, zend_function *fptr, int error_type TSRMLS_DC)
1278
/* we don't care if the function name is longer, in fact lowercasing only
1279
* the beginning of the name speeds up the check process */
1280
name_len = strlen(fptr->common.function_name);
1281
zend_str_tolower_copy(lcname, fptr->common.function_name, MIN(name_len, sizeof(lcname)-1));
1282
lcname[sizeof(lcname)-1] = '\0'; /* zend_str_tolower_copy won't necessarily set the zero byte */
1284
if (name_len == sizeof(ZEND_DESTRUCTOR_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_DESTRUCTOR_FUNC_NAME, sizeof(ZEND_DESTRUCTOR_FUNC_NAME)) && fptr->common.num_args != 0) {
1285
zend_error(error_type, "Destuctor %s::%s() cannot take arguments", ce->name, ZEND_DESTRUCTOR_FUNC_NAME);
1286
} else if (name_len == sizeof(ZEND_CLONE_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_CLONE_FUNC_NAME, sizeof(ZEND_CLONE_FUNC_NAME)) && fptr->common.num_args != 0) {
1287
zend_error(error_type, "Method %s::%s() cannot accept any arguments", ce->name, ZEND_CLONE_FUNC_NAME);
1288
} else if (name_len == sizeof(ZEND_GET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME)) && fptr->common.num_args != 1) {
1289
zend_error(error_type, "Method %s::%s() must take exactly 1 argument", ce->name, ZEND_GET_FUNC_NAME);
1290
} else if (name_len == sizeof(ZEND_SET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME)) && fptr->common.num_args != 2) {
1291
zend_error(error_type, "Method %s::%s() must take exactly 2 arguments", ce->name, ZEND_SET_FUNC_NAME);
1292
} else if (name_len == sizeof(ZEND_CALL_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)) && fptr->common.num_args != 2) {
1293
zend_error(error_type, "Method %s::%s() must take exactly 2 arguments", ce->name, ZEND_CALL_FUNC_NAME);
1297
/* registers all functions in *library_functions in the function hash */
1298
ZEND_API int zend_register_functions(zend_class_entry *scope, zend_function_entry *functions, HashTable *function_table, int type TSRMLS_DC)
1300
zend_function_entry *ptr = functions;
1301
zend_function function, *reg_function;
1302
zend_internal_function *internal_function = (zend_internal_function *)&function;
1303
int count=0, unload=0;
1304
HashTable *target_function_table = function_table;
1306
zend_function *ctor = NULL, *dtor = NULL, *clone = NULL, *__get = NULL, *__set = NULL, *__call = NULL;
1307
char *lowercase_name;
1309
char *lc_class_name;
1312
if (type==MODULE_PERSISTENT) {
1313
error_type = E_CORE_WARNING;
1315
error_type = E_WARNING;
1318
if (!target_function_table) {
1319
target_function_table = CG(function_table);
1321
internal_function->type = ZEND_INTERNAL_FUNCTION;
1324
class_name_len = strlen(scope->name);
1325
lc_class_name = zend_str_tolower_dup(scope->name, class_name_len);
1328
while (ptr->fname) {
1329
internal_function->handler = ptr->handler;
1330
internal_function->function_name = ptr->fname;
1331
internal_function->scope = scope;
1332
internal_function->prototype = NULL;
1333
if (ptr->arg_info) {
1334
internal_function->arg_info = ptr->arg_info+1;
1335
internal_function->num_args = ptr->num_args;
1336
/* Currently you cannot denote that the function can accept less arguments than num_args */
1337
if (ptr->arg_info[0].required_num_args == -1) {
1338
internal_function->required_num_args = ptr->num_args;
1340
internal_function->required_num_args = ptr->arg_info[0].required_num_args;
1342
internal_function->pass_rest_by_reference = ptr->arg_info[0].pass_by_reference;
1343
internal_function->return_reference = ptr->arg_info[0].return_reference;
1345
internal_function->arg_info = NULL;
1346
internal_function->num_args = 0;
1347
internal_function->required_num_args = 0;
1348
internal_function->pass_rest_by_reference = 0;
1349
internal_function->return_reference = 0;
1352
if (!(ptr->flags & ZEND_ACC_PPP_MASK)) {
1353
zend_error(error_type, "Invalid access level for %s%s%s() - access must be exactly one of public, protected or private", scope ? scope->name : "", scope ? "::" : "", ptr->fname);
1354
internal_function->fn_flags = ZEND_ACC_PUBLIC;
1356
internal_function->fn_flags = ptr->flags;
1359
internal_function->fn_flags = ZEND_ACC_PUBLIC;
1361
if (ptr->flags & ZEND_ACC_ABSTRACT) {
1363
/* This is a class that must be abstract itself. Here we set the check info. */
1364
scope->ce_flags |= ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
1365
if (!(scope->ce_flags & ZEND_ACC_INTERFACE)) {
1366
/* Since the class is not an interface it needs to be declared as a abstract class. */
1367
/* Since here we are handling internal functions only we can add the keyword flag. */
1368
/* This time we set the flag for the keyword 'abstratc'. */
1369
scope->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
1373
if (scope && (scope->ce_flags & ZEND_ACC_INTERFACE)) {
1374
zend_error(error_type, "Interface %s cannot contain non abstract method %s()", scope->name, ptr->fname);
1377
if (!internal_function->handler) {
1378
zend_error(error_type, "Method %s%s%s() cannot be a NULL function", scope ? scope->name : "", scope ? "::" : "", ptr->fname);
1379
zend_unregister_functions(functions, count, target_function_table TSRMLS_CC);
1383
fname_len = strlen(ptr->fname);
1384
lowercase_name = do_alloca(fname_len+1);
1385
zend_str_tolower_copy(lowercase_name, ptr->fname, fname_len);
1386
if (zend_hash_add(target_function_table, lowercase_name, fname_len+1, &function, sizeof(zend_function), (void**)®_function) == FAILURE) {
1388
free_alloca(lowercase_name);
1392
/* Look for ctor, dtor, clone
1393
* If it's an old-style constructor, store it only if we don't have
1394
* a constructor already.
1396
if ((fname_len == class_name_len) && !memcmp(lowercase_name, lc_class_name, class_name_len+1) && !ctor) {
1397
ctor = reg_function;
1398
} else if ((fname_len == sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME))) {
1399
ctor = reg_function;
1400
} else if ((fname_len == sizeof(ZEND_DESTRUCTOR_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_DESTRUCTOR_FUNC_NAME, sizeof(ZEND_DESTRUCTOR_FUNC_NAME))) {
1401
dtor = reg_function;
1402
if (internal_function->num_args) {
1403
zend_error(error_type, "Destructor %s::%s() cannot take arguments", scope->name, ptr->fname);
1405
} else if ((fname_len == sizeof(ZEND_CLONE_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_CLONE_FUNC_NAME, sizeof(ZEND_CLONE_FUNC_NAME))) {
1406
clone = reg_function;
1407
} else if ((fname_len == sizeof(ZEND_CALL_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME))) {
1408
__call = reg_function;
1409
} else if ((fname_len == sizeof(ZEND_GET_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME))) {
1410
__get = reg_function;
1411
} else if ((fname_len == sizeof(ZEND_SET_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME))) {
1412
__set = reg_function;
1414
reg_function = NULL;
1417
zend_check_magic_method_implementation(scope, reg_function, error_type TSRMLS_CC);
1422
free_alloca(lowercase_name);
1424
if (unload) { /* before unloading, display all remaining bad function in the module */
1426
efree(lc_class_name);
1428
while (ptr->fname) {
1429
if (zend_hash_exists(target_function_table, ptr->fname, strlen(ptr->fname)+1)) {
1430
zend_error(error_type, "Function registration failed - duplicate name - %s%s%s", scope ? scope->name : "", scope ? "::" : "", ptr->fname);
1434
zend_unregister_functions(functions, count, target_function_table TSRMLS_CC);
1438
scope->constructor = ctor;
1439
scope->destructor = dtor;
1440
scope->clone = clone;
1441
scope->__call = __call;
1442
scope->__get = __get;
1443
scope->__set = __set;
1445
ctor->common.fn_flags |= ZEND_ACC_CTOR;
1446
if (ctor->common.fn_flags & ZEND_ACC_STATIC) {
1447
zend_error(error_type, "Constructor %s::%s() cannot be static", scope->name, ctor->common.function_name);
1449
ctor->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
1452
dtor->common.fn_flags |= ZEND_ACC_DTOR;
1453
if (dtor->common.fn_flags & ZEND_ACC_STATIC) {
1454
zend_error(error_type, "Destructor %s::%s() cannot be static", scope->name, dtor->common.function_name);
1456
dtor->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
1459
clone->common.fn_flags |= ZEND_ACC_CLONE;
1460
if (clone->common.fn_flags & ZEND_ACC_STATIC) {
1461
zend_error(error_type, "Constructor %s::%s() cannot be static", scope->name, clone->common.function_name);
1463
clone->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
1466
if (__call->common.fn_flags & ZEND_ACC_STATIC) {
1467
zend_error(error_type, "Method %s::%s() cannot be static", scope->name, __call->common.function_name);
1469
__call->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
1472
if (__get->common.fn_flags & ZEND_ACC_STATIC) {
1473
zend_error(error_type, "Method %s::%s() cannot be static", scope->name, __get->common.function_name);
1475
__get->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
1478
if (__set->common.fn_flags & ZEND_ACC_STATIC) {
1479
zend_error(error_type, "Method %s::%s() cannot be static", scope->name, __set->common.function_name);
1481
__set->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
1483
efree(lc_class_name);
1488
/* count=-1 means erase all functions, otherwise,
1489
* erase the first count functions
1491
ZEND_API void zend_unregister_functions(zend_function_entry *functions, int count, HashTable *function_table TSRMLS_DC)
1493
zend_function_entry *ptr = functions;
1495
HashTable *target_function_table = function_table;
1497
if (!target_function_table) {
1498
target_function_table = CG(function_table);
1500
while (ptr->fname) {
1501
if (count!=-1 && i>=count) {
1505
zend_printf("Unregistering %s()\n", ptr->fname);
1507
zend_hash_del(target_function_table, ptr->fname, strlen(ptr->fname)+1);
1514
ZEND_API int zend_register_module(zend_module_entry *module)
1518
return zend_register_module_ex(module TSRMLS_CC);
1522
ZEND_API int zend_get_module_started(char *module_name)
1524
zend_module_entry *module;
1526
return (zend_hash_find(&module_registry, module_name, strlen(module_name)+1, (void**)&module) == SUCCESS && module->module_started) ? SUCCESS : FAILURE;
1530
void module_destructor(zend_module_entry *module)
1534
if (module->type == MODULE_TEMPORARY) {
1535
zend_clean_module_rsrc_dtors(module->module_number TSRMLS_CC);
1536
clean_module_constants(module->module_number TSRMLS_CC);
1539
if (module->module_started && module->module_shutdown_func) {
1541
zend_printf("%s: Module shutdown\n", module->name);
1543
module->module_shutdown_func(module->type, module->module_number TSRMLS_CC);
1545
module->module_started=0;
1546
if (module->functions) {
1547
zend_unregister_functions(module->functions, -1, NULL TSRMLS_CC);
1550
#if HAVE_LIBDL || defined(HAVE_MACH_O_DYLD_H)
1551
if (module->handle) {
1552
DL_UNLOAD(module->handle);
1558
/* call request startup for all modules */
1559
int module_registry_request_startup(zend_module_entry *module TSRMLS_DC)
1561
if (module->request_startup_func) {
1563
zend_printf("%s: Request startup\n", module->name);
1565
if (module->request_startup_func(module->type, module->module_number TSRMLS_CC)==FAILURE) {
1566
zend_error(E_WARNING, "request_startup() for %s module failed", module->name);
1574
/* call request shutdown for all modules */
1575
int module_registry_cleanup(zend_module_entry *module TSRMLS_DC)
1577
if (module->request_shutdown_func) {
1579
zend_printf("%s: Request shutdown\n", module->name);
1581
module->request_shutdown_func(module->type, module->module_number TSRMLS_CC);
1586
int module_registry_unload_temp(zend_module_entry *module TSRMLS_DC)
1588
switch (module->type) {
1589
case MODULE_TEMPORARY:
1596
/* return the next free module number */
1597
int zend_next_free_module(void)
1599
return ++module_count;
1602
static zend_class_entry *do_register_internal_class(zend_class_entry *orig_class_entry, zend_uint ce_flags TSRMLS_DC)
1604
zend_class_entry *class_entry = malloc(sizeof(zend_class_entry));
1605
char *lowercase_name = malloc(orig_class_entry->name_length + 1);
1606
*class_entry = *orig_class_entry;
1608
class_entry->type = ZEND_INTERNAL_CLASS;
1609
zend_initialize_class_data(class_entry, 0 TSRMLS_CC);
1610
class_entry->ce_flags = ce_flags;
1611
class_entry->module = EG(current_module);
1613
if (class_entry->builtin_functions) {
1614
zend_register_functions(class_entry, class_entry->builtin_functions, &class_entry->function_table, MODULE_PERSISTENT TSRMLS_CC);
1617
zend_str_tolower_copy(lowercase_name, orig_class_entry->name, class_entry->name_length);
1618
zend_hash_update(CG(class_table), lowercase_name, class_entry->name_length+1, &class_entry, sizeof(zend_class_entry *), NULL);
1619
free(lowercase_name);
1623
/* If parent_ce is not NULL then it inherits from parent_ce
1624
* If parent_ce is NULL and parent_name isn't then it looks for the parent and inherits from it
1625
* If both parent_ce and parent_name are NULL it does a regular class registration
1626
* If parent_name is specified but not found NULL is returned
1628
ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce, char *parent_name TSRMLS_DC)
1630
zend_class_entry *register_class;
1632
if (!parent_ce && parent_name) {
1633
zend_class_entry **pce;
1634
if (zend_hash_find(CG(class_table), parent_name, strlen(parent_name)+1, (void **) &pce)==FAILURE) {
1641
register_class = zend_register_internal_class(class_entry TSRMLS_CC);
1644
zend_do_inheritance(register_class, parent_ce TSRMLS_CC);
1646
return register_class;
1649
ZEND_API void zend_class_implements(zend_class_entry *class_entry TSRMLS_DC, int num_interfaces, ...)
1651
zend_class_entry *interface_entry;
1652
int ce_num = class_entry->num_interfaces, impl_num;
1653
va_list interface_list;
1654
va_start(interface_list, num_interfaces);
1656
if (class_entry->type & ZEND_INTERNAL_CLASS) {
1657
class_entry->interfaces = realloc(class_entry->interfaces, sizeof(zend_class_entry*) * (class_entry->num_interfaces+num_interfaces));
1659
class_entry->interfaces = erealloc(class_entry->interfaces, sizeof(zend_class_entry*) * (class_entry->num_interfaces+num_interfaces));
1662
while (num_interfaces--) {
1663
interface_entry = va_arg(interface_list, zend_class_entry *);
1664
class_entry->interfaces[class_entry->num_interfaces++] = interface_entry;
1666
impl_num = class_entry->num_interfaces;
1667
while(ce_num < impl_num) {
1668
zend_do_implement_interface(class_entry, class_entry->interfaces[ce_num++] TSRMLS_CC);
1670
va_end(interface_list);
1673
/* A class that contains at least one abstract method automatically becomes an abstract class.
1675
ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *orig_class_entry TSRMLS_DC)
1677
return do_register_internal_class(orig_class_entry, 0 TSRMLS_CC);
1680
ZEND_API zend_class_entry *zend_register_internal_interface(zend_class_entry *orig_class_entry TSRMLS_DC)
1682
return do_register_internal_class(orig_class_entry, ZEND_ACC_INTERFACE TSRMLS_CC);
1685
ZEND_API int zend_set_hash_symbol(zval *symbol, char *name, int name_length,
1686
zend_bool is_ref, int num_symbol_tables, ...)
1688
HashTable *symbol_table;
1689
va_list symbol_table_list;
1691
if (num_symbol_tables <= 0) return FAILURE;
1693
symbol->is_ref = is_ref;
1695
va_start(symbol_table_list, num_symbol_tables);
1696
while (num_symbol_tables-- > 0) {
1697
symbol_table = va_arg(symbol_table_list, HashTable *);
1698
zend_hash_update(symbol_table, name, name_length + 1, &symbol, sizeof(zval *), NULL);
1699
zval_add_ref(&symbol);
1701
va_end(symbol_table_list);
1708
/* Disabled functions support */
1710
ZEND_API ZEND_FUNCTION(display_disabled_function)
1712
zend_error(E_WARNING, "%s() has been disabled for security reasons", get_active_function_name(TSRMLS_C));
1716
static zend_function_entry disabled_function[] = {
1717
ZEND_FE(display_disabled_function, NULL)
1718
{ NULL, NULL, NULL }
1722
ZEND_API int zend_disable_function(char *function_name, uint function_name_length TSRMLS_DC)
1724
if (zend_hash_del(CG(function_table), function_name, function_name_length+1)==FAILURE) {
1727
disabled_function[0].fname = function_name;
1728
return zend_register_functions(NULL, disabled_function, CG(function_table), MODULE_PERSISTENT TSRMLS_CC);
1731
static zend_object_value display_disabled_class(zend_class_entry *class_type TSRMLS_DC)
1733
zend_object_value retval;
1734
zend_object *intern;
1735
retval = zend_objects_new(&intern, class_type TSRMLS_CC);
1736
ALLOC_HASHTABLE(intern->properties);
1737
zend_hash_init(intern->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
1738
zend_error(E_WARNING, "%s() has been disabled for security reasons", class_type->name);
1742
static zend_function_entry disabled_class_new[] = {
1743
{ NULL, NULL, NULL }
1746
ZEND_API int zend_disable_class(char *class_name, uint class_name_length TSRMLS_DC)
1748
zend_class_entry *disabled_class;
1749
disabled_class = (zend_class_entry *) emalloc(sizeof(zend_class_entry));
1751
zend_str_tolower(class_name, class_name_length);
1752
if (zend_hash_del(CG(class_table), class_name, class_name_length+1)==FAILURE) {
1755
INIT_CLASS_ENTRY((*disabled_class), class_name, disabled_class_new);
1756
disabled_class->create_object = display_disabled_class;
1757
zend_register_internal_class(disabled_class TSRMLS_CC);
1761
ZEND_API zend_bool zend_is_callable(zval *callable, uint check_flags, char **callable_name)
1764
zend_bool retval = 0;
1767
switch (Z_TYPE_P(callable)) {
1769
if (callable_name) {
1770
*callable_name = estrndup(Z_STRVAL_P(callable), Z_STRLEN_P(callable));
1772
if (check_flags & IS_CALLABLE_CHECK_SYNTAX_ONLY) {
1776
lcname = zend_str_tolower_dup(Z_STRVAL_P(callable), Z_STRLEN_P(callable));
1777
if (zend_hash_exists(EG(function_table), lcname, Z_STRLEN_P(callable)+1)) {
1787
zend_class_entry *ce = NULL, **pce;
1788
zend_uint callable_name_len;
1790
if (zend_hash_num_elements(Z_ARRVAL_P(callable)) == 2 &&
1791
zend_hash_index_find(Z_ARRVAL_P(callable), 0, (void **) &obj) == SUCCESS &&
1792
zend_hash_index_find(Z_ARRVAL_P(callable), 1, (void **) &method) == SUCCESS &&
1793
(Z_TYPE_PP(obj) == IS_OBJECT || Z_TYPE_PP(obj) == IS_STRING) &&
1794
Z_TYPE_PP(method) == IS_STRING) {
1796
if (Z_TYPE_PP(obj) == IS_STRING) {
1797
if (callable_name) {
1800
callable_name_len = Z_STRLEN_PP(obj) + Z_STRLEN_PP(method) + sizeof("::");
1801
ptr = *callable_name = emalloc(callable_name_len);
1802
memcpy(ptr, Z_STRVAL_PP(obj), Z_STRLEN_PP(obj));
1803
ptr += Z_STRLEN_PP(obj);
1804
memcpy(ptr, "::", sizeof("::") - 1);
1805
ptr += sizeof("::") - 1;
1806
memcpy(ptr, Z_STRVAL_PP(method), Z_STRLEN_PP(method) + 1);
1809
if (check_flags & IS_CALLABLE_CHECK_SYNTAX_ONLY)
1812
lcname = zend_str_tolower_dup(Z_STRVAL_PP(obj), Z_STRLEN_PP(obj));
1814
if (EG(active_op_array) && strcmp(lcname, "self") == 0) {
1815
ce = EG(active_op_array)->scope;
1816
} else if (strcmp(lcname, "parent") == 0 && EG(active_op_array) && EG(active_op_array)->scope) {
1817
ce = EG(active_op_array)->scope->parent;
1818
} else if (zend_lookup_class(Z_STRVAL_PP(obj), Z_STRLEN_PP(obj), &pce TSRMLS_CC) == SUCCESS) {
1824
ce = Z_OBJCE_PP(obj); /* TBFixed: what if it's overloaded? */
1826
if (callable_name) {
1829
callable_name_len = ce->name_length + Z_STRLEN_PP(method) + sizeof("::");
1830
ptr = *callable_name = emalloc(callable_name_len);
1831
memcpy(ptr, ce->name, ce->name_length);
1832
ptr += ce->name_length;
1833
memcpy(ptr, "::", sizeof("::") - 1);
1834
ptr += sizeof("::") - 1;
1835
memcpy(ptr, Z_STRVAL_PP(method), Z_STRLEN_PP(method) + 1);
1838
if (check_flags & IS_CALLABLE_CHECK_SYNTAX_ONLY)
1845
lcname = zend_str_tolower_dup(Z_STRVAL_PP(method), Z_STRLEN_PP(method));
1846
if (zend_hash_find(&ce->function_table, lcname, Z_STRLEN_PP(method)+1, (void **)&fbc) == SUCCESS) {
1848
if ((check_flags & IS_CALLABLE_CHECK_NO_ACCESS) == 0) {
1849
if (fbc->op_array.fn_flags & ZEND_ACC_PRIVATE) {
1850
if (!zend_check_private(fbc, (Z_TYPE_PP(obj) == IS_STRING)?EG(scope):(*obj)->value.obj.handlers->get_class_entry(*obj TSRMLS_CC), lcname, Z_STRLEN_PP(method) TSRMLS_CC)) {
1853
} else if ((fbc->common.fn_flags & ZEND_ACC_PROTECTED)) {
1854
if (!zend_check_protected(fbc->common.scope, EG(scope))) {
1860
/* check for __call too */
1861
if (retval == 0 && ce->__call != 0) {
1866
} else if (callable_name) {
1867
*callable_name = estrndup("Array", sizeof("Array")-1);
1873
if (callable_name) {
1877
zend_make_printable_zval(callable, &expr_copy, &use_copy);
1878
*callable_name = estrndup(Z_STRVAL(expr_copy), Z_STRLEN(expr_copy));
1879
zval_dtor(&expr_copy);
1888
ZEND_API zend_bool zend_make_callable(zval *callable, char **callable_name TSRMLS_DC)
1890
char *lcname, *func, *class_name;
1891
zend_bool retval = 0;
1892
zend_class_entry **pce;
1895
if (zend_is_callable(callable, 0, callable_name)) {
1898
switch (Z_TYPE_P(callable)) {
1900
lcname = zend_str_tolower_dup(Z_STRVAL_P(callable), Z_STRLEN_P(callable));
1902
if ((func = strstr(lcname, "::")) != NULL) {
1904
class_name_len = func - lcname;
1905
class_name = estrndup(Z_STRVAL_P(callable), class_name_len);
1906
if (zend_lookup_class(class_name, class_name_len, &pce TSRMLS_CC) == SUCCESS) {
1907
zval_dtor(callable);
1908
array_init(callable);
1909
add_next_index_stringl(callable, lcname, class_name_len, 1);
1911
add_next_index_stringl(callable, func, strlen(func), 1);
1923
ZEND_API char *zend_get_module_version(char *module_name)
1925
zend_module_entry *module;
1927
if (zend_hash_find(&module_registry, module_name, strlen(module_name) + 1,
1928
(void**)&module) == FAILURE) {
1931
return module->version;
1935
ZEND_API int zend_declare_property(zend_class_entry *ce, char *name, int name_length, zval *property, int access_type TSRMLS_DC)
1937
zend_property_info property_info;
1938
HashTable *target_symbol_table;
1940
if (!(access_type & ZEND_ACC_PPP_MASK)) {
1941
access_type |= ZEND_ACC_PUBLIC;
1943
if (access_type & ZEND_ACC_STATIC) {
1944
target_symbol_table = ce->static_members;
1946
target_symbol_table = &ce->default_properties;
1948
if (ce->type & ZEND_INTERNAL_CLASS) {
1949
switch(Z_TYPE_P(property)) {
1951
case IS_CONSTANT_ARRAY:
1954
zend_error(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources");
1960
switch (access_type & ZEND_ACC_PPP_MASK) {
1961
case ZEND_ACC_PRIVATE: {
1963
int priv_name_length;
1965
zend_mangle_property_name(&priv_name, &priv_name_length, ce->name, ce->name_length, name, name_length, ce->type & ZEND_INTERNAL_CLASS);
1966
zend_hash_update(target_symbol_table, priv_name, priv_name_length+1, &property, sizeof(zval *), NULL);
1967
property_info.name = priv_name;
1968
property_info.name_length = priv_name_length;
1971
case ZEND_ACC_PROTECTED: {
1973
int prot_name_length;
1975
zend_mangle_property_name(&prot_name, &prot_name_length, "*", 1, name, name_length, ce->type & ZEND_INTERNAL_CLASS);
1976
zend_hash_update(target_symbol_table, prot_name, prot_name_length+1, &property, sizeof(zval *), NULL);
1977
property_info.name = prot_name;
1978
property_info.name_length = prot_name_length;
1981
case ZEND_ACC_PUBLIC:
1984
int prot_name_length;
1986
zend_mangle_property_name(&prot_name, &prot_name_length, "*", 1, name, name_length, ce->type & ZEND_INTERNAL_CLASS);
1987
zend_hash_del(target_symbol_table, prot_name, prot_name_length+1);
1988
pefree(prot_name, ce->type & ZEND_INTERNAL_CLASS);
1990
zend_hash_update(target_symbol_table, name, name_length+1, &property, sizeof(zval *), NULL);
1991
property_info.name = ce->type & ZEND_INTERNAL_CLASS ? zend_strndup(name, name_length) : estrndup(name, name_length);
1992
property_info.name_length = name_length;
1995
property_info.flags = access_type;
1996
property_info.h = zend_get_hash_value(property_info.name, property_info.name_length+1);
1998
zend_hash_update(&ce->properties_info, name, name_length + 1, &property_info, sizeof(zend_property_info), NULL);
2003
ZEND_API int zend_declare_property_null(zend_class_entry *ce, char *name, int name_length, int access_type TSRMLS_DC)
2007
if (ce->type & ZEND_INTERNAL_CLASS) {
2008
property = malloc(sizeof(zval));
2010
ALLOC_ZVAL(property);
2012
INIT_ZVAL(*property);
2013
return zend_declare_property(ce, name, name_length, property, access_type TSRMLS_CC);
2016
ZEND_API int zend_declare_property_long(zend_class_entry *ce, char *name, int name_length, long value, int access_type TSRMLS_DC)
2020
if (ce->type & ZEND_INTERNAL_CLASS) {
2021
property = malloc(sizeof(zval));
2023
ALLOC_ZVAL(property);
2025
INIT_PZVAL(property);
2026
ZVAL_LONG(property, value);
2027
return zend_declare_property(ce, name, name_length, property, access_type TSRMLS_CC);
2030
ZEND_API int zend_declare_property_string(zend_class_entry *ce, char *name, int name_length, char *value, int access_type TSRMLS_DC)
2033
int len = strlen(value);
2035
if (ce->type & ZEND_INTERNAL_CLASS) {
2036
property = malloc(sizeof(zval));
2037
ZVAL_STRINGL(property, zend_strndup(value, len), len, 0);
2039
ALLOC_ZVAL(property);
2040
ZVAL_STRINGL(property, value, len, 1);
2042
INIT_PZVAL(property);
2043
return zend_declare_property(ce, name, name_length, property, access_type TSRMLS_CC);
2046
ZEND_API void zend_update_property(zend_class_entry *scope, zval *object, char *name, int name_length, zval *value TSRMLS_DC)
2049
zend_class_entry *old_scope = EG(scope);
2053
if (!Z_OBJ_HT_P(object)->write_property) {
2055
zend_uint class_name_len;
2057
zend_get_object_classname(object, &class_name, &class_name_len TSRMLS_CC);
2059
zend_error(E_CORE_ERROR, "Property %s of class %s cannot be updated", name, class_name);
2061
ZVAL_STRINGL(&property, name, name_length, 0);
2062
Z_OBJ_HT_P(object)->write_property(object, &property, value TSRMLS_CC);
2064
EG(scope) = old_scope;
2067
ZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, char *name, int name_length TSRMLS_DC)
2075
zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC);
2078
ZEND_API void zend_update_property_long(zend_class_entry *scope, zval *object, char *name, int name_length, long value TSRMLS_DC)
2085
ZVAL_LONG(tmp, value);
2086
zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC);
2089
ZEND_API void zend_update_property_string(zend_class_entry *scope, zval *object, char *name, int name_length, char *value TSRMLS_DC)
2096
ZVAL_STRING(tmp, value, 1);
2097
zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC);
2100
ZEND_API zval *zend_read_property(zend_class_entry *scope, zval *object, char *name, int name_length, zend_bool silent TSRMLS_DC)
2102
zval property, *value;
2103
zend_class_entry *old_scope = EG(scope);
2107
if (!Z_OBJ_HT_P(object)->read_property) {
2109
zend_uint class_name_len;
2111
zend_get_object_classname(object, &class_name, &class_name_len TSRMLS_CC);
2112
zend_error(E_CORE_ERROR, "Property %s of class %s cannot be read", name, class_name);
2114
ZVAL_STRINGL(&property, name, name_length, 0);
2115
value = Z_OBJ_HT_P(object)->read_property(object, &property, silent TSRMLS_CC);
2117
EG(scope) = old_scope;
2125
* indent-tabs-mode: t