@@ -298,7 +298,7 @@ static zval *spl_array_get_dimension_ptr(int check_inherited, spl_array_object *
298
298
}
299
299
300
300
if ((type == BP_VAR_W || type == BP_VAR_RW ) && intern -> nApplyCount > 0 ) {
301
- zend_error ( E_WARNING , "Modification of ArrayObject during sorting is prohibited" );
301
+ zend_throw_error ( NULL , "Modification of ArrayObject during sorting is prohibited" );
302
302
return & EG (error_zval );
303
303
}
304
304
@@ -386,9 +386,8 @@ static zval *spl_array_get_dimension_ptr(int check_inherited, spl_array_object *
386
386
ZVAL_DEREF (offset );
387
387
goto try_again ;
388
388
default :
389
- zend_error (E_WARNING , "Illegal offset type" );
390
- return (type == BP_VAR_W || type == BP_VAR_RW ) ?
391
- & EG (error_zval ) : & EG (uninitialized_zval );
389
+ zend_type_error ("Must be int|string, %s given" , zend_zval_type_name (offset ));
390
+ return NULL ;
392
391
}
393
392
} /* }}} */
394
393
@@ -446,7 +445,8 @@ static zval *spl_array_read_dimension(zend_object *object, zval *offset, int typ
446
445
return spl_array_read_dimension_ex (1 , object , offset , type , rv );
447
446
} /* }}} */
448
447
449
- static void spl_array_write_dimension_ex (int check_inherited , zend_object * object , zval * offset , zval * value ) /* {{{ */
448
+ static void spl_array_write_dimension_ex (int check_inherited , zend_object * object ,
449
+ zval * offset , zval * value , uint32_t offset_arg_num ) /* {{{ */
450
450
{
451
451
spl_array_object * intern = spl_array_from_obj (object );
452
452
zend_long index ;
@@ -467,7 +467,7 @@ static void spl_array_write_dimension_ex(int check_inherited, zend_object *objec
467
467
}
468
468
469
469
if (intern -> nApplyCount > 0 ) {
470
- zend_error ( E_WARNING , "Modification of ArrayObject during sorting is prohibited" );
470
+ zend_throw_error ( NULL , "Modification of ArrayObject during sorting is prohibited" );
471
471
return ;
472
472
}
473
473
@@ -510,15 +510,23 @@ static void spl_array_write_dimension_ex(int check_inherited, zend_object *objec
510
510
ZVAL_DEREF (offset );
511
511
goto try_again ;
512
512
default :
513
- zend_error (E_WARNING , "Illegal offset type" );
514
513
zval_ptr_dtor (value );
514
+ /* If offset_arg_num is 0 this mean the offset comes from an index use in [offset] */
515
+ if (offset_arg_num == 0 ) {
516
+ zend_type_error ("Offsets must be int|string, %s given" ,
517
+ zend_zval_type_name (offset ));
518
+ } else {
519
+ zend_argument_type_error (offset_arg_num , "must be int|string, %s given" ,
520
+ zend_zval_type_name (offset ));
521
+ }
515
522
return ;
516
523
}
517
524
} /* }}} */
518
525
519
526
static void spl_array_write_dimension (zend_object * object , zval * offset , zval * value ) /* {{{ */
520
527
{
521
- spl_array_write_dimension_ex (1 , object , offset , value );
528
+ /* Pass 0 as offset arg position to inform it comes from this handler */
529
+ spl_array_write_dimension_ex (1 , object , offset , value , 0 );
522
530
} /* }}} */
523
531
524
532
static void spl_array_unset_dimension_ex (int check_inherited , zend_object * object , zval * offset ) /* {{{ */
@@ -535,7 +543,7 @@ static void spl_array_unset_dimension_ex(int check_inherited, zend_object *objec
535
543
}
536
544
537
545
if (intern -> nApplyCount > 0 ) {
538
- zend_error ( E_WARNING , "Modification of ArrayObject during sorting is prohibited" );
546
+ zend_throw_error ( NULL , "Modification of ArrayObject during sorting is prohibited" );
539
547
return ;
540
548
}
541
549
@@ -596,7 +604,7 @@ static void spl_array_unset_dimension_ex(int check_inherited, zend_object *objec
596
604
ZVAL_DEREF (offset );
597
605
goto try_again ;
598
606
default :
599
- zend_error ( E_WARNING , "Illegal offset type" );
607
+ zend_type_error ( "Must be int|string, %s given" , zend_zval_type_name ( offset ) );
600
608
return ;
601
609
}
602
610
} /* }}} */
@@ -672,7 +680,7 @@ static int spl_array_has_dimension_ex(int check_inherited, zend_object *object,
672
680
ZVAL_DEREF (offset );
673
681
goto try_again ;
674
682
default :
675
- zend_error ( E_WARNING , "Illegal offset type" );
683
+ zend_type_error ( "Must be int|string, %s given" , zend_zval_type_name ( offset ) );
676
684
return 0 ;
677
685
}
678
686
@@ -733,7 +741,7 @@ SPL_METHOD(Array, offsetSet)
733
741
if (zend_parse_parameters (ZEND_NUM_ARGS (), "zz" , & index , & value ) == FAILURE ) {
734
742
RETURN_THROWS ();
735
743
}
736
- spl_array_write_dimension_ex (0 , Z_OBJ_P (ZEND_THIS ), index , value );
744
+ spl_array_write_dimension_ex (0 , Z_OBJ_P (ZEND_THIS ), index , value , 1 );
737
745
} /* }}} */
738
746
739
747
void spl_array_iterator_append (zval * object , zval * append_value ) /* {{{ */
@@ -1103,9 +1111,13 @@ static void spl_array_it_rewind(zend_object_iterator *iter) /* {{{ */
1103
1111
/* }}} */
1104
1112
1105
1113
/* {{{ spl_array_set_array */
1106
- static void spl_array_set_array (zval * object , spl_array_object * intern , zval * array , zend_long ar_flags , int just_array ) {
1114
+ static void spl_array_set_array (zval * object , spl_array_object * intern , zval * array ,
1115
+ zend_long ar_flags , int just_array , uint32_t arg_num ) {
1107
1116
if (Z_TYPE_P (array ) != IS_OBJECT && Z_TYPE_P (array ) != IS_ARRAY ) {
1108
- zend_type_error ("Passed variable is not an array or object" );
1117
+ if (arg_num == 0 ) {
1118
+ zend_type_error ("Passed variable must be array|object, %s given" , zend_zval_type_name (array ));
1119
+ }
1120
+ zend_argument_type_error (arg_num , "must be array|object, %s given" , zend_zval_type_name (array ));
1109
1121
return ;
1110
1122
}
1111
1123
@@ -1134,8 +1146,13 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval *ar
1134
1146
} else {
1135
1147
zend_object_get_properties_t handler = Z_OBJ_HANDLER_P (array , get_properties );
1136
1148
if (handler != zend_std_get_properties ) {
1137
- zend_type_error ("Overloaded object of type %s is not compatible with %s" ,
1138
- ZSTR_VAL (Z_OBJCE_P (array )-> name ), ZSTR_VAL (intern -> std .ce -> name ));
1149
+ if (arg_num == 0 ) {
1150
+ zend_type_error ("Overloaded object of type %s must be compatible with %s" ,
1151
+ ZSTR_VAL (Z_OBJCE_P (array )-> name ), ZSTR_VAL (intern -> std .ce -> name ));
1152
+ } else {
1153
+ zend_argument_type_error (arg_num , "must be compatible with %s" ,
1154
+ ZSTR_VAL (intern -> std .ce -> name ));
1155
+ }
1139
1156
return ;
1140
1157
}
1141
1158
zval_ptr_dtor (& intern -> array );
@@ -1166,7 +1183,7 @@ zend_object_iterator *spl_array_get_iterator(zend_class_entry *ce, zval *object,
1166
1183
spl_array_object * array_object = Z_SPLARRAY_P (object );
1167
1184
1168
1185
if (by_ref && (array_object -> ar_flags & SPL_ARRAY_OVERLOADED_CURRENT )) {
1169
- zend_throw_exception ( spl_ce_RuntimeException , "An iterator cannot be used with foreach by reference" , 0 );
1186
+ zend_throw_error ( NULL , "An iterator cannot be used with foreach by reference" );
1170
1187
return NULL ;
1171
1188
}
1172
1189
@@ -1210,7 +1227,7 @@ SPL_METHOD(Array, __construct)
1210
1227
1211
1228
ar_flags &= ~SPL_ARRAY_INT_MASK ;
1212
1229
1213
- spl_array_set_array (object , intern , array , ar_flags , ZEND_NUM_ARGS () == 1 );
1230
+ spl_array_set_array (object , intern , array , ar_flags , ZEND_NUM_ARGS () == 1 , 1 );
1214
1231
}
1215
1232
/* }}} */
1216
1233
@@ -1235,7 +1252,7 @@ SPL_METHOD(ArrayIterator, __construct)
1235
1252
1236
1253
ar_flags &= ~SPL_ARRAY_INT_MASK ;
1237
1254
1238
- spl_array_set_array (object , intern , array , ar_flags , ZEND_NUM_ARGS () == 1 );
1255
+ spl_array_set_array (object , intern , array , ar_flags , ZEND_NUM_ARGS () == 1 , 1 );
1239
1256
}
1240
1257
/* }}} */
1241
1258
@@ -1314,12 +1331,12 @@ SPL_METHOD(Array, exchangeArray)
1314
1331
}
1315
1332
1316
1333
if (intern -> nApplyCount > 0 ) {
1317
- zend_error ( E_WARNING , "Modification of ArrayObject during sorting is prohibited" );
1334
+ zend_throw_error ( NULL , "Modification of ArrayObject during sorting is prohibited" );
1318
1335
return ;
1319
1336
}
1320
1337
1321
1338
RETVAL_ARR (zend_array_dup (spl_array_get_hash_table (intern )));
1322
- spl_array_set_array (object , intern , array , 0L , 1 );
1339
+ spl_array_set_array (object , intern , array , 0L , 1 , 1 );
1323
1340
}
1324
1341
/* }}} */
1325
1342
@@ -1379,7 +1396,8 @@ SPL_METHOD(Array, seek)
1379
1396
return ; /* ok */
1380
1397
}
1381
1398
}
1382
- zend_value_error ("Seek position " ZEND_LONG_FMT " is out of range" , opos );
1399
+ zend_argument_value_error (1 , "position " ZEND_LONG_FMT " is out of range" , opos );
1400
+ RETURN_THROWS ();
1383
1401
} /* }}} */
1384
1402
1385
1403
static zend_long spl_array_object_count_elements_helper (spl_array_object * intern ) /* {{{ */
@@ -1731,7 +1749,7 @@ SPL_METHOD(Array, unserialize)
1731
1749
}
1732
1750
1733
1751
if (intern -> nApplyCount > 0 ) {
1734
- zend_error ( E_WARNING , "Modification of ArrayObject during sorting is prohibited" );
1752
+ zend_throw_error ( NULL , "Modification of ArrayObject during sorting is prohibited" );
1735
1753
return ;
1736
1754
}
1737
1755
@@ -1787,7 +1805,7 @@ SPL_METHOD(Array, unserialize)
1787
1805
ZVAL_NULL (array );
1788
1806
SEPARATE_ARRAY (& intern -> array );
1789
1807
} else {
1790
- spl_array_set_array (object , intern , array , 0L , 1 );
1808
+ spl_array_set_array (object , intern , array , 0L , 1 , 0 );
1791
1809
}
1792
1810
1793
1811
if (* p != ';' ) {
@@ -1816,6 +1834,7 @@ SPL_METHOD(Array, unserialize)
1816
1834
1817
1835
outexcept :
1818
1836
PHP_VAR_UNSERIALIZE_DESTROY (var_hash );
1837
+ /* TODO Use standard Error? */
1819
1838
zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 , "Error at offset " ZEND_LONG_FMT " of %zd bytes" , (zend_long )((char * )p - buf ), buf_len );
1820
1839
RETURN_THROWS ();
1821
1840
@@ -1883,7 +1902,7 @@ SPL_METHOD(Array, __unserialize)
1883
1902
zval_ptr_dtor (& intern -> array );
1884
1903
ZVAL_UNDEF (& intern -> array );
1885
1904
} else {
1886
- spl_array_set_array (ZEND_THIS , intern , storage_zv , 0L , 1 );
1905
+ spl_array_set_array (ZEND_THIS , intern , storage_zv , 0L , 1 , 0 );
1887
1906
}
1888
1907
1889
1908
object_properties_load (& intern -> std , Z_ARRVAL_P (members_zv ));
0 commit comments