@@ -309,24 +309,56 @@ static zend_object *spl_fixedarray_object_clone(zend_object *old_object)
309
309
return new_object ;
310
310
}
311
311
312
+ static zend_long spl_offset_convert_to_long (zval * offset ) /* {{{ */
313
+ {
314
+ try_again :
315
+ switch (Z_TYPE_P (offset )) {
316
+ case IS_STRING : {
317
+ zend_ulong index ;
318
+ if (ZEND_HANDLE_NUMERIC (Z_STR_P (offset ), index )) {
319
+ return (zend_long ) index ;
320
+ }
321
+ break ;
322
+ }
323
+ case IS_DOUBLE :
324
+ return zend_dval_to_lval_safe (Z_DVAL_P (offset ));
325
+ case IS_LONG :
326
+ return Z_LVAL_P (offset );
327
+ case IS_FALSE :
328
+ return 0 ;
329
+ case IS_TRUE :
330
+ return 1 ;
331
+ case IS_REFERENCE :
332
+ offset = Z_REFVAL_P (offset );
333
+ goto try_again ;
334
+ case IS_RESOURCE :
335
+ zend_error (E_WARNING , "Resource ID#%d used as offset, casting to integer (%d)" ,
336
+ Z_RES_HANDLE_P (offset ), Z_RES_HANDLE_P (offset ));
337
+ return Z_RES_HANDLE_P (offset );
338
+ }
339
+
340
+ zend_type_error ("Illegal offset type" );
341
+ return 0 ;
342
+ }
343
+
312
344
static zval * spl_fixedarray_object_read_dimension_helper (spl_fixedarray_object * intern , zval * offset )
313
345
{
314
346
zend_long index ;
315
347
316
348
/* we have to return NULL on error here to avoid memleak because of
317
349
* ZE duplicating uninitialized_zval_ptr */
318
350
if (!offset ) {
319
- zend_throw_exception ( spl_ce_RuntimeException , "Index invalid or out of range" , 0 );
351
+ zend_throw_error ( NULL , "[] operator not supported for SplFixedArray" );
320
352
return NULL ;
321
353
}
322
354
323
- if (Z_TYPE_P (offset ) != IS_LONG ) {
324
- index = spl_offset_convert_to_long (offset );
325
- } else {
326
- index = Z_LVAL_P (offset );
355
+ index = spl_offset_convert_to_long (offset );
356
+ if (EG (exception )) {
357
+ return NULL ;
327
358
}
328
359
329
360
if (index < 0 || index >= intern -> array .size ) {
361
+ // TODO Change error message and use OutOfBound SPL Exception?
330
362
zend_throw_exception (spl_ce_RuntimeException , "Index invalid or out of range" , 0 );
331
363
return NULL ;
332
364
} else {
@@ -368,17 +400,17 @@ static void spl_fixedarray_object_write_dimension_helper(spl_fixedarray_object *
368
400
369
401
if (!offset ) {
370
402
/* '$array[] = value' syntax is not supported */
371
- zend_throw_exception ( spl_ce_RuntimeException , "Index invalid or out of range" , 0 );
403
+ zend_throw_error ( NULL , "[] operator not supported for SplFixedArray" );
372
404
return ;
373
405
}
374
406
375
- if (Z_TYPE_P (offset ) != IS_LONG ) {
376
- index = spl_offset_convert_to_long (offset );
377
- } else {
378
- index = Z_LVAL_P (offset );
407
+ index = spl_offset_convert_to_long (offset );
408
+ if (EG (exception )) {
409
+ return ;
379
410
}
380
411
381
412
if (index < 0 || index >= intern -> array .size ) {
413
+ // TODO Change error message and use OutOfBound SPL Exception?
382
414
zend_throw_exception (spl_ce_RuntimeException , "Index invalid or out of range" , 0 );
383
415
return ;
384
416
} else {
@@ -410,13 +442,13 @@ static void spl_fixedarray_object_unset_dimension_helper(spl_fixedarray_object *
410
442
{
411
443
zend_long index ;
412
444
413
- if (Z_TYPE_P (offset ) != IS_LONG ) {
414
- index = spl_offset_convert_to_long (offset );
415
- } else {
416
- index = Z_LVAL_P (offset );
445
+ index = spl_offset_convert_to_long (offset );
446
+ if (EG (exception )) {
447
+ return ;
417
448
}
418
449
419
450
if (index < 0 || index >= intern -> array .size ) {
451
+ // TODO Change error message and use OutOfBound SPL Exception?
420
452
zend_throw_exception (spl_ce_RuntimeException , "Index invalid or out of range" , 0 );
421
453
return ;
422
454
} else {
@@ -439,28 +471,24 @@ static void spl_fixedarray_object_unset_dimension(zend_object *object, zval *off
439
471
spl_fixedarray_object_unset_dimension_helper (intern , offset );
440
472
}
441
473
442
- static int spl_fixedarray_object_has_dimension_helper (spl_fixedarray_object * intern , zval * offset , int check_empty )
474
+ static bool spl_fixedarray_object_has_dimension_helper (spl_fixedarray_object * intern , zval * offset , bool check_empty )
443
475
{
444
476
zend_long index ;
445
- int retval ;
446
477
447
- if (Z_TYPE_P (offset ) != IS_LONG ) {
448
- index = spl_offset_convert_to_long (offset );
449
- } else {
450
- index = Z_LVAL_P (offset );
478
+ index = spl_offset_convert_to_long (offset );
479
+ if (EG (exception )) {
480
+ return false;
451
481
}
452
482
453
483
if (index < 0 || index >= intern -> array .size ) {
454
- retval = 0 ;
455
- } else {
456
- if (check_empty ) {
457
- retval = zend_is_true (& intern -> array .elements [index ]);
458
- } else {
459
- retval = Z_TYPE (intern -> array .elements [index ]) != IS_NULL ;
460
- }
484
+ return false;
485
+ }
486
+
487
+ if (check_empty ) {
488
+ return zend_is_true (& intern -> array .elements [index ]);
461
489
}
462
490
463
- return retval ;
491
+ return Z_TYPE ( intern -> array . elements [ index ]) != IS_NULL ;
464
492
}
465
493
466
494
static int spl_fixedarray_object_has_dimension (zend_object * object , zval * offset , int check_empty )
0 commit comments