@@ -1401,6 +1401,13 @@ const struct _zend_function_entry *ClassImpl::entries()
1401
1401
if (!hasMethod (" serialize" )) entrycount += 1 ;
1402
1402
if (!hasMethod (" unserialize" )) entrycount += 1 ;
1403
1403
}
1404
+
1405
+ // if the class is iterable, we might need some extra methods
1406
+ if (_base->traversable ())
1407
+ {
1408
+ // add the getIterator method if the class does not have one defined yet
1409
+ if (!hasMethod (" getIterator" )) entrycount += 1 ;
1410
+ }
1404
1411
1405
1412
// allocate memory for the functions
1406
1413
_entries = new zend_function_entry[entrycount + 1 ];
@@ -1432,7 +1439,7 @@ const struct _zend_function_entry *ClassImpl::entries()
1432
1439
// if the class is serializable, we might need some extra methods
1433
1440
if (_base->serializable ())
1434
1441
{
1435
- // the method objectneed to stay in scope for the lifetime of the script (because the register a pointer
1442
+ // the method object need to stay in scope for the lifetime of the script (because the register a pointer
1436
1443
// to an internal string buffer) -- so we create them as static variables
1437
1444
static Method serialize (" serialize" , &Base::__serialize, 0 , {});
1438
1445
static Method unserialize (" unserialize" , &Base::__unserialize, 0 , { ByVal (" input" , Type::Undefined, true ) });
@@ -1441,6 +1448,17 @@ const struct _zend_function_entry *ClassImpl::entries()
1441
1448
if (!hasMethod (" serialize" )) serialize.initialize (&_entries[i++], _name);
1442
1449
if (!hasMethod (" unserialize" )) unserialize.initialize (&_entries[i++], _name);
1443
1450
}
1451
+
1452
+ // if the class is traverable, we might need extra methods too (especially on php 8.1, maybe also 8.0?)
1453
+ if (_base->traversable ())
1454
+ {
1455
+ // the method object need to stay in scope for the lifetime of the script (because the register a pointer
1456
+ // to an internal string buffer) -- so we create them as static variables
1457
+ static Method getIterator (" getIterator" , &Base::__getIterator, 0 , {});
1458
+
1459
+ // register the serialize and unserialize method in case this was not yet done in PHP user space
1460
+ if (!hasMethod (" getIterator" )) getIterator.initialize (&_entries[i++], _name);
1461
+ }
1444
1462
1445
1463
// last entry should be set to all zeros
1446
1464
zend_function_entry *last = &_entries[i];
0 commit comments