@@ -237,7 +237,7 @@ static zend_object *spl_fixedarray_object_new_ex(zend_class_entry *class_type, z
237
237
}
238
238
239
239
if (!parent ) { /* this must never happen */
240
- php_error_docref (NULL , E_COMPILE_ERROR , "Internal compiler error, Class is not child of SplFixedArray" );
240
+ zend_throw_error (NULL , "Internal compiler error, Class is not child of SplFixedArray" );
241
241
}
242
242
243
243
funcs_ptr = class_type -> iterator_funcs_ptr ;
@@ -307,25 +307,37 @@ static zend_object *spl_fixedarray_object_clone(zend_object *old_object) /* {{{
307
307
}
308
308
/* }}} */
309
309
310
- static inline zval * spl_fixedarray_object_read_dimension_helper (spl_fixedarray_object * intern , zval * offset ) /* {{{ */
310
+ static inline zval * spl_fixedarray_object_read_dimension_helper (spl_fixedarray_object * intern ,
311
+ zval * offset , uint32_t offset_arg_num ) /* {{{ */
311
312
{
312
313
zend_long index ;
313
314
314
315
/* we have to return NULL on error here to avoid memleak because of
315
316
* ZE duplicating uninitialized_zval_ptr */
316
317
if (!offset ) {
317
- zend_value_error ( "Index invalid or out of range " );
318
+ zend_throw_error ( NULL , "Must provided an index to read " );
318
319
return NULL ;
319
320
}
320
321
321
322
if (Z_TYPE_P (offset ) != IS_LONG ) {
322
323
index = spl_offset_convert_to_long (offset );
324
+ if (index == -1 ) {
325
+ if (offset_arg_num == 0 ) {
326
+ zend_value_error ("Offset must be numeric" );
327
+ } else {
328
+ zend_argument_value_error (offset_arg_num , "must be numeric" );
329
+ }
330
+ }
323
331
} else {
324
332
index = Z_LVAL_P (offset );
325
333
}
326
334
327
335
if (index < 0 || index >= intern -> array .size ) {
328
- zend_value_error ("Index invalid or out of range" );
336
+ if (offset_arg_num == 0 ) {
337
+ zend_value_error ("Offset is out of range" );
338
+ } else {
339
+ zend_argument_value_error (offset_arg_num , "is out of range" );
340
+ }
329
341
return NULL ;
330
342
} else {
331
343
return & intern -> array .elements [index ];
@@ -339,20 +351,20 @@ static zval *spl_fixedarray_object_read_dimension(zend_object *object, zval *off
339
351
{
340
352
spl_fixedarray_object * intern ;
341
353
354
+ if (!offset ) {
355
+ /* This emits a Notice
356
+ Indirect modification of overloaded element of SplFixedArray has no effect */
357
+ return & EG (uninitialized_zval );
358
+ }
359
+
342
360
intern = spl_fixed_array_from_obj (object );
343
361
344
362
if (type == BP_VAR_IS && !spl_fixedarray_object_has_dimension (object , offset , 0 )) {
345
363
return & EG (uninitialized_zval );
346
364
}
347
365
348
366
if (intern -> fptr_offset_get ) {
349
- zval tmp ;
350
- if (!offset ) {
351
- ZVAL_NULL (& tmp );
352
- offset = & tmp ;
353
- } else {
354
- SEPARATE_ARG_IF_REF (offset );
355
- }
367
+ SEPARATE_ARG_IF_REF (offset );
356
368
zend_call_method_with_1_params (object , intern -> std .ce , & intern -> fptr_offset_get , "offsetGet" , rv , offset );
357
369
zval_ptr_dtor (offset );
358
370
if (!Z_ISUNDEF_P (rv )) {
@@ -361,19 +373,16 @@ static zval *spl_fixedarray_object_read_dimension(zend_object *object, zval *off
361
373
return & EG (uninitialized_zval );
362
374
}
363
375
364
- return spl_fixedarray_object_read_dimension_helper (intern , offset );
376
+ return spl_fixedarray_object_read_dimension_helper (intern , offset , 0 );
365
377
}
366
378
/* }}} */
367
379
368
- static inline void spl_fixedarray_object_write_dimension_helper (spl_fixedarray_object * intern , zval * offset , zval * value ) /* {{{ */
380
+ static inline void spl_fixedarray_object_write_dimension_helper (spl_fixedarray_object * intern ,
381
+ zval * offset , zval * value , uint32_t offset_arg_num ) /* {{{ */
369
382
{
370
383
zend_long index ;
371
384
372
- if (!offset ) {
373
- /* '$array[] = value' syntax is not supported */
374
- zend_value_error ("Index invalid or out of range" );
375
- return ;
376
- }
385
+ ZEND_ASSERT (offset != NULL );
377
386
378
387
if (Z_TYPE_P (offset ) != IS_LONG ) {
379
388
index = spl_offset_convert_to_long (offset );
@@ -382,7 +391,11 @@ static inline void spl_fixedarray_object_write_dimension_helper(spl_fixedarray_o
382
391
}
383
392
384
393
if (index < 0 || index >= intern -> array .size ) {
385
- zend_value_error ("Index invalid or out of range" );
394
+ if (offset_arg_num == 0 ) {
395
+ zend_value_error ("Offset is out of range" );
396
+ } else {
397
+ zend_argument_value_error (offset_arg_num , "is out of range" );
398
+ }
386
399
return ;
387
400
} else {
388
401
zval_ptr_dtor (& (intern -> array .elements [index ]));
@@ -394,29 +407,30 @@ static inline void spl_fixedarray_object_write_dimension_helper(spl_fixedarray_o
394
407
static void spl_fixedarray_object_write_dimension (zend_object * object , zval * offset , zval * value ) /* {{{ */
395
408
{
396
409
spl_fixedarray_object * intern ;
397
- zval tmp ;
410
+
411
+ /* '$array[] = value' syntax is not supported */
412
+ if (!offset ) {
413
+ zend_throw_error (NULL , "Dynamic allocation is forbidden" );
414
+ return ;
415
+ }
398
416
399
417
intern = spl_fixed_array_from_obj (object );
400
418
401
419
if (intern -> fptr_offset_set ) {
402
- if (!offset ) {
403
- ZVAL_NULL (& tmp );
404
- offset = & tmp ;
405
- } else {
406
- SEPARATE_ARG_IF_REF (offset );
407
- }
420
+ SEPARATE_ARG_IF_REF (offset );
408
421
SEPARATE_ARG_IF_REF (value );
409
422
zend_call_method_with_2_params (object , intern -> std .ce , & intern -> fptr_offset_set , "offsetSet" , NULL , offset , value );
410
423
zval_ptr_dtor (value );
411
424
zval_ptr_dtor (offset );
412
425
return ;
413
426
}
414
427
415
- spl_fixedarray_object_write_dimension_helper (intern , offset , value );
428
+ spl_fixedarray_object_write_dimension_helper (intern , offset , value , 0 );
416
429
}
417
430
/* }}} */
418
431
419
- static inline void spl_fixedarray_object_unset_dimension_helper (spl_fixedarray_object * intern , zval * offset ) /* {{{ */
432
+ static inline void spl_fixedarray_object_unset_dimension_helper (spl_fixedarray_object * intern ,
433
+ zval * offset , uint32_t offset_arg_num ) /* {{{ */
420
434
{
421
435
zend_long index ;
422
436
@@ -427,7 +441,11 @@ static inline void spl_fixedarray_object_unset_dimension_helper(spl_fixedarray_o
427
441
}
428
442
429
443
if (index < 0 || index >= intern -> array .size ) {
430
- zend_value_error ("Index invalid or out of range" );
444
+ if (offset_arg_num == 0 ) {
445
+ zend_value_error ("Offset is out of range" );
446
+ } else {
447
+ zend_argument_value_error (offset_arg_num , "is out of range" );
448
+ }
431
449
return ;
432
450
} else {
433
451
zval_ptr_dtor (& (intern -> array .elements [index ]));
@@ -449,7 +467,7 @@ static void spl_fixedarray_object_unset_dimension(zend_object *object, zval *off
449
467
return ;
450
468
}
451
469
452
- spl_fixedarray_object_unset_dimension_helper (intern , offset );
470
+ spl_fixedarray_object_unset_dimension_helper (intern , offset , 0 );
453
471
}
454
472
/* }}} */
455
473
@@ -527,14 +545,14 @@ SPL_METHOD(SplFixedArray, __construct)
527
545
{
528
546
zval * object = ZEND_THIS ;
529
547
spl_fixedarray_object * intern ;
530
- zend_long size = 0 ;
548
+ zend_long size = 1 ;
531
549
532
550
if (zend_parse_parameters (ZEND_NUM_ARGS (), "|l" , & size ) == FAILURE ) {
533
551
RETURN_THROWS ();
534
552
}
535
553
536
- if (size < 0 ) {
537
- zend_value_error ( "array size cannot be less than zero " );
554
+ if (size <= 0 ) {
555
+ zend_argument_value_error ( 1 , "must be greater than 0 " );
538
556
RETURN_THROWS ();
539
557
}
540
558
@@ -645,6 +663,7 @@ SPL_METHOD(SplFixedArray, fromArray)
645
663
646
664
ZEND_HASH_FOREACH_KEY (Z_ARRVAL_P (data ), num_index , str_index ) {
647
665
if (str_index != NULL || (zend_long )num_index < 0 ) {
666
+ /* TODO Better error message? */
648
667
zend_value_error ("array must contain only positive integer keys" );
649
668
RETURN_THROWS ();
650
669
}
@@ -656,7 +675,7 @@ SPL_METHOD(SplFixedArray, fromArray)
656
675
657
676
tmp = max_index + 1 ;
658
677
if (tmp <= 0 ) {
659
- zend_throw_exception_ex ( spl_ce_InvalidArgumentException , 0 , "integer overflow detected" );
678
+ zend_throw_error ( NULL , "Integer overflow detected" );
660
679
RETURN_THROWS ();
661
680
}
662
681
spl_fixedarray_init (& array , tmp );
@@ -714,8 +733,8 @@ SPL_METHOD(SplFixedArray, setSize)
714
733
RETURN_THROWS ();
715
734
}
716
735
717
- if (size < 0 ) {
718
- zend_value_error ( "array size cannot be less than zero " );
736
+ if (size <= 0 ) {
737
+ zend_argument_value_error ( 1 , "must be greater than 0 " );
719
738
RETURN_THROWS ();
720
739
}
721
740
@@ -754,7 +773,7 @@ SPL_METHOD(SplFixedArray, offsetGet)
754
773
}
755
774
756
775
intern = Z_SPLFIXEDARRAY_P (ZEND_THIS );
757
- value = spl_fixedarray_object_read_dimension_helper (intern , zindex );
776
+ value = spl_fixedarray_object_read_dimension_helper (intern , zindex , 1 );
758
777
759
778
if (value ) {
760
779
ZVAL_COPY_DEREF (return_value , value );
@@ -775,7 +794,7 @@ SPL_METHOD(SplFixedArray, offsetSet)
775
794
}
776
795
777
796
intern = Z_SPLFIXEDARRAY_P (ZEND_THIS );
778
- spl_fixedarray_object_write_dimension_helper (intern , zindex , value );
797
+ spl_fixedarray_object_write_dimension_helper (intern , zindex , value , 1 );
779
798
780
799
} /* }}} */
781
800
@@ -791,7 +810,7 @@ SPL_METHOD(SplFixedArray, offsetUnset)
791
810
}
792
811
793
812
intern = Z_SPLFIXEDARRAY_P (ZEND_THIS );
794
- spl_fixedarray_object_unset_dimension_helper (intern , zindex );
813
+ spl_fixedarray_object_unset_dimension_helper (intern , zindex , 1 );
795
814
796
815
} /* }}} */
797
816
@@ -844,7 +863,7 @@ static zval *spl_fixedarray_it_get_current_data(zend_object_iterator *iter) /* {
844
863
845
864
ZVAL_LONG (& zindex , object -> current );
846
865
847
- data = spl_fixedarray_object_read_dimension_helper (object , & zindex );
866
+ data = spl_fixedarray_object_read_dimension_helper (object , & zindex , 0 );
848
867
849
868
if (data == NULL ) {
850
869
data = & EG (uninitialized_zval );
@@ -948,7 +967,7 @@ SPL_METHOD(SplFixedArray, current)
948
967
949
968
ZVAL_LONG (& zindex , intern -> current );
950
969
951
- value = spl_fixedarray_object_read_dimension_helper (intern , & zindex );
970
+ value = spl_fixedarray_object_read_dimension_helper (intern , & zindex , 0 );
952
971
953
972
if (value ) {
954
973
ZVAL_COPY_DEREF (return_value , value );
@@ -974,7 +993,7 @@ zend_object_iterator *spl_fixedarray_get_iterator(zend_class_entry *ce, zval *ob
974
993
spl_fixedarray_it * iterator ;
975
994
976
995
if (by_ref ) {
977
- zend_throw_exception ( spl_ce_RuntimeException , "An iterator cannot be used with foreach by reference" , 0 );
996
+ zend_throw_error ( NULL , "An iterator cannot be used with foreach by reference" );
978
997
return NULL ;
979
998
}
980
999
0 commit comments