Skip to content

Commit 45a0656

Browse files
committed
Remove get() object handler
Now that set() is gone, there is little point in keeping get(), as it is essentially just a different way of writing cast_object() now. Closes GH-4202.
1 parent 693955c commit 45a0656

14 files changed

+22
-190
lines changed

UPGRADING.INTERNALS

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ PHP 8.0 INTERNALS UPGRADE NOTES
44
a. Object Handlers API
55
b. ZEND_OVERLOADED_FUNCTION and corresponding call_method() object handler
66
c. TSRM changes
7-
d. set() object handler
7+
d. get() and set() object handlers
88

99
2. Build system changes
1010
a. Abstract
@@ -40,9 +40,12 @@ PHP 8.0 INTERNALS UPGRADE NOTES
4040
- tsrm_free_interpreter_context
4141
- support for GNUPTH, SGI ST, and BETHREADS
4242

43-
d. The set() object handler, which allowed overloading the assignment
44-
operator, has been removed. There is no direct replacement for this
45-
functionality, though some use-cases may be replaced by do_operation().
43+
d. The get() and set() object handlers have been removed. The get() handler
44+
can generally be replaced with cast_object(). Some uses of set() may be
45+
replaced by do_operation(). If set() was used to overload direct
46+
assignments using "=", then this is no longer supported and the
47+
functionality should be provided in some other way (for example, as
48+
modification of an object property).
4649

4750

4851
========================

Zend/zend_API.c

-16
Original file line numberDiff line numberDiff line change
@@ -438,22 +438,6 @@ ZEND_API int ZEND_FASTCALL zend_parse_arg_str_weak(zval *arg, zend_string **dest
438438
*dest = Z_STR_P(arg);
439439
return 1;
440440
}
441-
} else if (zobj->handlers->get) {
442-
zval rv;
443-
zval *z = zobj->handlers->get(zobj, &rv);
444-
445-
if (Z_TYPE_P(z) != IS_OBJECT) {
446-
OBJ_RELEASE(zobj);
447-
if (Z_TYPE_P(z) == IS_STRING) {
448-
ZVAL_COPY_VALUE(arg, z);
449-
} else {
450-
ZVAL_STR(arg, zval_get_string_func(z));
451-
zval_ptr_dtor(z);
452-
}
453-
*dest = Z_STR_P(arg);
454-
return 1;
455-
}
456-
zval_ptr_dtor(z);
457441
}
458442
return 0;
459443
} else {

Zend/zend_builtin_functions.c

+4-12
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,6 @@ ZEND_FUNCTION(define)
789789

790790
ZVAL_UNDEF(&val_free);
791791

792-
repeat:
793792
switch (Z_TYPE_P(val)) {
794793
case IS_LONG:
795794
case IS_DOUBLE:
@@ -810,17 +809,10 @@ ZEND_FUNCTION(define)
810809
}
811810
break;
812811
case IS_OBJECT:
813-
if (Z_TYPE(val_free) == IS_UNDEF) {
814-
if (Z_OBJ_HT_P(val)->get) {
815-
zval rv;
816-
val = Z_OBJ_HT_P(val)->get(Z_OBJ_P(val), &rv);
817-
ZVAL_COPY_VALUE(&val_free, val);
818-
goto repeat;
819-
} else if (Z_OBJ_HT_P(val)->cast_object) {
820-
if (Z_OBJ_HT_P(val)->cast_object(Z_OBJ_P(val), &val_free, IS_STRING) == SUCCESS) {
821-
val = &val_free;
822-
break;
823-
}
812+
if (Z_OBJ_HT_P(val)->cast_object) {
813+
if (Z_OBJ_HT_P(val)->cast_object(Z_OBJ_P(val), &val_free, IS_STRING) == SUCCESS) {
814+
val = &val_free;
815+
break;
824816
}
825817
}
826818
/* no break */

Zend/zend_execute.c

-36
Original file line numberDiff line numberDiff line change
@@ -1296,15 +1296,6 @@ static zend_never_inline void zend_binary_assign_op_obj_dim(zval *object, zval *
12961296

12971297
if ((z = Z_OBJ_HT_P(object)->read_dimension(Z_OBJ_P(object), property, BP_VAR_R, &rv)) != NULL) {
12981298

1299-
if (Z_TYPE_P(z) == IS_OBJECT && Z_OBJ_HT_P(z)->get) {
1300-
zval rv2;
1301-
zval *value = Z_OBJ_HT_P(z)->get(Z_OBJ_P(z), &rv2);
1302-
1303-
if (z == &rv) {
1304-
zval_ptr_dtor(&rv);
1305-
}
1306-
ZVAL_COPY_VALUE(z, value);
1307-
}
13081299
if (binary_op(&res, z, value) == SUCCESS) {
13091300
Z_OBJ_HT_P(object)->write_dimension(Z_OBJ_P(object), property, &res);
13101301
}
@@ -1783,15 +1774,6 @@ static zend_never_inline void zend_post_incdec_overloaded_property(zend_object *
17831774
return;
17841775
}
17851776

1786-
if (UNEXPECTED(Z_TYPE_P(z) == IS_OBJECT) && Z_OBJ_HT_P(z)->get) {
1787-
zval rv2;
1788-
zval *value = Z_OBJ_HT_P(z)->get(Z_OBJ_P(z), &rv2);
1789-
if (z == &rv) {
1790-
zval_ptr_dtor(&rv);
1791-
}
1792-
ZVAL_COPY_VALUE(z, value);
1793-
}
1794-
17951777
ZVAL_COPY_DEREF(&z_copy, z);
17961778
ZVAL_COPY(EX_VAR(opline->result.var), &z_copy);
17971779
if (inc) {
@@ -1821,15 +1803,6 @@ static zend_never_inline void zend_pre_incdec_overloaded_property(zend_object *o
18211803
return;
18221804
}
18231805

1824-
if (UNEXPECTED(Z_TYPE_P(z) == IS_OBJECT) && Z_OBJ_HT_P(z)->get) {
1825-
zval rv2;
1826-
zval *value = Z_OBJ_HT_P(z)->get(Z_OBJ_P(z), &rv2);
1827-
1828-
if (z == &rv) {
1829-
zval_ptr_dtor(&rv);
1830-
}
1831-
ZVAL_COPY_VALUE(z, value);
1832-
}
18331806
ZVAL_COPY_DEREF(&z_copy, z);
18341807
if (inc) {
18351808
increment_function(&z_copy);
@@ -1859,15 +1832,6 @@ static zend_never_inline void zend_assign_op_overloaded_property(zend_object *ob
18591832
}
18601833
return;
18611834
}
1862-
if (Z_TYPE_P(z) == IS_OBJECT && Z_OBJ_HT_P(z)->get) {
1863-
zval rv2;
1864-
zval *value = Z_OBJ_HT_P(z)->get(Z_OBJ_P(z), &rv2);
1865-
1866-
if (z == &rv) {
1867-
zval_ptr_dtor(&rv);
1868-
}
1869-
ZVAL_COPY_VALUE(z, value);
1870-
}
18711835
if (binary_op(&res, z, value) == SUCCESS) {
18721836
object->handlers->write_property(object, name, &res, cache_slot);
18731837
}

Zend/zend_iterators.c

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ static const zend_object_handlers iterator_object_handlers = {
3636
NULL, /* read dim */
3737
NULL, /* write dim */
3838
NULL,
39-
NULL, /* get */
4039
NULL, /* has prop */
4140
NULL, /* unset prop */
4241
NULL, /* has dim */

Zend/zend_object_handlers.c

-1
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,6 @@ ZEND_API const zend_object_handlers std_object_handlers = {
18371837
zend_std_read_dimension, /* read_dimension */
18381838
zend_std_write_dimension, /* write_dimension */
18391839
zend_std_get_property_ptr_ptr, /* get_property_ptr_ptr */
1840-
NULL, /* get */
18411840
zend_std_has_property, /* has_property */
18421841
zend_std_unset_property, /* unset_property */
18431842
zend_std_has_dimension, /* has_dimension */

Zend/zend_object_handlers.h

-6
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ typedef void (*zend_object_write_dimension_t)(zend_object *object, zval *offset,
6363
/* Used to create pointer to the property of the object, for future direct r/w access */
6464
typedef zval *(*zend_object_get_property_ptr_ptr_t)(zend_object *object, zend_string *member, int type, void **cache_slot);
6565

66-
/* Used to get object value. Can be used when converting object value to
67-
* one of the basic types and when using scalar ops (like ++, +=) on the object
68-
*/
69-
typedef zval* (*zend_object_get_t)(zend_object *object, zval *rv);
70-
7166
/* Used to check if a property of the object exists */
7267
/* param has_set_exists:
7368
* 0 (has) whether property exists and is not NULL
@@ -158,7 +153,6 @@ struct _zend_object_handlers {
158153
zend_object_read_dimension_t read_dimension; /* required */
159154
zend_object_write_dimension_t write_dimension; /* required */
160155
zend_object_get_property_ptr_ptr_t get_property_ptr_ptr; /* required */
161-
zend_object_get_t get; /* optional */
162156
zend_object_has_property_t has_property; /* required */
163157
zend_object_unset_property_t unset_property; /* required */
164158
zend_object_has_dimension_t has_dimension; /* required */

Zend/zend_operators.c

+3-42
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,6 @@ ZEND_API zend_long ZEND_FASTCALL zend_atol(const char *str, size_t str_len) /* {
143143
"Object of class %s could not be converted to %s", ZSTR_VAL(Z_OBJCE_P(op)->name),\
144144
zend_get_type_by_const(ctype)); \
145145
} \
146-
} else if (Z_OBJ_HT_P(op)->get) { \
147-
zval *newop = Z_OBJ_HT_P(op)->get(Z_OBJ_P(op), dst); \
148-
if (Z_TYPE_P(newop) != IS_OBJECT) { \
149-
/* for safety - avoid loop */ \
150-
ZVAL_COPY_VALUE(dst, newop); \
151-
conv_func(dst); \
152-
} \
153146
}
154147

155148
/* }}} */
@@ -866,14 +859,6 @@ ZEND_API zend_string* ZEND_FASTCALL zval_get_string_func(zval *op) /* {{{ */
866859
if (Z_OBJ_HT_P(op)->cast_object(Z_OBJ_P(op), &tmp, IS_STRING) == SUCCESS) {
867860
return Z_STR(tmp);
868861
}
869-
} else if (Z_OBJ_HT_P(op)->get) {
870-
zval *z = Z_OBJ_HT_P(op)->get(Z_OBJ_P(op), &tmp);
871-
if (Z_TYPE_P(z) != IS_OBJECT) {
872-
zend_string *str = zval_get_string(z);
873-
zval_ptr_dtor(z);
874-
return str;
875-
}
876-
zval_ptr_dtor(z);
877862
}
878863
zend_error(EG(exception) ? E_ERROR : E_RECOVERABLE_ERROR, "Object of class %s could not be converted to string", ZSTR_VAL(Z_OBJCE_P(op)->name));
879864
return ZSTR_EMPTY_ALLOC();
@@ -1969,8 +1954,7 @@ ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2)
19691954
{
19701955
int ret;
19711956
int converted = 0;
1972-
zval op1_copy, op2_copy;
1973-
zval *op_free, tmp_free;
1957+
zval op1_copy, op2_copy, tmp_free;
19741958

19751959
while (1) {
19761960
switch (TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2))) {
@@ -2076,13 +2060,7 @@ ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2)
20762060
}
20772061
}
20782062
if (Z_TYPE_P(op1) == IS_OBJECT) {
2079-
if (Z_OBJ_HT_P(op1)->get) {
2080-
zval rv;
2081-
op_free = Z_OBJ_HT_P(op1)->get(Z_OBJ_P(op1), &rv);
2082-
ret = compare_function(result, op_free, op2);
2083-
zend_free_obj_get_result(op_free);
2084-
return ret;
2085-
} else if (Z_TYPE_P(op2) != IS_OBJECT && Z_OBJ_HT_P(op1)->cast_object) {
2063+
if (Z_TYPE_P(op2) != IS_OBJECT && Z_OBJ_HT_P(op1)->cast_object) {
20862064
ZVAL_UNDEF(&tmp_free);
20872065
if (Z_OBJ_HT_P(op1)->cast_object(Z_OBJ_P(op1), &tmp_free, ((Z_TYPE_P(op2) == IS_FALSE || Z_TYPE_P(op2) == IS_TRUE) ? _IS_BOOL : Z_TYPE_P(op2))) == FAILURE) {
20882066
ZVAL_LONG(result, 1);
@@ -2095,13 +2073,7 @@ ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2)
20952073
}
20962074
}
20972075
if (Z_TYPE_P(op2) == IS_OBJECT) {
2098-
if (Z_OBJ_HT_P(op2)->get) {
2099-
zval rv;
2100-
op_free = Z_OBJ_HT_P(op2)->get(Z_OBJ_P(op2), &rv);
2101-
ret = compare_function(result, op1, op_free);
2102-
zend_free_obj_get_result(op_free);
2103-
return ret;
2104-
} else if (Z_TYPE_P(op1) != IS_OBJECT && Z_OBJ_HT_P(op2)->cast_object) {
2076+
if (Z_TYPE_P(op1) != IS_OBJECT && Z_OBJ_HT_P(op2)->cast_object) {
21052077
ZVAL_UNDEF(&tmp_free);
21062078
if (Z_OBJ_HT_P(op2)->cast_object(Z_OBJ_P(op2), &tmp_free, ((Z_TYPE_P(op1) == IS_FALSE || Z_TYPE_P(op1) == IS_TRUE) ? _IS_BOOL : Z_TYPE_P(op1))) == FAILURE) {
21072079
ZVAL_LONG(result, -1);
@@ -2549,17 +2521,6 @@ ZEND_API int ZEND_FASTCALL zend_object_is_true(zval *op) /* {{{ */
25492521
return Z_TYPE(tmp) == IS_TRUE;
25502522
}
25512523
zend_error(E_RECOVERABLE_ERROR, "Object of class %s could not be converted to bool", ZSTR_VAL(zobj->ce->name));
2552-
} else if (zobj->handlers->get) {
2553-
int result;
2554-
zval rv;
2555-
zval *tmp = zobj->handlers->get(zobj, &rv);
2556-
2557-
if (Z_TYPE_P(tmp) != IS_OBJECT) {
2558-
/* for safety - avoid loop */
2559-
result = i_zend_is_true(tmp);
2560-
zval_ptr_dtor(tmp);
2561-
return result;
2562-
}
25632524
}
25642525
return 1;
25652526
}

ext/com_dotnet/com_handlers.c

-9
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,6 @@ static void com_write_dimension(zend_object *object, zval *offset, zval *value)
174174
}
175175
}
176176

177-
#if 0
178-
static zval *com_object_get(zval *property)
179-
{
180-
/* Not yet implemented in the engine */
181-
return NULL;
182-
}
183-
#endif
184-
185177
static int com_property_exists(zend_object *object, zend_string *member, int check_empty, void **cache_slot)
186178
{
187179
DISPID dispid;
@@ -540,7 +532,6 @@ zend_object_handlers php_com_object_handlers = {
540532
com_read_dimension,
541533
com_write_dimension,
542534
NULL,
543-
NULL, /* com_object_get, */
544535
com_property_exists,
545536
com_property_delete,
546537
com_dimension_exists,

ext/com_dotnet/com_saproxy.c

-9
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,6 @@ static void saproxy_write_dimension(zend_object *object, zval *offset, zval *val
274274
}
275275
}
276276

277-
#if 0
278-
static zval *saproxy_object_get(zval *property)
279-
{
280-
/* Not yet implemented in the engine */
281-
return NULL;
282-
}
283-
#endif
284-
285277
static int saproxy_property_exists(zend_object *object, zend_string *member, int check_empty, void **cache_slot)
286278
{
287279
/* no properties */
@@ -397,7 +389,6 @@ zend_object_handlers php_com_saproxy_handlers = {
397389
saproxy_read_dimension,
398390
saproxy_write_dimension,
399391
NULL,
400-
NULL, /* saproxy_object_get, */
401392
saproxy_property_exists,
402393
saproxy_property_delete,
403394
saproxy_dimension_exists,

ext/ffi/ffi.c

-8
Original file line numberDiff line numberDiff line change
@@ -4610,13 +4610,6 @@ static ZEND_COLD void zend_ffi_free_unset_property(zend_object *obj, zend_string
46104610
}
46114611
/* }}} */
46124612

4613-
static zval* zend_ffi_free_get(zend_object *obj, zval *rv) /* {{{ */
4614-
{
4615-
zend_ffi_use_after_free();
4616-
return NULL;
4617-
}
4618-
/* }}} */
4619-
46204613
static HashTable *zend_ffi_free_get_debug_info(zend_object *obj, int *is_temp) /* {{{ */
46214614
{
46224615
zend_ffi_use_after_free();
@@ -4767,7 +4760,6 @@ ZEND_MINIT_FUNCTION(ffi)
47674760
zend_ffi_cdata_free_handlers.read_dimension = zend_ffi_free_read_dimension;
47684761
zend_ffi_cdata_free_handlers.write_dimension = zend_ffi_free_write_dimension;
47694762
zend_ffi_cdata_free_handlers.get_property_ptr_ptr = zend_fake_get_property_ptr_ptr;
4770-
zend_ffi_cdata_free_handlers.get = zend_ffi_free_get;
47714763
zend_ffi_cdata_free_handlers.has_property = zend_ffi_free_has_property;
47724764
zend_ffi_cdata_free_handlers.unset_property = zend_ffi_free_unset_property;
47734765
zend_ffi_cdata_free_handlers.has_dimension = zend_ffi_free_has_dimension;

ext/intl/collator/collator_convert.c

+1-23
Original file line numberDiff line numberDiff line change
@@ -226,29 +226,7 @@ zval* collator_convert_object_to_string( zval* obj, zval *rv )
226226
}
227227

228228
/* Try object's handlers. */
229-
if( Z_OBJ_HT_P(obj)->get )
230-
{
231-
zstr = Z_OBJ_HT_P(obj)->get( Z_OBJ_P(obj), rv );
232-
233-
switch( Z_TYPE_P( zstr ) )
234-
{
235-
case IS_OBJECT:
236-
{
237-
/* Bail out. */
238-
zval_ptr_dtor( zstr );
239-
COLLATOR_CONVERT_RETURN_FAILED( obj );
240-
} break;
241-
242-
case IS_STRING:
243-
break;
244-
245-
default:
246-
{
247-
convert_to_string( zstr );
248-
} break;
249-
}
250-
}
251-
else if( Z_OBJ_HT_P(obj)->cast_object )
229+
if( Z_OBJ_HT_P(obj)->cast_object )
252230
{
253231
zstr = rv;
254232

ext/opcache/jit/zend_jit_helpers.c

-9
Original file line numberDiff line numberDiff line change
@@ -968,15 +968,6 @@ static void ZEND_FASTCALL zend_jit_assign_dim_op_helper(zval *container, zval *d
968968
z = Z_OBJ_HT_P(object)->read_dimension(Z_OBJ_P(object), property, BP_VAR_R, &rv);
969969
if (z != NULL) {
970970

971-
if (Z_TYPE_P(z) == IS_OBJECT && Z_OBJ_HT_P(z)->get) {
972-
zval rv2;
973-
zval *value = Z_OBJ_HT_P(z)->get(Z_OBJ_P(z), &rv2);
974-
975-
if (z == &rv) {
976-
zval_ptr_dtor(&rv);
977-
}
978-
ZVAL_COPY_VALUE(z, value);
979-
}
980971
if (binary_op(&res, Z_ISREF_P(z) ? Z_REFVAL_P(z) : z, value) == SUCCESS) {
981972
Z_OBJ_HT_P(object)->write_dimension(Z_OBJ_P(object), property, &res);
982973
}

0 commit comments

Comments
 (0)