@@ -203,10 +203,16 @@ static zend_object *spl_filesystem_object_new(zend_class_entry *class_type)
203203}
204204/* }}} */
205205
206+ static inline bool spl_intern_is_glob (const spl_filesystem_object * intern )
207+ {
208+ /* NULL check on `dirp` is necessary as destructors may interfere. */
209+ return intern -> u .dir .dirp && php_stream_is (intern -> u .dir .dirp , & php_glob_stream_ops );
210+ }
211+
206212PHPAPI zend_string * spl_filesystem_object_get_path (const spl_filesystem_object * intern ) /* {{{ */
207213{
208214#ifdef HAVE_GLOB
209- if (intern -> type == SPL_FS_DIR && php_stream_is (intern -> u . dir . dirp , & php_glob_stream_ops )) {
215+ if (intern -> type == SPL_FS_DIR && spl_intern_is_glob (intern )) {
210216 size_t len = 0 ;
211217 char * tmp = php_glob_stream_get_path (intern -> u .dir .dirp , & len );
212218 if (len == 0 ) {
@@ -636,7 +642,7 @@ static inline HashTable *spl_filesystem_object_get_debug_info(zend_object *objec
636642 }
637643 if (intern -> type == SPL_FS_DIR ) {
638644#ifdef HAVE_GLOB
639- if (intern -> u . dir . dirp && php_stream_is (intern -> u . dir . dirp , & php_glob_stream_ops )) {
645+ if (spl_intern_is_glob (intern )) {
640646 ZVAL_STR_COPY (& tmp , intern -> path );
641647 } else {
642648 ZVAL_FALSE (& tmp );
@@ -1590,11 +1596,11 @@ PHP_METHOD(GlobIterator, count)
15901596 RETURN_THROWS ();
15911597 }
15921598
1593- if (intern -> u . dir . dirp && php_stream_is (intern -> u . dir . dirp , & php_glob_stream_ops )) {
1599+ if (spl_intern_is_glob (intern )) {
15941600 RETURN_LONG (php_glob_stream_get_count (intern -> u .dir .dirp , NULL ));
15951601 } else {
1596- /* should not happen */
1597- // TODO ZEND_ASSERT ?
1602+ /* This can happen by abusing destructors. */
1603+ /* TODO: relax this from E_ERROR to an exception */
15981604 php_error_docref (NULL , E_ERROR , "GlobIterator lost glob state" );
15991605 }
16001606}
0 commit comments