@@ -231,6 +231,7 @@ pt_property_site pt_ah_method_call_name_site;
231231pt_property_site pt_ah_array_items_site;
232232pt_property_site pt_ah_array_item_key_site;
233233pt_property_site pt_ah_array_item_unpack_site;
234+ pt_property_site pt_ah_array_item_by_ref_site;
234235pt_property_site pt_ah_array_item_value_site;
235236pt_property_site pt_ah_string_value_site;
236237pt_method_site pt_ah_identifier_to_string_site;
@@ -309,6 +310,51 @@ inline bool closureKind(zval *value, bool &isClosure, bool &isArrowFunction)
309310 return true ;
310311}
311312
313+ /* Mirrors isClosureOrClosureArray(): a closure, or an array literal holding
314+ * only closures (with literal keys); false = pending exception */
315+ bool isClosureOrClosureArray (zval *value, bool &out)
316+ {
317+ out = false ;
318+ bool isClosure, isArrowFunction;
319+ if (UNEXPECTED (!closureKind (value, isClosure, isArrowFunction))) return false ;
320+ if (isClosure || isArrowFunction) {
321+ out = true ;
322+ return true ;
323+ }
324+ bool isArray = false ;
325+ if (UNEXPECTED (!isA (value, PT_CLASS_ARRAY_EXPR , isArray))) return false ;
326+ if (!isArray) return true ;
327+ zv::Val itemsHold;
328+ zval *items = readProperty (pt_ah_array_items_site, value, PT_LC (" items" ), itemsHold);
329+ if (UNEXPECTED (items == NULL )) return false ;
330+ if (Z_TYPE_P (items) != IS_ARRAY || zend_hash_num_elements (Z_ARRVAL_P (items)) == 0 ) return true ;
331+ for (zv::ArrayEntry entry : zv::TableRef (Z_ARRVAL_P (items))) {
332+ zval *item = entry.value ().deref ().raw ();
333+ zv::Val byRefHold, unpackHold, keyHold, itemValueHold;
334+ zval *byRef = readProperty (pt_ah_array_item_by_ref_site, item, PT_LC (" byRef" ), byRefHold);
335+ if (UNEXPECTED (byRef == NULL )) return false ;
336+ if (zend_is_true (byRef)) return true ;
337+ zval *unpack = readProperty (pt_ah_array_item_unpack_site, item, PT_LC (" unpack" ), unpackHold);
338+ if (UNEXPECTED (unpack == NULL )) return false ;
339+ if (zend_is_true (unpack)) return true ;
340+ zval *key = readProperty (pt_ah_array_item_key_site, item, PT_LC (" key" ), keyHold);
341+ if (UNEXPECTED (key == NULL )) return false ;
342+ if (Z_TYPE_P (key) != IS_NULL ) {
343+ bool isString = false , isInt = false ;
344+ if (UNEXPECTED (!isA (key, PT_CLASS_SCALAR_STRING , isString))) return false ;
345+ if (!isString && UNEXPECTED (!isA (key, PT_CLASS_SCALAR_INT , isInt))) return false ;
346+ if (!isString && !isInt) return true ;
347+ }
348+ zval *itemValue = readProperty (pt_ah_array_item_value_site, item, PT_LC (" value" ), itemValueHold);
349+ if (UNEXPECTED (itemValue == NULL )) return false ;
350+ bool itemIsClosure = false ;
351+ if (UNEXPECTED (!isClosureOrClosureArray (itemValue, itemIsClosure))) return false ;
352+ if (!itemIsClosure) return true ;
353+ }
354+ out = true ;
355+ return true ;
356+ }
357+
312358/* $callLike->getArgs() (pt_call_like_args(): the `args` slot,
313359 * or the method's result) as an owned value; UNDEF = pending exception */
314360zv::Val callArgs (zval *callLike)
@@ -1562,7 +1608,7 @@ class ArgumentsHandler
15621608 Walk *walk = NULL ;
15631609 };
15641610
1565- /* the usort() comparator: closures after non-closures , then the
1611+ /* the usort() comparator: closures (and closure-only arrays) after the rest , then the
15661612 * normalized-only arguments after the original ones, by index / start
15671613 * token position (a strict order together with the stable fallback on
15681614 * the original position, so any stable sort agrees with usort()) */
@@ -1612,9 +1658,7 @@ class ArgumentsHandler
16121658 zv::Val valueHold;
16131659 zval *value = argValue (record.sortHasOriginal ? original : record.arg , valueHold);
16141660 if (UNEXPECTED (value == NULL )) return false ;
1615- bool isClosure, isArrowFunction;
1616- if (UNEXPECTED (!closureKind (value, isClosure, isArrowFunction))) return false ;
1617- record.sortIsClosure = isClosure || isArrowFunction;
1661+ if (UNEXPECTED (!isClosureOrClosureArray (value, record.sortIsClosure ))) return false ;
16181662 record.sortStartTokenPos = -1 ;
16191663 if (record.sortHasOriginal ) {
16201664 if (UNEXPECTED (Z_TYPE_P (original) != IS_OBJECT )) {
0 commit comments