@@ -1041,16 +1041,36 @@ PHP_FUNCTION(uksort)
1041
1041
}
1042
1042
/* }}} */
1043
1043
1044
+ static inline HashTable * get_ht_for_iap (zval * zv , bool separate ) {
1045
+ if (EXPECTED (Z_TYPE_P (zv ) == IS_ARRAY )) {
1046
+ return Z_ARRVAL_P (zv );
1047
+ }
1048
+
1049
+ ZEND_ASSERT (Z_TYPE_P (zv ) == IS_OBJECT );
1050
+ php_error_docref (NULL , E_DEPRECATED ,
1051
+ "Calling %s() on an object is deprecated" , get_active_function_name ());
1052
+
1053
+ zend_object * zobj = Z_OBJ_P (zv );
1054
+ if (separate && zobj -> properties && UNEXPECTED (GC_REFCOUNT (zobj -> properties ) > 1 )) {
1055
+ if (EXPECTED (!(GC_FLAGS (zobj -> properties ) & IS_ARRAY_IMMUTABLE ))) {
1056
+ GC_DELREF (zobj -> properties );
1057
+ }
1058
+ zobj -> properties = zend_array_dup (zobj -> properties );
1059
+ }
1060
+ return zobj -> handlers -> get_properties (zobj );
1061
+ }
1062
+
1044
1063
/* {{{ Advances array argument's internal pointer to the last element and return it */
1045
1064
PHP_FUNCTION (end )
1046
1065
{
1047
- HashTable * array ;
1066
+ zval * array_zv ;
1048
1067
zval * entry ;
1049
1068
1050
1069
ZEND_PARSE_PARAMETERS_START (1 , 1 )
1051
- Z_PARAM_ARRAY_OR_OBJECT_HT_EX ( array , 0 , 1 )
1070
+ Z_PARAM_ARRAY_OR_OBJECT_EX ( array_zv , 0 , 1 )
1052
1071
ZEND_PARSE_PARAMETERS_END ();
1053
1072
1073
+ HashTable * array = get_ht_for_iap (array_zv , /* separate */ true);
1054
1074
zend_hash_internal_pointer_end (array );
1055
1075
1056
1076
if (USED_RET ()) {
@@ -1070,13 +1090,14 @@ PHP_FUNCTION(end)
1070
1090
/* {{{ Move array argument's internal pointer to the previous element and return it */
1071
1091
PHP_FUNCTION (prev )
1072
1092
{
1073
- HashTable * array ;
1093
+ zval * array_zv ;
1074
1094
zval * entry ;
1075
1095
1076
1096
ZEND_PARSE_PARAMETERS_START (1 , 1 )
1077
- Z_PARAM_ARRAY_OR_OBJECT_HT_EX ( array , 0 , 1 )
1097
+ Z_PARAM_ARRAY_OR_OBJECT_EX ( array_zv , 0 , 1 )
1078
1098
ZEND_PARSE_PARAMETERS_END ();
1079
1099
1100
+ HashTable * array = get_ht_for_iap (array_zv , /* separate */ true);
1080
1101
zend_hash_move_backwards (array );
1081
1102
1082
1103
if (USED_RET ()) {
@@ -1096,13 +1117,14 @@ PHP_FUNCTION(prev)
1096
1117
/* {{{ Move array argument's internal pointer to the next element and return it */
1097
1118
PHP_FUNCTION (next )
1098
1119
{
1099
- HashTable * array ;
1120
+ zval * array_zv ;
1100
1121
zval * entry ;
1101
1122
1102
1123
ZEND_PARSE_PARAMETERS_START (1 , 1 )
1103
- Z_PARAM_ARRAY_OR_OBJECT_HT_EX ( array , 0 , 1 )
1124
+ Z_PARAM_ARRAY_OR_OBJECT_EX ( array_zv , 0 , 1 )
1104
1125
ZEND_PARSE_PARAMETERS_END ();
1105
1126
1127
+ HashTable * array = get_ht_for_iap (array_zv , /* separate */ true);
1106
1128
zend_hash_move_forward (array );
1107
1129
1108
1130
if (USED_RET ()) {
@@ -1122,13 +1144,14 @@ PHP_FUNCTION(next)
1122
1144
/* {{{ Set array argument's internal pointer to the first element and return it */
1123
1145
PHP_FUNCTION (reset )
1124
1146
{
1125
- HashTable * array ;
1147
+ zval * array_zv ;
1126
1148
zval * entry ;
1127
1149
1128
1150
ZEND_PARSE_PARAMETERS_START (1 , 1 )
1129
- Z_PARAM_ARRAY_OR_OBJECT_HT_EX ( array , 0 , 1 )
1151
+ Z_PARAM_ARRAY_OR_OBJECT_EX ( array_zv , 0 , 1 )
1130
1152
ZEND_PARSE_PARAMETERS_END ();
1131
1153
1154
+ HashTable * array = get_ht_for_iap (array_zv , /* separate */ true);
1132
1155
zend_hash_internal_pointer_reset (array );
1133
1156
1134
1157
if (USED_RET ()) {
@@ -1148,13 +1171,14 @@ PHP_FUNCTION(reset)
1148
1171
/* {{{ Return the element currently pointed to by the internal array pointer */
1149
1172
PHP_FUNCTION (current )
1150
1173
{
1151
- HashTable * array ;
1174
+ zval * array_zv ;
1152
1175
zval * entry ;
1153
1176
1154
1177
ZEND_PARSE_PARAMETERS_START (1 , 1 )
1155
- Z_PARAM_ARRAY_OR_OBJECT_HT ( array )
1178
+ Z_PARAM_ARRAY_OR_OBJECT ( array_zv )
1156
1179
ZEND_PARSE_PARAMETERS_END ();
1157
1180
1181
+ HashTable * array = get_ht_for_iap (array_zv , /* separate */ false);
1158
1182
if ((entry = zend_hash_get_current_data (array )) == NULL ) {
1159
1183
RETURN_FALSE ;
1160
1184
}
@@ -1170,12 +1194,13 @@ PHP_FUNCTION(current)
1170
1194
/* {{{ Return the key of the element currently pointed to by the internal array pointer */
1171
1195
PHP_FUNCTION (key )
1172
1196
{
1173
- HashTable * array ;
1197
+ zval * array_zv ;
1174
1198
1175
1199
ZEND_PARSE_PARAMETERS_START (1 , 1 )
1176
- Z_PARAM_ARRAY_OR_OBJECT_HT ( array )
1200
+ Z_PARAM_ARRAY_OR_OBJECT ( array_zv )
1177
1201
ZEND_PARSE_PARAMETERS_END ();
1178
1202
1203
+ HashTable * array = get_ht_for_iap (array_zv , /* separate */ false);
1179
1204
zend_hash_get_current_key_zval (array , return_value );
1180
1205
}
1181
1206
/* }}} */
0 commit comments