@@ -650,6 +650,28 @@ static int spl_array_has_dimension(zval *object, zval *offset, int check_empty T
650
650
return spl_array_has_dimension_ex (1 , object , offset , check_empty TSRMLS_CC );
651
651
} /* }}} */
652
652
653
+ /* {{{ spl_array_object_verify_pos_ex */
654
+ static inline int spl_array_object_verify_pos_ex (spl_array_object * object , HashTable * ht , const char * msg_prefix TSRMLS_DC )
655
+ {
656
+ if (!ht ) {
657
+ php_error_docref (NULL TSRMLS_CC , E_NOTICE , "%sArray was modified outside object and is no longer an array" , msg_prefix );
658
+ return FAILURE ;
659
+ }
660
+
661
+ if (object -> pos && (object -> ar_flags & SPL_ARRAY_IS_REF ) && spl_hash_verify_pos_ex (object , ht TSRMLS_CC ) == FAILURE ) {
662
+ php_error_docref (NULL TSRMLS_CC , E_NOTICE , "%sArray was modified outside object and internal position is no longer valid" , msg_prefix );
663
+ return FAILURE ;
664
+ }
665
+
666
+ return SUCCESS ;
667
+ } /* }}} */
668
+
669
+ /* {{{ spl_array_object_verify_pos */
670
+ static inline int spl_array_object_verify_pos (spl_array_object * object , HashTable * ht TSRMLS_DC )
671
+ {
672
+ return spl_array_object_verify_pos_ex (object , ht , "" TSRMLS_CC );
673
+ } /* }}} */
674
+
653
675
/* {{{ proto bool ArrayObject::offsetExists(mixed $index)
654
676
proto bool ArrayIterator::offsetExists(mixed $index)
655
677
Returns whether the requested $index exists. */
@@ -963,17 +985,11 @@ static int spl_array_it_valid(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
963
985
if (object -> ar_flags & SPL_ARRAY_OVERLOADED_VALID ) {
964
986
return zend_user_it_valid (iter TSRMLS_CC );
965
987
} else {
966
- if (!aht ) {
967
- php_error_docref (NULL TSRMLS_CC , E_NOTICE , "ArrayIterator::valid(): Array was modified outside object and is no longer an array" );
968
- return FAILURE ;
969
- }
970
-
971
- if (object -> pos && (object -> ar_flags & SPL_ARRAY_IS_REF ) && spl_hash_verify_pos_ex (object , aht TSRMLS_CC ) == FAILURE ) {
972
- php_error_docref (NULL TSRMLS_CC , E_NOTICE , "ArrayIterator::valid(): Array was modified outside object and internal position is no longer valid" );
988
+ if (spl_array_object_verify_pos_ex (object , aht , "ArrayIterator::valid(): " TSRMLS_CC ) == FAILURE ) {
973
989
return FAILURE ;
974
- } else {
975
- return zend_hash_has_more_elements_ex (aht , & object -> pos );
976
990
}
991
+
992
+ return zend_hash_has_more_elements_ex (aht , & object -> pos );
977
993
}
978
994
}
979
995
/* }}} */
@@ -1003,13 +1019,7 @@ static int spl_array_it_get_current_key(zend_object_iterator *iter, char **str_k
1003
1019
if (object -> ar_flags & SPL_ARRAY_OVERLOADED_KEY ) {
1004
1020
return zend_user_it_get_current_key (iter , str_key , str_key_len , int_key TSRMLS_CC );
1005
1021
} else {
1006
- if (!aht ) {
1007
- php_error_docref (NULL TSRMLS_CC , E_NOTICE , "ArrayIterator::current(): Array was modified outside object and is no longer an array" );
1008
- return HASH_KEY_NON_EXISTANT ;
1009
- }
1010
-
1011
- if ((object -> ar_flags & SPL_ARRAY_IS_REF ) && spl_hash_verify_pos_ex (object , aht TSRMLS_CC ) == FAILURE ) {
1012
- php_error_docref (NULL TSRMLS_CC , E_NOTICE , "ArrayIterator::current(): Array was modified outside object and internal position is no longer valid" );
1022
+ if (spl_array_object_verify_pos_ex (object , aht , "ArrayIterator::current(): " TSRMLS_CC ) == FAILURE ) {
1013
1023
return HASH_KEY_NON_EXISTANT ;
1014
1024
}
1015
1025
@@ -1494,13 +1504,7 @@ SPL_METHOD(Array, current)
1494
1504
return ;
1495
1505
}
1496
1506
1497
- if (!aht ) {
1498
- php_error_docref (NULL TSRMLS_CC , E_NOTICE , "Array was modified outside object and is no longer an array" );
1499
- return ;
1500
- }
1501
-
1502
- if ((intern -> ar_flags & SPL_ARRAY_IS_REF ) && spl_hash_verify_pos_ex (intern , aht TSRMLS_CC ) == FAILURE ) {
1503
- php_error_docref (NULL TSRMLS_CC , E_NOTICE , "Array was modified outside object and internal position is no longer valid" );
1507
+ if (spl_array_object_verify_pos (intern , aht TSRMLS_CC ) == FAILURE ) {
1504
1508
return ;
1505
1509
}
1506
1510
@@ -1530,13 +1534,7 @@ void spl_array_iterator_key(zval *object, zval *return_value TSRMLS_DC) /* {{{ *
1530
1534
ulong num_key ;
1531
1535
HashTable * aht = spl_array_get_hash_table (intern , 0 TSRMLS_CC );
1532
1536
1533
- if (!aht ) {
1534
- php_error_docref (NULL TSRMLS_CC , E_NOTICE , "Array was modified outside object and is no longer an array" );
1535
- return ;
1536
- }
1537
-
1538
- if ((intern -> ar_flags & SPL_ARRAY_IS_REF ) && spl_hash_verify_pos_ex (intern , aht TSRMLS_CC ) == FAILURE ) {
1539
- php_error_docref (NULL TSRMLS_CC , E_NOTICE , "Array was modified outside object and internal position is no longer valid" );
1537
+ if (spl_array_object_verify_pos (intern , aht TSRMLS_CC ) == FAILURE ) {
1540
1538
return ;
1541
1539
}
1542
1540
@@ -1564,13 +1562,12 @@ SPL_METHOD(Array, next)
1564
1562
if (zend_parse_parameters_none () == FAILURE ) {
1565
1563
return ;
1566
1564
}
1567
-
1568
- if (!aht ) {
1569
- php_error_docref (NULL TSRMLS_CC , E_NOTICE , "Array was modified outside object and is no longer an array" );
1565
+
1566
+ if (spl_array_object_verify_pos (intern , aht TSRMLS_CC ) == FAILURE ) {
1570
1567
return ;
1571
1568
}
1572
1569
1573
- spl_array_next_ex (intern , aht TSRMLS_CC );
1570
+ spl_array_next_no_verify (intern , aht TSRMLS_CC );
1574
1571
}
1575
1572
/* }}} */
1576
1573
@@ -1585,14 +1582,8 @@ SPL_METHOD(Array, valid)
1585
1582
if (zend_parse_parameters_none () == FAILURE ) {
1586
1583
return ;
1587
1584
}
1588
-
1589
- if (!aht ) {
1590
- php_error_docref (NULL TSRMLS_CC , E_NOTICE , "Array was modified outside object and is no longer an array" );
1591
- return ;
1592
- }
1593
1585
1594
- if (intern -> pos && (intern -> ar_flags & SPL_ARRAY_IS_REF ) && spl_hash_verify_pos_ex (intern , aht TSRMLS_CC ) == FAILURE ) {
1595
- php_error_docref (NULL TSRMLS_CC , E_NOTICE , "Array was modified outside object and internal position is no longer valid" );
1586
+ if (spl_array_object_verify_pos (intern , aht TSRMLS_CC ) == FAILURE ) {
1596
1587
RETURN_FALSE ;
1597
1588
} else {
1598
1589
RETURN_BOOL (zend_hash_has_more_elements_ex (aht , & intern -> pos ) == SUCCESS );
@@ -1611,14 +1602,8 @@ SPL_METHOD(Array, hasChildren)
1611
1602
if (zend_parse_parameters_none () == FAILURE ) {
1612
1603
return ;
1613
1604
}
1614
-
1615
- if (!aht ) {
1616
- php_error_docref (NULL TSRMLS_CC , E_NOTICE , "Array was modified outside object and is no longer an array" );
1617
- RETURN_FALSE ;
1618
- }
1619
1605
1620
- if ((intern -> ar_flags & SPL_ARRAY_IS_REF ) && spl_hash_verify_pos_ex (intern , aht TSRMLS_CC ) == FAILURE ) {
1621
- php_error_docref (NULL TSRMLS_CC , E_NOTICE , "Array was modified outside object and internal position is no longer valid" );
1606
+ if (spl_array_object_verify_pos (intern , aht TSRMLS_CC ) == FAILURE ) {
1622
1607
RETURN_FALSE ;
1623
1608
}
1624
1609
@@ -1642,13 +1627,7 @@ SPL_METHOD(Array, getChildren)
1642
1627
return ;
1643
1628
}
1644
1629
1645
- if (!aht ) {
1646
- php_error_docref (NULL TSRMLS_CC , E_NOTICE , "Array was modified outside object and is no longer an array" );
1647
- return ;
1648
- }
1649
-
1650
- if ((intern -> ar_flags & SPL_ARRAY_IS_REF ) && spl_hash_verify_pos_ex (intern , aht TSRMLS_CC ) == FAILURE ) {
1651
- php_error_docref (NULL TSRMLS_CC , E_NOTICE , "Array was modified outside object and internal position is no longer valid" );
1630
+ if (spl_array_object_verify_pos (intern , aht TSRMLS_CC ) == FAILURE ) {
1652
1631
return ;
1653
1632
}
1654
1633
0 commit comments