phplang 0.2.2

PHP as a fusevm frontend: lexer, parser, and compiler to fusevm::Chunk on a PhpHost heap — the first compiled standalone PHP runtime
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
//! The language corpus: the exact `(name, chapter, signature, description,
//! example)` table that documents every name the current phplang build
//! recognizes.
//!
//! Every entry mirrors real code, and the chapter says which table it came from:
//!   * "Keyword" / "Language construct" / "Operator" / "Cast" — the reserved
//!     words, constructs, and punctuation `src/lexer.rs` tokenizes and
//!     `src/parser.rs` handles.
//!   * "Magic method" — the `__`-prefixed methods the runtime itself invokes
//!     (`src/host.rs`), as opposed to ones a program may merely declare.
//!   * "Predefined constant" — `predefined_constants()` in `src/host.rs`.
//!   * "Prelude class" — the classes `src/lib.rs` compiles from PHP source into
//!     every fresh host (`EXCEPTION_PRELUDE`, `DATETIME_PRELUDE`, `SPL_PRELUDE`).
//!   * "Core library — …" — the core `call_library` match in `src/builtins.rs`.
//!   * every other chapter — one `dispatch` match arm in the module named by the
//!     chapter, from the 26-module chain in `src/stdlib/mod.rs`.
//!
//! Descriptions are written from the implementation, not from the PHP manual.
//! Where phplang diverges from reference PHP 8 — an ignored argument, a bounded
//! approximation, a construct the parser rejects — the description says so. A
//! divergence that goes unstated is a documentation bug.
//!
//! `gen-docs` (`src/bin/gen_docs.rs`) renders this table to `docs/reference.html`
//! and `src/lsp.rs` answers completion and hover from it, so the reference manual
//! never documents a name the runtime does not implement.

/// One reference entry: `(name, chapter, signature, description, example)`.
///
/// `example` may be empty, in which case the entry renders as signature plus
/// description — the right shape for a constant, a class, or an operator whose
/// use the signature already shows. `signature` is never empty.
pub type Entry = (
    &'static str,
    &'static str,
    &'static str,
    &'static str,
    &'static str,
);

/// The corpus. Grouped by chapter in the order the reference presents them.
pub const CORPUS: &[Entry] = &[
    // ══ Keyword ═════════════════════════════════════════════════════════════
    (
        "if",
        "Keyword",
        "if (expr) statement",
        "Conditional branch; runs its body when the condition is truthy. The body is a single statement or a braced block. PHP's alternative `if: … endif;` syntax is not parsed.",
        "if (1 < 2) echo \"y\";   // => y",
    ),
    (
        "elseif",
        "Keyword",
        "if (expr) stmt elseif (expr) stmt",
        "Additional condition tested when every preceding one failed. The two-word spelling `else if` is folded into the same branch list by the parser, so both forms behave identically.",
        "if (0) echo \"a\"; elseif (1) echo \"b\";   // => b",
    ),
    (
        "else",
        "Keyword",
        "if (expr) stmt else stmt",
        "Fallback branch taken when the `if` condition and every `elseif` condition are falsey.",
        "if (0) echo \"a\"; else echo \"b\";   // => b",
    ),
    (
        "while",
        "Keyword",
        "while (expr) statement",
        "Loops while the condition stays truthy, testing before each pass. The alternative `while: … endwhile;` syntax is not parsed.",
        "$i = 0; while ($i < 3) $i++; echo $i;   // => 3",
    ),
    (
        "do",
        "Keyword",
        "do statement while (expr);",
        "Post-tested loop; the body always runs at least once. The trailing `while (…)` and its semicolon are both required.",
        "$i = 5; do $i++; while ($i < 3); echo $i;   // => 6",
    ),
    (
        "for",
        "Keyword",
        "for (init; cond; step) statement",
        "C-style loop. Each of the three clauses is a comma-separated expression list and each may be empty; an empty condition loops forever.",
        "$s = 0; for ($i = 1; $i <= 3; $i++) $s += $i; echo $s;   // => 6",
    ),
    (
        "foreach",
        "Keyword",
        "foreach (expr as [&]$value) statement\nforeach (expr as $key => [&]$value) statement",
        "Iterates an array. A `&` before the value variable iterates by reference and writes each assignment back into the array. Only arrays and generators are iterable — no user class implements `Iterator`.",
        "foreach ([1, 2] as $v) echo $v;   // => 12",
    ),
    (
        "as",
        "Keyword",
        "foreach (expr as $v)\nuse A { m as [visibility] [alias]; }   //  trait adaptation\nuse Ns\\Name as Alias;   //  namespace import",
        "Binds the current element inside a `foreach` header. In a trait adaptation block it binds a trait method under a second name, a new visibility, or both — `m as x;` adds `x` alongside `m`, `m as protected;` only re-marks `m`. In a namespace import the alias is accepted and discarded, because phplang resolves every name in one flat namespace.",
        "foreach ([9] as $k => $v) echo $k;   // => 0",
    ),
    (
        "insteadof",
        "Keyword",
        "use A, B { A::m insteadof B[, C]; }   //  inside a class body",
        "Resolves a trait method collision by EXCLUDING the named traits' version of the method, inside the `{ … }` block of a `use`. Two used traits declaring the same method with no `insteadof` between them is a fatal error, and excluding only one of three still leaves the other two colliding. The excluded method is not gone — an `as` alias in the same block can still bind it under another name.",
        "trait A { function m() { return \"A\"; } }\ntrait B { function m() { return \"B\"; } }\nclass C { use A, B { A::m insteadof B; B::m as bm; } }\n$c = new C; echo $c->m(), $c->bm();   // => AB",
    ),
    (
        "switch",
        "Keyword",
        "switch (expr) { case expr: … default: … }",
        "Multi-way branch; each `case` compares against the subject with loose (`==`) equality. A case label may end in `:` or `;`. The alternative `switch: … endswitch;` syntax is not parsed.",
        "switch (2) { case 2: echo \"two\"; }   // => two",
    ),
    (
        "case",
        "Keyword",
        "case expr:   //  also: case Name [= value]; inside an enum",
        "A labelled `switch` branch, falling through into the next branch until a `break`. Inside an `enum` body the same keyword declares a case, optionally with a backing value.",
        "switch (1) { case 1: echo \"a\"; case 2: echo \"b\"; }   // => ab",
    ),
    (
        "default",
        "Keyword",
        "default:   //  in switch;   default => expr   //  in match",
        "The branch taken when no case matched — in a `switch` body and in a `match` expression.",
        "switch (9) { default: echo \"d\"; }   // => d",
    ),
    (
        "break",
        "Keyword",
        "break;\nbreak <int>;   //  level parsed, then IGNORED",
        "Exits the nearest enclosing loop or `switch`. DIVERGENCE: the optional numeric level is parsed and discarded (`src/parser.rs`), so `break 2;` unwinds ONE level exactly like `break;` instead of two. Nested loops therefore keep running where reference PHP would have left them.",
        "for ($i=0;$i<2;$i++){ for ($j=0;$j<2;$j++){ echo $i.$j.\" \"; break 2; } }\necho \"end\";   // => 00 10 end   (PHP 8 prints: 00 end)",
    ),
    (
        "continue",
        "Keyword",
        "continue;\ncontinue <int>;   //  level parsed, then IGNORED",
        "Skips to the next iteration of the nearest loop. DIVERGENCE: like `break`, the numeric level is parsed and discarded, so `continue 2;` only restarts the innermost loop.",
        "foreach ([1, 2, 3] as $v) { if ($v == 2) continue; echo $v; }   // => 13",
    ),
    (
        "declare",
        "Keyword",
        "declare(directive=value);\ndeclare(directive=value) { body }   //  not for strict_types",
        "Sets a compilation-unit directive. `strict_types=1` turns off the coercion a scalar parameter or return type would otherwise perform, so a value must already be of the declared type — with int→float widening the one exception, since it cannot lose anything. Its rules are all COMPILE-time, and each has its own message: it must be the very first statement (a preceding `declare` does not count against it, any other statement does), its value must be the literal `0` or `1`, and it may not use the block form even though `ticks` may. `ticks` is accepted and ignored — no tick handler exists to call. `encoding` is recognised and refused with the reference's own wording; any other directive warns `Unsupported declare`. DIVERGENCE: upstream reads the mode from the CALLER's file, so a strict file calling a non-strict file's function still checks strictly; phplang has no `include`, so a run is one file and the two readings coincide.",
        "declare(strict_types=1); function f(int $x) { return $x; } f(\"5\");   // => TypeError",
    ),
    (
        "function",
        "Keyword",
        "function name(params) [: type] { body }\nfunction (params) [use (vars)] [: type] { body }   //  closure",
        "Declares a named function as a statement, or an anonymous closure as an expression. A scalar parameter or return type (`int`, `float`, `string`, `bool`, and their `?` nullable forms) is ENFORCED: coerced on the way in by default, required exactly under `declare(strict_types=1)`. Any other type — a union, an intersection, a class name, `array`, `iterable`, `callable`, `mixed`, `object`, `void`, `never`, `static` — is parsed and carried but imposes no check. A function with no `return` yields null.",
        "function sq($x) { return $x * $x; } echo sq(4);   // => 16",
    ),
    (
        "fn",
        "Keyword",
        "fn(params) [: type] => expr",
        "Arrow function: a single-expression body that automatically captures every free variable by value. Returns a real `Closure`.",
        "$d = fn($x) => $x * 2; echo $d(4);   // => 8",
    ),
    (
        "use",
        "Keyword",
        "function (…) use ($a, $b) { … }\nuse Ns\\Name [as Alias];\nuse T1, T2 [{ adaptations }];   //  inside a class body",
        "Three unrelated roles. In a closure header it captures the named enclosing variables by value — DIVERGENCE: by-reference capture `use (&$v)` is rejected with a parse error rather than silently binding by value. As a statement it is a namespace import, accepted and discarded. Inside a class body it pulls the traits' members in, with an optional `{ … }` block of `insteadof`/`as` adaptations resolving collisions and binding extra names.",
        "$n = 10; $f = function () use ($n) { return $n; }; echo $f();   // => 10",
    ),
    (
        "return",
        "Keyword",
        "return [expr];",
        "Returns a value from the current function, or null when the expression is omitted. At the top level it ends the script.",
        "function one() { return 1; } echo one();   // => 1",
    ),
    (
        "yield",
        "Keyword",
        "yield;\nyield $value;\nyield $key => $value;",
        "Suspends the enclosing generator and hands a value (and optionally a key) to the consumer; the expression evaluates to whatever the next `->send()` passes in. Any function containing `yield` becomes a generator, run on its own native stack.",
        "function g() { yield 1; yield 2; } foreach (g() as $v) echo $v;   // => 12",
    ),
    (
        "yield from",
        "Keyword",
        "yield from expr",
        "Delegates to an inner generator or array, re-yielding each of its elements before continuing.",
        "function inner() { yield 1; yield 2; }\nfunction outer() { yield from inner(); yield 3; }\nforeach (outer() as $v) echo $v;   // => 123",
    ),
    (
        "match",
        "Keyword",
        "match (expr) { cond[, cond] => expr, … , default => expr }",
        "PHP 8 expression that compares the subject to each arm with strict (`===`) equality and evaluates the first hit. With no matching arm and no `default` it throws `UnhandledMatchError` rather than yielding null.",
        "echo match (2) { 1 => \"a\", 2 => \"b\" };   // => b\ntry { echo match (5) { 1 => \"a\" }; }\ncatch (UnhandledMatchError $e) { echo $e->getMessage(); }   // => Unhandled match case 5",
    ),
    (
        "array",
        "Keyword",
        "array(elem, …)   //  identical to [elem, …]",
        "The long-form array literal constructor. It parses to exactly the same node as the `[…]` short form, so keys, `=>` pairs, and destructuring behave identically.",
        "echo count(array(1, 2, 3));   // => 3",
    ),
    (
        "list",
        "Keyword",
        "list($a, $b) = expr;\nlist('k' => $v) = expr;",
        "The long-form destructuring target. It desugars to the same array node as `[$a, $b] = …`, so both forms share one assignment path. An empty slot (`list(, $b)`) still consumes a positional index.",
        "list($a, $b) = [1, 2]; echo $a . $b;   // => 12",
    ),
    (
        "clone",
        "Keyword",
        "clone $object",
        "Duplicates an object: a new instance of the same class carrying a copy of the properties, then `__clone()` on the copy if the class defines one. The copy is shallow the way PHP means it — an array property is a value and travels as a copy, an object property is a handle and stays shared with the original. Binds tighter than every operator, so `clone $a->b` clones the property and `clone $a instanceof C` tests the clone. A non-object is `TypeError: clone(): Argument #1 ($object) must be of type object, int given`; a live generator holds a suspended stack and is refused with `Error: Trying to clone an uncloneable object of class Generator`.",
        "class C { public $n = 1; } $a = new C; $b = clone $a; $b->n = 2; echo $a->n, $b->n;   // => 12",
    ),
    (
        "class",
        "Keyword",
        "[abstract|final|readonly] class Name [extends Parent] [implements I, …] { members }",
        "Declares a class: constants, properties, static properties, and methods. `abstract` marks the class un-instantiable; `readonly` makes every property it declares readonly; `final` is parsed and ignored.",
        "class C { public $x = 1; } $o = new C; echo $o->x;   // => 1",
    ),
    (
        "interface",
        "Keyword",
        "interface Name [extends I, …] { const …; function m(); }",
        "Declares an interface, stored in the same class table as classes so `instanceof` and `class_exists` both see it. DIVERGENCE: `interface_exists()` is a hardcoded `false`, so it disagrees with `instanceof` on the very same name.",
        "interface I {} class C implements I {} $o = new C;\nvar_dump($o instanceof I, interface_exists(\"I\"));   // => bool(true) bool(false)",
    ),
    (
        "trait",
        "Keyword",
        "trait Name { members }   //  then: use Name; inside a class",
        "Declares a reusable member bundle that a class pulls in with `use`, optionally adapted by an `insteadof`/`as` block. A `use` naming a trait that was never declared is a throwable `Error`; an unresolved method collision is a fatal raised when the declaration is reached, so output produced before it is still printed. DIVERGENCE: `trait_exists()` is a hardcoded `false` even for a trait that was declared and successfully used; two definitions of the same property with different defaults are merged silently rather than refused.",
        "trait T { function f() { return 3; } } class C { use T; } echo (new C)->f();   // => 3",
    ),
    (
        "enum",
        "Keyword",
        "enum Name [: backing-type] [implements I] { case A [= value]; … }",
        "Declares an enum. Cases are class constants holding a case object with `->name` and, for a backed enum, `->value`. Every enum implicitly implements `UnitEnum`, and a backed one also `BackedEnum`. `enum` is only treated as a declaration when a name and `{`, `:`, or `implements` follow, so a bareword `enum` still parses as an identifier. DIVERGENCE: `enum_exists()` is a hardcoded `false`.",
        "enum Suit: string { case Hearts = \"H\"; } echo Suit::Hearts->value;   // => H",
    ),
    (
        "extends",
        "Keyword",
        "class C extends Parent    //  interface I extends A, B",
        "Single inheritance for a class — the child inherits its parent's methods, properties, and constants. An interface may extend several parents, which the parser records as implemented interfaces.",
        "class A { function f() { return 1; } } class B extends A {} echo (new B)->f();   // => 1",
    ),
    (
        "implements",
        "Keyword",
        "class C implements I, J",
        "Lists the interfaces a class satisfies. `instanceof` walks this list transitively, including through parent classes. DIVERGENCE: `class_implements()` always returns an empty array, so it does not report what `instanceof` honours.",
        "interface I {} class C implements I {} var_dump((new C) instanceof I);   // => bool(true)",
    ),
    (
        "new",
        "Keyword",
        "new ClassName[(args)]\nnew class[(args)] [extends P] [implements I, …] { members }",
        "Instantiates a class, running `__construct` with the given arguments. The parentheses are optional when there are no arguments. The class name is a bareword — `new $className` is not parsed. `new class` declares the class inline: its arguments come BEFORE the `extends`/`implements` clauses, and the declaration is compiled once, so the same site in a loop yields instances of one class. Its generated name is `Base@anonymous\\0<script>:<line>$<n>` — the parent, else the first interface, else `class` — so `get_class` returns a unique string while `var_dump` and diagnostics print the readable head alone.",
        "class C { function __construct($x) { $this->x = $x; } } echo (new C(5))->x;   // => 5",
    ),
    (
        "const",
        "Keyword",
        "const NAME = expr[, NAME2 = expr2]*;",
        "Declares a constant. Inside a class or interface body it is a class constant, read back through `ClassName::NAME`. At statement level it is a GLOBAL constant, read back as a bareword — the declaration spelling of `define()`, and top-level only, so a function body or an `if` block rejects it the way PHP's grammar does. It is not hoisted: the constant exists from the statement onwards, so a `defined()` above it answers false. Redefining warns and keeps the FIRST value, through either spelling. Several names may be declared in one comma-separated statement, and a later one may read an earlier one.",
        "class A { const K = 7; } echo A::K;   // => 7\nconst G = 1, H = G + 1; echo H;   // => 2",
    ),
    (
        "static",
        "Keyword",
        "static $var [= expr];\nstatic function m() { … }\nstatic public $prop;\nstatic::member",
        "Four roles, told apart by what follows. Before a `$variable` in a function body it declares a static local that survives between calls; before a member it marks it static; as a `::` qualifier it is late static binding; and before `function`/`fn` it makes a CLOSURE static, so it is not bound to the `$this` of the method it was written in and `Closure::bind` refuses to give it one afterwards (warning `Cannot bind an instance to a static closure, this will be an error in PHP 9` and answering null). It keeps that method's class scope, so a private static stays reachable.",
        "class A { static $n = 4; } echo A::$n;   // => 4\n$f = static fn($x) => $x + 1; echo $f(1);   // => 2",
    ),
    (
        "public",
        "Keyword",
        "public $prop;   public function m() { … }   public function __construct(public $x)",
        "Marks a member publicly visible (the default when no visibility keyword is given). In a constructor parameter list it promotes the parameter to a property.",
        "class C { public $x = 2; } echo (new C)->x;   // => 2",
    ),
    (
        "protected",
        "Keyword",
        "protected $prop;   protected function m() { … }",
        "Marks a member reachable only from the declaring class and its subclasses. Visibility IS enforced: reading, writing or unsetting the property from outside throws a catchable `Error: Cannot access protected property C::$x` — unless the class defines the matching magic method (`__get`, `__set`, `__unset`), which is consulted first and makes the access succeed instead.",
        "class A { protected $x = 1; }\nclass B extends A { function g() { return $this->x; } }\necho (new B)->g();   // => 1",
    ),
    (
        "private",
        "Keyword",
        "private $prop;   private function m() { … }",
        "Marks a member reachable only from the declaring class. Enforced for both properties and methods. A property access from outside throws a catchable `Error: Cannot access private property C::$x`, naming the class that DECLARED it, unless the class defines the matching magic method (`__get`, `__set`, `__unset`), which is consulted first. `isset()` never throws here — an unreachable property is simply not set. DIVERGENCE: a method call from outside still aborts with the uncatchable host error `php: Call to private method C::m() from global scope`.",
        "class C { private $x = 4; function get() { return $this->x; } }\necho (new C)->get();   // => 4",
    ),
    (
        "readonly",
        "Keyword",
        "readonly $prop;   function __construct(public readonly $x)   readonly class C",
        "Marks a property writable exactly once. Accepted on a property declaration, on a promoted constructor parameter, and on the class itself (`readonly class`, which applies it to every property the class declares, promoted parameters included); a trait's readonly property stays readonly in the class that uses it. The one write must come from the declaring class or a subclass, so an outside write to a still-uninitialized property is `Error: Cannot modify protected(set) readonly property C::$x from global scope` and every later write anywhere is `Error: Cannot modify readonly property C::$x`. Writing THROUGH the property (`$o->arr[] = 1`) is `Error: Cannot indirectly modify readonly property C::$arr` and `unset()` on an initialized one is `Error: Cannot unset readonly property C::$x`. `__clone` is the single reopening: it may rewrite the copy's readonly properties, which lock again when it returns.",
        "class C { public readonly $x; function __construct() { $this->x = 1; } }\n$c = new C; try { $c->x = 2; } catch (Error $e) { echo $e->getMessage(); }\n// => Cannot modify readonly property C::$x",
    ),
    (
        "abstract",
        "Keyword",
        "abstract class C { abstract function m(); }",
        "On a class it marks it un-instantiable. On a method it is parsed and discarded; an abstract method is simply a method whose body is `;`, so calling an un-overridden one returns null instead of raising a fatal error.",
        "abstract class A { abstract function f(); } class B extends A { function f() { return 9; } }\necho (new B)->f();   // => 9",
    ),
    (
        "final",
        "Keyword",
        "final class C { … }   final function m() { … }",
        "Parsed and discarded on both classes and methods. DIVERGENCE: a `final` class can still be extended and a `final` method still overridden.",
        "final class A {} class B extends A {} echo get_class(new B);   // => B   (PHP 8: fatal error)",
    ),
    (
        "var",
        "Keyword",
        "var $prop;",
        "The PHP 4 property declaration keyword. Accepted and treated as `public`.",
        "class C { var $x = 5; } echo (new C)->x;   // => 5",
    ),
    (
        "instanceof",
        "Keyword",
        "expr instanceof ClassName",
        "True when the value is an object whose class is, extends, or implements the named class — the check walks the parent chain and every implemented interface transitively. `Throwable` is special-cased to match both the `Exception` and `Error` roots.",
        "class A {} class B extends A {} var_dump(new B instanceof A);   // => bool(true)",
    ),
    (
        "try",
        "Keyword",
        "try { body } catch (T [$e]) { … } [finally { … }]",
        "Guards a block. At least one `catch` or a `finally` must follow, matching PHP's own rule.",
        "try { echo \"a\"; } finally { echo \"b\"; }   // => ab",
    ),
    (
        "catch",
        "Keyword",
        "catch (A | B [$e]) { body }",
        "Handles a thrown object whose class matches any type in the `|`-separated union. The bound variable is optional (PHP 8 syntax). A leading `\\` and any `Ns\\` prefix are folded away, so `\\RuntimeException` and `RuntimeException` name the same class.",
        "try { throw new Exception(\"x\"); } catch (Exception $e) { echo $e->getMessage(); }   // => x",
    ),
    (
        "finally",
        "Keyword",
        "finally { body }",
        "Runs after the `try`/`catch` on every exit path — normal fall-through, `return`, a rethrown exception, `break`, and `continue`.",
        "try { echo \"t\"; } finally { echo \"f\"; }   // => tf",
    ),
    (
        "throw",
        "Keyword",
        "throw expr;   //  also usable as an expression",
        "Raises an exception. It is both a statement and a PHP 8 expression, so `$x ?? throw new E` and `cond ? throw new E : $v` both parse.",
        "try { throw new Exception(\"boom\"); } catch (Exception $e) { echo $e->getMessage(); }   // => boom",
    ),
    (
        "namespace",
        "Keyword",
        "namespace Name;   //  or  namespace Name { … }",
        "Accepted and discarded: phplang resolves every name in one flat namespace, folding a qualified name to its last segment. The block form runs its body inline.",
        "namespace App; function f() { return 1; } echo f();   // => 1",
    ),
    (
        "true",
        "Keyword",
        "true",
        "The boolean true literal, matched case-insensitively.",
        "echo true ? \"y\" : \"n\";   // => y",
    ),
    (
        "false",
        "Keyword",
        "false",
        "The boolean false literal, matched case-insensitively.",
        "echo false ? \"y\" : \"n\";   // => n",
    ),
    (
        "null",
        "Keyword",
        "null",
        "The null literal — the absent or unset value, matched case-insensitively. Reading an undefined variable or a missing array key also produces it, quietly.",
        "echo null ?? \"fallback\";   // => fallback",
    ),
    (
        "and",
        "Keyword",
        "expr and expr",
        "Logical AND that short-circuits. DIVERGENCE: the parser gives it the same binding power as `&&`, whereas PHP puts `and` below assignment — so `$x = true and false;` assigns `false` here and `true` in PHP 8.",
        "echo (true and false) ? \"y\" : \"n\";   // => n",
    ),
    (
        "or",
        "Keyword",
        "expr or expr",
        "Logical OR that short-circuits. It carries the same precedence as `||`, with the same divergence from PHP's low-precedence `or` described under `and`. There is no `xor` — it is not a token the parser recognizes.",
        "echo (false or true) ? \"y\" : \"n\";   // => y",
    ),
    // ══ Language construct ══════════════════════════════════════════════════
    (
        "echo",
        "Language construct",
        "echo expr[, expr …];   //  also: <?= expr ?>",
        "Writes one or more values to standard output and has no return value. The short echo tag `<?=` is the single-argument form. An object argument is converted through `__toString`, as it is everywhere a value becomes a string.",
        "echo \"hi\", \"!\";   // => hi!",
    ),
    (
        "print",
        "Language construct",
        "print expr;",
        "Writes a single value to standard output. DIVERGENCE: it is a statement only. PHP's `print` is an expression that evaluates to `1`, but `$x = print \"a\";` is a syntax error here.",
        "print \"hi\";   // => hi",
    ),
    (
        "exit",
        "Language construct",
        "exit[(string|int $status = 0)]: never   //  also spelled `die`",
        "Ends the request where it stands. Both the parentheses and the argument are optional, which is what keeps `exit` a construct even though PHP 8.4 also registered it as a callable function (`function_exists(\"exit\")` is true, and `$f = \"exit\"; $f(3);` works). An INT becomes the process exit status, taken modulo 256 — `exit(300)` leaves 44 and `exit(-1)` leaves 255. A STRING is written to output and the status is 0. A bool or float narrows to int, a float with a fraction raising `Implicit conversion from float … to int loses precision`; an explicit null is deprecated and reads as 0; anything else is a `TypeError`. The unwind is not catchable and does not run a `finally` — `try { exit(5); } finally { echo \"fin\"; }` prints nothing — but open output buffers are still flushed on the way out.",
        "echo \"a\"; exit(3);   // => a, exit status 3",
    ),
    (
        "die",
        "Language construct",
        "die[(string|int $status = 0)]: never",
        "The alternative spelling of `exit`, folded onto it by the scanner: the two are one construct, so a `die()` argument PHP rejects is reported against `exit()` and a syntax error on `die` names the `exit` token. See `exit` for the semantics.",
        "die(\"bye\");   // => bye, exit status 0",
    ),
    (
        "isset",
        "Language construct",
        "isset($var[, $var …]): bool",
        "True when every argument is set and not null, staying quiet about undefined variables and missing keys — asking is never an error, so even an unreachable private property is simply `false` rather than a fatal. On an OBJECT PROPERTY it consults `__isset` and stops there: it never reads a value, so `isset($o->p)` is true whenever `__isset` says so even if `__get` would answer null.",
        "$a = 1; echo isset($a) ? \"y\" : \"n\";   // => y",
    ),
    (
        "empty",
        "Language construct",
        "empty($var): bool",
        "True when the argument is falsey or unset, raising no notice for an undefined name, so `empty(\"0\")`, `empty([])`, and `empty(null)` are all true. On an OBJECT PROPERTY it sits between `isset` and `??`: it wants a value, but will not read one through `__get` unless `__isset` vouched for the property first. A class with `__get` and no `__isset` is therefore `empty()` without `__get` ever being called, while `$o->p ?? \"d\"` on that same class does call it.",
        "echo empty(0) ? \"y\" : \"n\";   // => y",
    ),
    (
        "global",
        "Keyword",
        "global $var[, $var …];",
        "Binds each name to the GLOBAL variable of that name for the rest of the function. It is a reference, not a copy: a write through either side is seen by the other, and a global that does not exist yet is created by the binding. `unset()` on the local breaks the alias and leaves the global alone. Without the declaration the name is an ordinary, unrelated local. At global scope there is no second frame to bind to and the statement does nothing.",
        "$g = 1; function f() { global $g; $g = 2; } f(); echo $g;   // => 2",
    ),
    (
        "$$",
        "Operator",
        "$$name\n${expr}",
        "A variable VARIABLE: the operand is evaluated and its string value names the variable to read or write, so the name is not known until it runs. `$$x` nests, so `$$$x` is two lookups, and `${expr}` takes any expression. What it names is an ordinary variable — assignable, unsettable, and acceptable where a by-reference parameter wants a location. A quiet context reads through it without the undefined-variable warning.",
        "$a = 5; $n = 'a'; echo $$n, ' ', ${'a'};   // => 5 5",
    ),
    (
        "unset",
        "Language construct",
        "unset($var[, $var …]): void",
        "Removes variables, array elements and object properties. Like `isset`, it is a construct rather than a call, so an index path such as `$a[$k]` is unset in place rather than being evaluated to a value first. `unset($o->p)` removes the property outright — a later read of it goes through `__get` as for any property that is not there — or calls `__unset` when the property is unreachable or absent and the class defines one. Unsetting a property that is not there is not an error; unsetting one that is out of reach, with no `__unset` to take it, throws `Error: Cannot access private property C::$p`.",
        "$a = [1, 2]; unset($a[0]); echo count($a);   // => 1",
    ),
    (
        "#[Attr]",
        "Language construct",
        "#[Name], #[Name(args)], #[Ns\\Name] …   //  before a class, function, method, property, class constant, enum case, or parameter",
        "An attribute group: declarative metadata attached to the declaration that follows. It is NOT a comment — `#[` and `#` are different tokens, and lexing `#[Attr] class C {}` as a comment would delete the declaration. Arguments are scanned for bracket balance and discarded. DIVERGENCE: attributes are not reflectable (`ReflectionAttribute` does not exist) and none is evaluated; only `#[AllowDynamicProperties]` changes behaviour.",
        "#[Attr(1)] class C { #[Attr] public $v = 7; } echo (new C)->v;   // => 7",
    ),
    (
        "#[AllowDynamicProperties]",
        "Language construct",
        "#[AllowDynamicProperties] class C { … }",
        "Opts a class out of the PHP 8.2 `Deprecated: Creation of dynamic property C::$p is deprecated` notice, which otherwise fires the first time a property no class in the chain declares is written. The opt-out is INHERITED by subclasses. `stdClass` is exempt without it, as is any property the class (or an ancestor) declares — including one promoted from a constructor parameter. The name is matched exactly, so a namespaced `#[Ns\\AllowDynamicProperties]` is a different, inert attribute.",
        "#[AllowDynamicProperties] class C {} $c = new C; $c->x = 1; echo $c->x;   // => 1",
    ),
    (
        "rust { … }",
        "Language construct",
        "rust { pub extern \"C\" fn name(args) -> ty { … } }",
        "Inline Rust FFI. The block is lifted out before lexing and replaced with a `__rust_compile(…)` call carrying the base64-encoded body; every `pub extern \"C\"` function it exports becomes callable from PHP as a bareword. Unique to phplang — reference PHP has no such construct.",
        "rust { pub extern \"C\" fn add(a: i64, b: i64) -> i64 { a + b } }\necho add(2, 3);   // => 5",
    ),
    // ══ Language construct: magic constants ════════════════════════════════
    (
        "__LINE__",
        "Language construct",
        "__LINE__: int",
        "The line the constant is WRITTEN on, resolved by the parse rather than looked up at run time. A function reporting `__LINE__` therefore reports where the constant stands inside it, not the line it was called from.",
        "echo __LINE__;   // => 1",
    ),
    (
        "__FILE__",
        "Language construct",
        "__FILE__: string",
        "The running script's name, which is whatever the ENTRY POINT called it: a named file is its resolved path, `php -r` code is `Command line code`, and a script on standard input is `Standard input code`. It is the same name every diagnostic quotes, so the two can never disagree.",
        "echo __FILE__;   // => Command line code",
    ),
    (
        "__DIR__",
        "Language construct",
        "__DIR__: string",
        "The directory part of `__FILE__`. Code with no file behind it — `php -r`, or a script on standard input — has no directory to report, and answers the working directory instead, as the reference does.",
        "var_dump(__DIR__ === getcwd());   // => bool(true)",
    ),
    (
        "__FUNCTION__",
        "Language construct",
        "__FUNCTION__: string",
        "The enclosing function's name, or `\"\"` at file scope. A CLOSURE has no name of its own, so PHP 8.4 builds it one out of the scope the closure was written in: `{closure:<scope>:<line>}`, where the scope is `__FILE__` at file scope, `f()` inside a function, `C::m()` inside a method — and the closure's own name when closures nest, so the two compose.",
        "function g() { echo __FUNCTION__; } g();   // => g",
    ),
    (
        "__CLASS__",
        "Language construct",
        "__CLASS__: string",
        "The class the code was WRITTEN in, or `\"\"` outside one — so an inherited method reports the class that declared it, not the subclass the call arrived through. Two cases are answered from the running frame instead, because a parse cannot settle them: inside a TRAIT method it is the class that used the trait (one trait, many users), and inside an anonymous class it is the generated `class@anonymous` name `get_class` reports. A named function declared inside a method body belongs to no class and reports `\"\"`.",
        "class C { function m() { echo __CLASS__; } } class D extends C {} (new D)->m();   // => C",
    ),
    (
        "__METHOD__",
        "Language construct",
        "__METHOD__: string",
        "`Class::method` for a method, and just the name for a free function — there is no `::` half to prepend outside a class. A trait's method reports the TRAIT (`T::tm`) even though `__CLASS__` in the same body reports the using class. Inside a closure it is the closure's name, the same string `__FUNCTION__` gives.",
        "class C { function m() { echo __METHOD__; } } (new C)->m();   // => C::m",
    ),
    (
        "__NAMESPACE__",
        "Language construct",
        "__NAMESPACE__: string",
        "The enclosing `namespace` declaration in full — `A\\B`, not the last segment a class reference folds to — and `\"\"` with no declaration. DIVERGENCE: phplang's namespaces are flat, so while this constant is exact, the class and function names around it stay unqualified where the reference qualifies them.",
        "namespace A\\B; echo __NAMESPACE__;   // => A\\B",
    ),
    (
        "__TRAIT__",
        "Language construct",
        "__TRAIT__: string",
        "The enclosing `trait` declaration's name, and `\"\"` everywhere else — including inside a class that merely USES the trait, once the method is being read as part of that class's own body.",
        "trait T { function t() { echo __TRAIT__; } } class C { use T; } (new C)->t();   // => T",
    ),
    // ══ Operator ════════════════════════════════════════════════════════════
    (
        "+",
        "Operator",
        "expr + expr   //  binary;   +expr   //  unary",
        "Numeric addition, or array union when BOTH operands are arrays — the left operand's entries win and the right contributes only the keys it lacks. Under PHP 8 a string operand with no numeric prefix (`\"g\"`, `\"\"`, `\"   \"`) makes the whole operation a `TypeError: Unsupported operand types: string + int`, while one that merely trails garbage (`\"5g\"`) raises `Warning: A non-numeric value encountered` and continues with its prefix. Operands resolve left before right, so `\"5g\" + \"g\"` warns and then throws while `\"g\" + \"5g\"` throws without warning.",
        "echo 2 + 3;   // => 5",
    ),
    (
        "-",
        "Operator",
        "expr - expr   //  binary;   -expr   //  unary",
        "Numeric subtraction and arithmetic negation. Unary minus binds looser than `**`, so `-2 ** 2` is `-(2 ** 2)`. Both unary signs are multiplications to the engine, which is why `-\"g\"` and `+\"g\"` report `Unsupported operand types: string * int`.",
        "echo 7 - 2, \" \", -2 ** 2;   // => 5 -4",
    ),
    (
        "*",
        "Operator",
        "expr * expr",
        "Numeric multiplication. Integer operands stay integers unless the result overflows into a float.",
        "echo 6 * 7;   // => 42",
    ),
    (
        "/",
        "Operator",
        "expr / expr",
        "Division. Two integers that divide exactly yield an integer, otherwise a float. A zero divisor throws a catchable `DivisionByZeroError` with the message `Division by zero`.",
        "echo 7 / 2;   // => 3.5",
    ),
    (
        "%",
        "Operator",
        "expr % expr",
        "Integer remainder, taking the sign of the left operand. Both operands are cast to integers first, so `7.5 % 2` is `1`. A zero divisor throws a catchable `DivisionByZeroError` with the message `Modulo by zero`.",
        "echo 7 % 3;   // => 1",
    ),
    (
        "**",
        "Operator",
        "expr ** expr",
        "Exponentiation. It is right-associative and binds tighter than unary minus, and its right operand may itself be a unary expression, so `2 ** -1` parses.",
        "echo 2 ** 3 ** 2;   // => 512",
    ),
    (
        ".",
        "Operator",
        "expr . expr",
        "String concatenation, casting both operands to strings. DIVERGENCE: it carries the SAME precedence as `+` and `-` (PHP 7 behaviour). PHP 8 lowered `.` below the additive operators, so `\"x\" . 1 + 2` groups as `(\"x\" . 1) + 2` here and evaluates to `2`, where PHP 8 gives `\"x3\"`.",
        "echo \"a\" . \"b\";   // => ab\necho \"x\" . 1 + 2;   // => 2   (PHP 8 prints: x3)",
    ),
    (
        "=",
        "Operator",
        "target = expr",
        "Assignment, right-associative and itself an expression. Arrays and objects are handles, so assigning one aliases the same storage rather than copying it — a divergence from PHP's copy-on-write arrays.",
        "$a = 5; echo $a;   // => 5",
    ),
    (
        "=&",
        "Operator",
        "$target = &expr",
        "Reference binding: the target becomes another name for the same storage cell rather than a copy of its value.",
        "$a = 1; $b = &$a; $b = 9; echo $a;   // => 9",
    ),
    (
        "+= -= *= /= %= .= **=",
        "Operator",
        "target op= expr",
        "The arithmetic and string compound assignments. Each reads the target, applies the matching binary operator, and stores the result back — including that operator's PHP 8 operand rules, so `$x = \"g\"; $x += 9;` is a `TypeError` just as `\"g\" + 9` is.",
        "$x = 10; $x += 5; $x .= \"!\"; echo $x;   // => 15!",
    ),
    (
        "&= |= ^= <<= >>=",
        "Operator",
        "target op= expr",
        "The bitwise compound assignments — AND, OR, XOR, left shift, and right shift applied in place.",
        "$m = 6; $m &= 3; echo $m;   // => 2",
    ),
    (
        "??=",
        "Operator",
        "target ??= expr",
        "Null-coalescing assignment: stores the right-hand value only when the target is null. It desugars to `target = (target ?? expr)`, so the target is read twice.",
        "$a = null; $a ??= 5; echo $a;   // => 5",
    ),
    (
        "==",
        "Operator",
        "expr == expr",
        "Loose equality with PHP 8 string/number comparison: a numeric string compares numerically against a number, while a non-numeric string makes the number a string first — so `\"abc\" == 0` is false.",
        "var_dump(\"10\" == 10, \"abc\" == 0);   // => bool(true) bool(false)",
    ),
    (
        "!=",
        "Operator",
        "expr != expr   //  also spelled <>",
        "Loose inequality — the negation of `==`. The legacy `<>` spelling lexes to the same operator.",
        "var_dump(1 != 2, 1 <> 1);   // => bool(true) bool(false)",
    ),
    (
        "===",
        "Operator",
        "expr === expr",
        "Strict equality: values must share a type and, for arrays and objects, be the same handle. It is also the comparison `match` uses for its arms.",
        "var_dump(\"10\" === 10, 10 === 10);   // => bool(false) bool(true)",
    ),
    (
        "!==",
        "Operator",
        "expr !== expr",
        "Strict inequality — the negation of `===`. `isset()` desugars to a chain of these against null.",
        "var_dump(\"10\" !== 10);   // => bool(true)",
    ),
    (
        "< > <= >=",
        "Operator",
        "expr < expr   //  and > <= >=",
        "Relational comparison using the same loose rules as `==`: numeric where both sides look numeric, string comparison otherwise.",
        "var_dump(2 < 10, \"2\" < \"10\");   // => bool(true) bool(true)",
    ),
    (
        "<=>",
        "Operator",
        "expr <=> expr: int",
        "The spaceship operator: `-1`, `0`, or `1` as the left operand sorts before, with, or after the right. It is the natural comparator for `usort`.",
        "echo 10 <=> 3;   // => 1",
    ),
    (
        "&& ||",
        "Operator",
        "expr && expr   //  expr || expr",
        "Short-circuiting logical AND and OR. The right operand is not evaluated when the left already decides the result. Both yield a real boolean.",
        "var_dump(true && false, false || true);   // => bool(false) bool(true)",
    ),
    (
        "!",
        "Operator",
        "!expr: bool",
        "Logical negation of the operand's truthiness. `empty($x)` desugars to exactly this.",
        "var_dump(!0, !\"a\");   // => bool(true) bool(false)",
    ),
    (
        "& | ^ ~",
        "Operator",
        "expr & expr   //  | ^ ;   ~expr",
        "Bitwise AND, OR, XOR, and one's-complement NOT over 64-bit integers. Both operands are cast to integers first. DIVERGENCE: `&`/`|`/`^` do not operate byte-wise on strings.",
        "echo 6 & 3, \" \", 6 | 3, \" \", 6 ^ 3, \" \", ~5;   // => 2 7 5 -6",
    ),
    (
        "<< >>",
        "Operator",
        "expr << expr   //  expr >> expr",
        "Arithmetic left and right shift on 64-bit integers. A shift count at or beyond 64 yields `0` for `<<` and the sign-fill (`0` or `-1`) for `>>` rather than wrapping.",
        "echo 1 << 4, \" \", -16 >> 2;   // => 16 -4",
    ),
    (
        "++ --",
        "Operator",
        "++target   target++   --target   target--",
        "Increment and decrement in prefix and postfix position. The prefix form evaluates to the new value, the postfix form to the old one. They apply to variables, array elements, properties, and static properties.",
        "$i = 5; echo $i++, $i, ++$i;   // => 567",
    ),
    (
        "?:",
        "Operator",
        "cond ? then : else\ncond ?: else",
        "The full ternary and the short `?:` (Elvis) form, which yields the condition itself when it is truthy.",
        "echo 1 ? \"a\" : \"b\", \"\" ?: \"fallback\";   // => afallback",
    ),
    (
        "??",
        "Operator",
        "expr ?? expr",
        "Null coalescing: the right operand is used when the left is null, and it is quiet about undefined variables and missing keys. Right-associative, so a chain falls through left to right.",
        "$a = null; echo $a ?? \"d\";   // => d",
    ),
    (
        "->",
        "Operator",
        "$object->property   $object->method(args)",
        "Instance member access — property read/write and method call. The member name is a bareword; `$o->$name` is not parsed.",
        "class C { public $x = 1; function f() { return 2; } }\n$o = new C; echo $o->x, $o->f();   // => 12",
    ),
    (
        "?->",
        "Operator",
        "$object?->property   $object?->method(args)",
        "Nullsafe member access: yields null instead of raising when the left operand is null, short-circuiting the rest of the chain.",
        "$o = null; var_dump($o?->x);   // => NULL",
    ),
    (
        "::",
        "Operator",
        "Class::CONST   Class::$staticProp   Class::method(args)   Class::class   $cls::CONST",
        "Scope resolution: class constants, static properties, static and parent method calls, and the `::class` name literal. The left side is either a bareword class name — `self`, `parent`, and `static` included — or a dereferenceable expression whose value names the class at run time: a string is the class name, an object contributes its own. A value that is neither is `Error: Class name must be a valid object or a string`, and a string naming nothing is `Error: Class \"X\" not found`. `::class` is stricter than the rest: it answers for an object only, and refuses even a class-name string with `TypeError: Cannot use \"::class\" on string`.",
        "class A { const K = 1; static $s = 2; } $c = \"A\"; echo A::K, $c::$s, (new A)::class;   // => 12A",
    ),
    (
        "[]",
        "Operator",
        "expr[index]   $array[] = expr",
        "Array and string indexing. A bare `$a[]` on the left of an assignment appends with the next integer key. String indexing is by byte offset and accepts a negative offset counting from the end.",
        "$a = [1, 2]; $a[] = 3; echo $a[2], \"abc\"[-1];   // => 3c",
    ),
    (
        "...",
        "Operator",
        "f(...$array)   function f(...$rest)   strlen(...)",
        "Three roles for one token: argument unpacking at a call site, a variadic parameter that collects the trailing arguments into an array, and — as the sole argument — PHP 8.1 first-class callable syntax, which builds a real `Closure`.",
        "function sum(...$n) { return array_sum($n); }\necho sum(...[1, 2, 3]);   // => 6\n$f = strlen(...); echo $f(\"abcd\");   // => 4",
    ),
    (
        "name:",
        "Operator",
        "f(paramName: value)",
        "PHP 8.0 named arguments. An identifier followed by a single `:` inside an argument list binds that argument to the named parameter, so arguments may be supplied out of order.",
        "function f($a, $b = \"z\") { return \"$a$b\"; } echo f(b: \"q\", a: 1);   // => 1q",
    ),
    (
        "@",
        "Operator",
        "@expr",
        "The error-suppression operator. The operand is evaluated exactly as it would be without the `@` and only the DIAGNOSTICS it raises are dropped — including the ones raised from inside the functions it calls, so `@preg_match('/[a', $s)` and `@range('ab', 'c')` are silent too. It is NOT an isset-mode read: `@$o->p` calls `__get` (where `isset($o->p)` would ask `__isset`), and it does not swallow an `Error`, so `@$o->privateProp` still throws. Suppression is restored when an exception unwinds out of the expression.",
        "echo @$undefined ?? \"quiet\";   // => quiet",
    ),
    (
        "\\",
        "Operator",
        "\\Name   Ns\\Name",
        "The namespace separator. Because phplang uses one flat namespace, a leading `\\` is skipped and a qualified name folds to its last segment — `\\RuntimeException` and `App\\Util\\RuntimeException` both resolve to `RuntimeException`.",
        "try { throw new \\Exception(\"x\"); } catch (\\Exception $e) { echo $e->getMessage(); }   // => x",
    ),
    (
        "$var \"…$var…\"",
        "Operator",
        "\"text $var text\"   //  double-quoted interpolation",
        "Double-quoted strings and heredoc-free literals interpolate a bare `$name`. DIVERGENCE: the braced form `{$expr}` is NOT interpolated — the braces are emitted literally around the substituted variable — and heredoc/nowdoc (`<<<EOT`) is not lexed at all.",
        "$s = \"ab\"; echo \"v=$s\";   // => v=ab\necho \"{$s}\";      // => {ab}   (PHP 8 prints: ab)",
    ),
    // ══ Cast ════════════════════════════════════════════════════════════════
    (
        "(int)",
        "Cast",
        "(int) expr   //  also (integer)",
        "Casts to integer by desugaring to a call to `intval`, which takes the leading numeric prefix of a string and yields `0` when there is none.",
        "echo (int) \"42px\";   // => 42",
    ),
    (
        "(float)",
        "Cast",
        "(float) expr   //  also (double), (real)",
        "Casts to float by desugaring to `floatval`. All three spellings map to the same call.",
        "echo (float) \"3.5kg\";   // => 3.5",
    ),
    (
        "(string)",
        "Cast",
        "(string) expr",
        "Casts to string by desugaring to `strval`. DIVERGENCE: an object stringifies to `Array` because `__toString` is not consulted.",
        "echo (string) 123;   // => 123",
    ),
    (
        "(bool)",
        "Cast",
        "(bool) expr   //  also (boolean)",
        "Casts to boolean by desugaring to `boolval`. Falsey values are `0`, `0.0`, `\"\"`, `\"0\"`, the empty array, and null.",
        "var_dump((bool) 0, (bool) \"0\", (bool) \"a\");   // => bool(false) bool(false) bool(true)",
    ),
    (
        "(array) (object) (unset)",
        "Cast",
        "(array) expr   //  NOT SUPPORTED",
        "Listed for completeness: `cast_fn` in `src/parser.rs` maps only int, float, string, and bool. `(array)`, `(object)`, and `(unset)` are not recognized as casts, so `(array) $x` parses as a constant fetch of the bareword `array` followed by `$x` and is a syntax error.",
        "",
    ),
    // ══ Magic method ════════════════════════════════════════════════════════
    (
        "__construct",
        "Magic method",
        "public function __construct(mixed ...$args)",
        "The constructor, invoked automatically by `new`. A parameter carrying a visibility or `readonly` keyword is promoted to a property of the same name and assigned before the body runs.",
        "class P { function __construct(public $x) {} } echo (new P(4))->x;   // => 4",
    ),
    (
        "__invoke",
        "Magic method",
        "public function __invoke(mixed ...$args): mixed",
        "Called when a value is used as a function. Declaring it makes every instance of the class callable — `$obj(…)`, `is_callable($obj)`, and passing `$obj` where a callback is expected (`array_map`, `usort`, `Closure::fromCallable`) all resolve through it.",
        "class Twice { public function __invoke($x) { return $x * 2; } }\necho (new Twice)(21);   // => 42",
    ),
    (
        "__toString",
        "Magic method",
        "public function __toString(): string",
        "Declared by the prelude `Exception` and `Error` classes and callable like any other method. DIVERGENCE: the runtime never invokes it implicitly — `echo $obj`, `(string) $obj`, and interpolation all produce `Array`, so it must be called explicitly.",
        "class C { function __toString() { return \"S\"; } }\n$o = new C; echo $o->__toString(), \"|\", $o;   // => S|Array",
    ),
    (
        "__get",
        "Magic method",
        "public function __get(string $name): mixed",
        "Called when a property is read that the object does not carry — because no class declared it, because it was `unset`, or because its visibility puts it out of reach of the reading scope. Consulted BEFORE any access error, so a class with `__get` never reports `Cannot access private property`. While it runs for a given property it is not re-entered for that same property, so `__get($n) { return $this->$n; }` terminates rather than recursing.",
        "class C { function __get($n) { return \"g:$n\"; } } echo (new C)->zz;   // => g:zz",
    ),
    (
        "__set",
        "Magic method",
        "public function __set(string $name, mixed $value): void",
        "Called when a property is WRITTEN that the object does not carry or cannot reach. A write it handles creates no real property, so `get_object_vars` stays empty. In a read-modify-write (`$o->p .= \"x\"`, `$o->p++`) it is used only when the class ALSO defines `__get`: `__set` is half of a pair, and without `__get` supplying the old value the reference reads and writes the property directly instead.",
        "class C { function __set($n, $v) { echo \"set:$n\"; } } $o = new C; $o->zz = 1;   // => set:zz",
    ),
    (
        "__isset",
        "Magic method",
        "public function __isset(string $name): bool",
        "Called by `isset()` and `empty()` on a property the object does not carry or cannot reach. It answers the question by itself for `isset()`; for `empty()` and `??` a true answer is then followed by `__get` to obtain the value.",
        "class C { function __isset($n) { return $n === \"ok\"; } }\n$o = new C; var_dump(isset($o->ok), isset($o->no));   // => bool(true) bool(false)",
    ),
    (
        "__unset",
        "Magic method",
        "public function __unset(string $name): void",
        "Called by `unset()` on a property the object does not carry or cannot reach. Like the others it is consulted before any access error, so a class defining it can be asked to unset a private property from outside without a fatal.",
        "class C { function __unset($n) { echo \"unset:$n\"; } }\n$o = new C; unset($o->zz);   // => unset:zz",
    ),
    (
        "__rust_compile",
        "Magic method",
        "__rust_compile(string $base64Body, int $line): void",
        "The internal builtin a `rust { … }` block desugars to. It compiles and loads the encoded Rust body and registers each exported `pub extern \"C\"` function under its bare name. Programs call it only through the `rust` construct, never directly.",
        "",
    ),
    // ══ Predefined constant ═════════════════════════════════════════════════
    // Seeded onto every fresh host by `predefined_constants()` in `src/host.rs`.
    // Constant lookup is case-SENSITIVE, and an undefined bareword resolves to
    // its own name as a string rather than raising.
    (
        "PHP_INT_MAX",
        "Predefined constant",
        "PHP_INT_MAX: int = 9223372036854775807",
        "The largest representable integer. phplang integers are 64-bit signed, so this is `i64::MAX`.",
        "echo PHP_INT_MAX;   // => 9223372036854775807",
    ),
    (
        "PHP_INT_MIN",
        "Predefined constant",
        "PHP_INT_MIN: int = -9223372036854775808",
        "The smallest representable integer, `i64::MIN`.",
        "",
    ),
    (
        "PHP_INT_SIZE",
        "Predefined constant",
        "PHP_INT_SIZE: int = 8",
        "Integer width in bytes. Always 8 — phplang has no 32-bit build.",
        "",
    ),
    (
        "PHP_FLOAT_DIG",
        "Predefined constant",
        "PHP_FLOAT_DIG: int = 15",
        "Number of decimal digits a float can round-trip.",
        "",
    ),
    (
        "PHP_FLOAT_EPSILON",
        "Predefined constant",
        "PHP_FLOAT_EPSILON: float = 2.220446049250313E-16",
        "The smallest positive value that, added to 1.0, produces a different float (`f64::EPSILON`).",
        "",
    ),
    (
        "PHP_FLOAT_MAX",
        "Predefined constant",
        "PHP_FLOAT_MAX: float = 1.7976931348623157E+308",
        "The largest finite float, `f64::MAX`.",
        "",
    ),
    (
        "PHP_FLOAT_MIN",
        "Predefined constant",
        "PHP_FLOAT_MIN: float = 2.2250738585072014E-308",
        "The smallest positive normalized float, `f64::MIN_POSITIVE`.",
        "",
    ),
    (
        "INF",
        "Predefined constant",
        "INF: float = f64::INFINITY",
        "Positive floating-point infinity. `is_infinite(INF)` is true.",
        "",
    ),
    (
        "NAN",
        "Predefined constant",
        "NAN: float = f64::NAN",
        "The floating-point not-a-number value. It compares unequal to everything, including itself.",
        "",
    ),
    (
        "PHP_VERSION",
        "Predefined constant",
        "PHP_VERSION: string = \"8.3.0\"",
        "The PHP language version phplang targets, reported as a fixed string.",
        "echo PHP_VERSION;   // => 8.3.0",
    ),
    (
        "PHP_MAJOR_VERSION",
        "Predefined constant",
        "PHP_MAJOR_VERSION: int = 8",
        "Major component of `PHP_VERSION`.",
        "",
    ),
    (
        "PHP_MINOR_VERSION",
        "Predefined constant",
        "PHP_MINOR_VERSION: int = 3",
        "Minor component of `PHP_VERSION`.",
        "",
    ),
    (
        "PHP_RELEASE_VERSION",
        "Predefined constant",
        "PHP_RELEASE_VERSION: int = 0",
        "Release component of `PHP_VERSION`.",
        "",
    ),
    (
        "PHP_VERSION_ID",
        "Predefined constant",
        "PHP_VERSION_ID: int = 80300",
        "The version as a single comparable integer, `major*10000 + minor*100 + release`.",
        "",
    ),
    (
        "PHP_OS",
        "Predefined constant",
        "PHP_OS: string = \"Darwin\" | \"WINNT\" | \"Linux\"",
        "The host operating system, resolved at COMPILE time from `cfg!(target_os)` rather than by a runtime `uname(2)`.",
        "",
    ),
    (
        "PHP_OS_FAMILY",
        "Predefined constant",
        "PHP_OS_FAMILY: string = \"Windows\" | \"Darwin\" | \"Linux\"",
        "The operating-system family, also decided at compile time. Every non-Windows, non-macOS target reports `Linux`.",
        "",
    ),
    (
        "PHP_EOL",
        "Predefined constant",
        "PHP_EOL: string = \"\\n\"",
        "The platform line terminator. DIVERGENCE: it is `\\n` unconditionally, including on Windows builds where PHP uses `\\r\\n`.",
        "echo \"a\" . PHP_EOL . \"b\";   // => a<newline>b",
    ),
    (
        "DIRECTORY_SEPARATOR",
        "Predefined constant",
        "DIRECTORY_SEPARATOR: string = \"/\" | \"\\\\\"",
        "The path component separator, `\\` on Windows builds and `/` everywhere else.",
        "",
    ),
    (
        "PATH_SEPARATOR",
        "Predefined constant",
        "PATH_SEPARATOR: string = \":\" | \";\"",
        "The separator between entries in a path list, `;` on Windows builds and `:` everywhere else.",
        "",
    ),
    (
        "PHP_ROUND_HALF_UP",
        "Predefined constant",
        "PHP_ROUND_HALF_UP: int = 1",
        "Rounding mode: halves away from zero. This is the behaviour `round()` always uses — the mode argument is not read.",
        "",
    ),
    (
        "PHP_ROUND_HALF_DOWN",
        "Predefined constant",
        "PHP_ROUND_HALF_DOWN: int = 2",
        "Rounding mode: halves toward zero. Defined for source compatibility; `round()` ignores the mode argument.",
        "",
    ),
    (
        "PHP_ROUND_HALF_EVEN",
        "Predefined constant",
        "PHP_ROUND_HALF_EVEN: int = 3",
        "Rounding mode: halves to the nearest even value. Honoured: `round(2.5, 0, PHP_ROUND_HALF_EVEN)` is `2` and `round(3.5, 0, PHP_ROUND_HALF_EVEN)` is `4`.",
        "",
    ),
    (
        "PHP_ROUND_HALF_ODD",
        "Predefined constant",
        "PHP_ROUND_HALF_ODD: int = 4",
        "Rounding mode: halves to the nearest odd value. Honoured: `round(2.5, 0, PHP_ROUND_HALF_ODD)` is `3` and `round(3.5, 0, PHP_ROUND_HALF_ODD)` is `3`.",
        "",
    ),
    (
        "E_ERROR",
        "Predefined constant",
        "E_ERROR: int = 1",
        "Error level for a fatal runtime error. phplang has no error-level machinery, so this is a value for scripts to pass around.",
        "",
    ),
    (
        "E_WARNING",
        "Predefined constant",
        "E_WARNING: int = 2",
        "Error level for a non-fatal runtime warning.",
        "",
    ),
    (
        "E_PARSE",
        "Predefined constant",
        "E_PARSE: int = 4",
        "Error level for a compile-time parse error.",
        "",
    ),
    (
        "E_NOTICE",
        "Predefined constant",
        "E_NOTICE: int = 8",
        "Error level for a runtime notice.",
        "",
    ),
    (
        "E_STRICT",
        "Predefined constant",
        "E_STRICT: int = 2048",
        "Error level for interoperability suggestions. The level was REMOVED in PHP 8.4 — nothing raises it and it is not part of `E_ALL` — but the constant remains so an existing `E_ALL & ~E_STRICT` still parses.",
        "",
    ),
    (
        "E_DEPRECATED",
        "Predefined constant",
        "E_DEPRECATED: int = 8192",
        "Error level for a deprecation notice.",
        "",
    ),
    (
        "E_ALL",
        "Predefined constant",
        "E_ALL: int = 30719",
        "Every error level that still exists. It is 30719, not the pre-8.4 32767: PHP 8.4 removed `E_STRICT` and took its bit out of `E_ALL`, so `E_ALL & E_STRICT` is 0. This is also the level a program starts at unless `-d error_reporting=…` says otherwise.",
        "echo E_ALL, \"|\", E_ALL & E_STRICT;   // => 30719|0",
    ),
    (
        "E_USER_ERROR",
        "Predefined constant",
        "E_USER_ERROR: int = 256",
        "User-generated error level. Passed to `trigger_error()`, it prints `Fatal error: …` to stderr but does NOT halt the program.",
        "",
    ),
    (
        "E_USER_WARNING",
        "Predefined constant",
        "E_USER_WARNING: int = 512",
        "User-generated warning level; `trigger_error()` labels it `Warning`.",
        "",
    ),
    (
        "E_USER_NOTICE",
        "Predefined constant",
        "E_USER_NOTICE: int = 1024",
        "User-generated notice level and the default for `trigger_error()`, which labels it `Notice`.",
        "",
    ),
    (
        "E_USER_DEPRECATED",
        "Predefined constant",
        "E_USER_DEPRECATED: int = 16384",
        "User-generated deprecation level; `trigger_error()` labels it `Deprecated`.",
        "",
    ),
    (
        "SORT_REGULAR",
        "Predefined constant",
        "SORT_REGULAR: int = 0",
        "Sort flag for comparing items normally. phplang's sorts always compare this way — the flag argument is not read.",
        "",
    ),
    (
        "SORT_NUMERIC",
        "Predefined constant",
        "SORT_NUMERIC: int = 1",
        "Sort flag for numeric comparison. Accepted by `array_multisort` as a column type marker; the plain sorts ignore it.",
        "",
    ),
    (
        "SORT_STRING",
        "Predefined constant",
        "SORT_STRING: int = 2",
        "Sort flag for string comparison, with the same limited effect as `SORT_NUMERIC`.",
        "",
    ),
    (
        "SORT_DESC",
        "Predefined constant",
        "SORT_DESC: int = 3",
        "Descending sort order for `array_multisort` columns.",
        "",
    ),
    (
        "SORT_ASC",
        "Predefined constant",
        "SORT_ASC: int = 4",
        "Ascending sort order for `array_multisort` columns, and its default.",
        "",
    ),
    (
        "SORT_LOCALE_STRING",
        "Predefined constant",
        "SORT_LOCALE_STRING: int = 5",
        "Locale-aware string sort flag. Defined for compatibility; phplang has no locale support.",
        "",
    ),
    (
        "SORT_NATURAL",
        "Predefined constant",
        "SORT_NATURAL: int = 6",
        "Natural-order sort flag. Use `natsort()` for the real behaviour — the plain sorts do not read the flag.",
        "",
    ),
    (
        "SORT_FLAG_CASE",
        "Predefined constant",
        "SORT_FLAG_CASE: int = 8",
        "Bit combined with `SORT_STRING` or `SORT_NATURAL` to fold case. Honoured: `sort($a, SORT_STRING|SORT_FLAG_CASE)` orders `[\"B\", \"a\"]` as `[\"a\", \"B\"]`.",
        "",
    ),
    (
        "COUNT_NORMAL",
        "Predefined constant",
        "COUNT_NORMAL: int = 0",
        "`count()` mode counting only top-level elements. This is the only mode implemented.",
        "",
    ),
    (
        "COUNT_RECURSIVE",
        "Predefined constant",
        "COUNT_RECURSIVE: int = 1",
        "`count()` mode that counts nested elements too: a nested array counts as one element AND contributes its own contents, at every depth. Recursion is into arrays only — a nested `Countable` is a single element and its own `count()` is not consulted.",
        "echo count([1, [2, 3]], COUNT_RECURSIVE);   // => 4",
    ),
    (
        "STR_PAD_RIGHT",
        "Predefined constant",
        "STR_PAD_RIGHT: int = 1",
        "`str_pad()` / `mb_str_pad()` mode padding on the right. The default, and the fallback for an unrecognized mode.",
        "",
    ),
    (
        "STR_PAD_LEFT",
        "Predefined constant",
        "STR_PAD_LEFT: int = 0",
        "`str_pad()` / `mb_str_pad()` mode padding on the left.",
        "echo str_pad(\"5\", 3, \"0\", STR_PAD_LEFT);   // => 005",
    ),
    (
        "STR_PAD_BOTH",
        "Predefined constant",
        "STR_PAD_BOTH: int = 2",
        "`str_pad()` / `mb_str_pad()` mode padding on both sides, with the left side floored.",
        "",
    ),
    (
        "ARRAY_FILTER_USE_KEY",
        "Predefined constant",
        "ARRAY_FILTER_USE_KEY: int = 2",
        "`array_filter()` mode passing only the key to the callback.",
        "",
    ),
    (
        "ARRAY_FILTER_USE_BOTH",
        "Predefined constant",
        "ARRAY_FILTER_USE_BOTH: int = 1",
        "`array_filter()` mode passing the value and then the key to the callback.",
        "",
    ),
    (
        "PREG_PATTERN_ORDER",
        "Predefined constant",
        "PREG_PATTERN_ORDER: int = 1",
        "`preg_match_all()` ordering that groups results by capture group: `$matches[group][set]`. The default.",
        "",
    ),
    (
        "PREG_SET_ORDER",
        "Predefined constant",
        "PREG_SET_ORDER: int = 2",
        "`preg_match_all()` ordering that groups results by match: `$matches[set][group]`. This bit is honoured.",
        "",
    ),
    (
        "PREG_OFFSET_CAPTURE",
        "Predefined constant",
        "PREG_OFFSET_CAPTURE: int = 256",
        "Turns every `$matches` cell into a `[text, offset]` pair. The offset is a BYTE position, which is what PHP reports even under `/u`, where the subject is walked as UTF-8 but positions are still counted in bytes. A group that did not participate is `['', -1]`, not `['', 0]`. Honoured by `preg_match`, `preg_match_all` and `preg_replace_callback`; `preg_split` has its own separate `PREG_SPLIT_OFFSET_CAPTURE` bit.",
        "",
    ),
    (
        "PREG_UNMATCHED_AS_NULL",
        "Predefined constant",
        "PREG_UNMATCHED_AS_NULL: int = 512",
        "Reports a non-participating group as null rather than an empty string, and SUPPRESSES the trailing-unmatched trim so the row keeps its full width. Combined with `PREG_OFFSET_CAPTURE` such a cell is `[null, -1]`.",
        "",
    ),
    (
        "PREG_SPLIT_NO_EMPTY",
        "Predefined constant",
        "PREG_SPLIT_NO_EMPTY: int = 1",
        "`preg_split()` flag dropping empty pieces from the result. Honoured.",
        "",
    ),
    (
        "PREG_SPLIT_DELIM_CAPTURE",
        "Predefined constant",
        "PREG_SPLIT_DELIM_CAPTURE: int = 2",
        "`preg_split()` flag interleaving captured delimiter groups into the result. Honoured.",
        "",
    ),
    (
        "PREG_SPLIT_OFFSET_CAPTURE",
        "Predefined constant",
        "PREG_SPLIT_OFFSET_CAPTURE: int = 4",
        "`preg_split()` flag emitting `[piece, byteOffset]` pairs instead of bare strings. Honoured.",
        "",
    ),
    (
        "JSON_HEX_TAG",
        "Predefined constant",
        "JSON_HEX_TAG: int = 1",
        "`json_encode()` flag escaping `<` and `>` as `\\u003C` and `\\u003E`. The hex digits are UPPER case, where the control and unicode escapes spell theirs in lower.",
        "",
    ),
    (
        "JSON_HEX_AMP",
        "Predefined constant",
        "JSON_HEX_AMP: int = 2",
        "`json_encode()` flag escaping `&` as `\\u0026`.",
        "",
    ),
    (
        "JSON_HEX_APOS",
        "Predefined constant",
        "JSON_HEX_APOS: int = 4",
        "`json_encode()` flag escaping `'` as `\\u0027`.",
        "",
    ),
    (
        "JSON_HEX_QUOT",
        "Predefined constant",
        "JSON_HEX_QUOT: int = 8",
        "`json_encode()` flag escaping `\"` as `\\u0022` instead of `\\\"`.",
        "",
    ),
    (
        "JSON_FORCE_OBJECT",
        "Predefined constant",
        "JSON_FORCE_OBJECT: int = 16",
        "`json_encode()` flag emitting a JSON object even for an array whose keys are already `0..n`.",
        "",
    ),
    (
        "JSON_NUMERIC_CHECK",
        "Predefined constant",
        "JSON_NUMERIC_CHECK: int = 32",
        "`json_encode()` flag encoding a numeric string as the number it reads as, by PHP's own `is_numeric_string` — so `\" 5\"` and `\"5 \"` convert while `\"0x1A\"` does not. An integral result loses its fractional part (`\"1e3\"` encodes as `1000`), and a string that reads as a non-finite double (`\"1e999\"`) stays a string. Array KEYS are unaffected; JSON has no non-string key.",
        "",
    ),
    (
        "JSON_UNESCAPED_SLASHES",
        "Predefined constant",
        "JSON_UNESCAPED_SLASHES: int = 64",
        "`json_encode()` flag leaving `/` unescaped, where the default writes `\\/`.",
        "",
    ),
    (
        "JSON_PRETTY_PRINT",
        "Predefined constant",
        "JSON_PRETTY_PRINT: int = 128",
        "`json_encode()` flag requesting indented output: four spaces per level, and `\": \"` rather than `\":\"` after a key.",
        "echo json_encode([\"a\" => 1], JSON_PRETTY_PRINT);   // => {\n    \"a\": 1\n}",
    ),
    (
        "JSON_UNESCAPED_UNICODE",
        "Predefined constant",
        "JSON_UNESCAPED_UNICODE: int = 256",
        "`json_encode()` flag emitting literal UTF-8 instead of `\\uXXXX`.",
        "",
    ),
    (
        "JSON_THROW_ON_ERROR",
        "Predefined constant",
        "JSON_THROW_ON_ERROR: int = 4194304",
        "Flag asking the JSON functions to throw `JsonException` instead of returning `false`/null. Honoured by `json_encode`, `json_decode` and `json_validate`: the exception's `getCode()` is the `JSON_ERROR_*` constant, and `json_last_error()` is left at `JSON_ERROR_NONE` because the failure travelled on the throw instead of being recorded for a later read.",
        "",
    ),
    (
        "JSON_OBJECT_AS_ARRAY",
        "Predefined constant",
        "JSON_OBJECT_AS_ARRAY: int = 1",
        "`json_decode()` flag decoding JSON objects as PHP arrays. Consulted only when `$associative` is left null, which is `ext/json`'s own precedence — an explicit `$associative` wins over the flag in both directions.",
        "",
    ),
    (
        "JSON_BIGINT_AS_STRING",
        "Predefined constant",
        "JSON_BIGINT_AS_STRING: int = 2",
        "`json_decode()` flag keeping oversized integers as strings. DIVERGENCE: not honoured — an integer beyond `i64` decodes to a float.",
        "",
    ),
    (
        "JSON_ERROR_NONE",
        "Predefined constant",
        "JSON_ERROR_NONE: int = 0",
        "`json_last_error()` code meaning the last decode succeeded.",
        "",
    ),
    (
        "JSON_ERROR_DEPTH",
        "Predefined constant",
        "JSON_ERROR_DEPTH: int = 1",
        "`json_last_error()` code meaning the maximum nesting depth was exceeded.",
        "",
    ),
    (
        "JSON_ERROR_STATE_MISMATCH",
        "Predefined constant",
        "JSON_ERROR_STATE_MISMATCH: int = 2",
        "`json_last_error()` code for invalid or malformed JSON.",
        "",
    ),
    (
        "JSON_ERROR_CTRL_CHAR",
        "Predefined constant",
        "JSON_ERROR_CTRL_CHAR: int = 3",
        "`json_last_error()` code for a raw control character inside a string.",
        "",
    ),
    (
        "JSON_ERROR_SYNTAX",
        "Predefined constant",
        "JSON_ERROR_SYNTAX: int = 4",
        "`json_last_error()` code for a syntax error.",
        "",
    ),
    (
        "JSON_ERROR_UTF8",
        "Predefined constant",
        "JSON_ERROR_UTF8: int = 5",
        "`json_last_error()` code for malformed UTF-8. The decoder also uses code 6 for an unpaired UTF-16 surrogate, which has no seeded constant.",
        "",
    ),
    (
        "PHP_URL_SCHEME",
        "Predefined constant",
        "PHP_URL_SCHEME: int = 0",
        "`parse_url()`'s `$component` selector for the scheme (`https`). A component the URL does not carry reads back as null.",
        "",
    ),
    (
        "PHP_URL_HOST",
        "Predefined constant",
        "PHP_URL_HOST: int = 1",
        "`parse_url()`'s `$component` selector for the host. A component the URL does not carry reads back as null.",
        "",
    ),
    (
        "PHP_URL_PORT",
        "Predefined constant",
        "PHP_URL_PORT: int = 2",
        "`parse_url()`'s `$component` selector for the port, as an int. A component the URL does not carry reads back as null.",
        "",
    ),
    (
        "PHP_URL_USER",
        "Predefined constant",
        "PHP_URL_USER: int = 3",
        "`parse_url()`'s `$component` selector for the userinfo user. A component the URL does not carry reads back as null.",
        "",
    ),
    (
        "PHP_URL_PASS",
        "Predefined constant",
        "PHP_URL_PASS: int = 4",
        "`parse_url()`'s `$component` selector for the userinfo password. A component the URL does not carry reads back as null.",
        "",
    ),
    (
        "PHP_URL_PATH",
        "Predefined constant",
        "PHP_URL_PATH: int = 5",
        "`parse_url()`'s `$component` selector for the path. A component the URL does not carry reads back as null.",
        "",
    ),
    (
        "PHP_URL_QUERY",
        "Predefined constant",
        "PHP_URL_QUERY: int = 6",
        "`parse_url()`'s `$component` selector for the query string, without the `?`. A component the URL does not carry reads back as null.",
        "",
    ),
    (
        "PHP_URL_FRAGMENT",
        "Predefined constant",
        "PHP_URL_FRAGMENT: int = 7",
        "`parse_url()`'s `$component` selector for the fragment, without the `#`. A component the URL does not carry reads back as null.",
        "",
    ),
    (
        "INPUT_GET",
        "Predefined constant",
        "INPUT_GET: int = 1",
        "`filter_has_var()` input source for query parameters. phplang is standalone with no request context, so the lookup always reports false.",
        "",
    ),
    (
        "INPUT_POST",
        "Predefined constant",
        "INPUT_POST: int = 0",
        "`filter_has_var()` input source for form-body parameters, with the same always-false result.",
        "",
    ),
    (
        "FILTER_DEFAULT",
        "Predefined constant",
        "FILTER_DEFAULT: int = 516",
        "`filter_var()` filter that returns the value string-cast without validating. Also the fallback for any unrecognized filter id.",
        "",
    ),
    (
        "FILTER_UNSAFE_RAW",
        "Predefined constant",
        "FILTER_UNSAFE_RAW: int = 516",
        "The same id as `FILTER_DEFAULT` — an unfiltered string-cast pass-through.",
        "",
    ),
    (
        "FILTER_VALIDATE_INT",
        "Predefined constant",
        "FILTER_VALIDATE_INT: int = 257",
        "Validates an integer, honouring `min_range`/`max_range` options and the hex/octal flags. Leading zeros are rejected.",
        "var_dump(filter_var(\"42\", FILTER_VALIDATE_INT));   // => int(42)",
    ),
    (
        "FILTER_VALIDATE_BOOLEAN",
        "Predefined constant",
        "FILTER_VALIDATE_BOOLEAN: int = 258",
        "Validates a boolean: `1/true/on/yes` are true, `0/false/off/no/\"\"` are false, anything else fails.",
        "",
    ),
    (
        "FILTER_VALIDATE_BOOL",
        "Predefined constant",
        "FILTER_VALIDATE_BOOL: int = 258",
        "The PHP 8 spelling of `FILTER_VALIDATE_BOOLEAN`, sharing its id and behaviour.",
        "",
    ),
    (
        "FILTER_VALIDATE_FLOAT",
        "Predefined constant",
        "FILTER_VALIDATE_FLOAT: int = 259",
        "Validates a float. Every byte must be in `[0-9+-.eE]`, so `inf` and `nan` fail, and a non-finite result is rejected.",
        "",
    ),
    (
        "FILTER_VALIDATE_REGEXP",
        "Predefined constant",
        "FILTER_VALIDATE_REGEXP: int = 272",
        "Validates against the `options['regexp']` pattern, compiled by the same engine pair `preg_match` uses — so the delimiter rules, the modifier set, look-around and backreferences all behave identically, and a pattern fault raises `Warning: filter_var(): <reason>` and sets `preg_last_error()` exactly as the reference does.",
        "",
    ),
    (
        "FILTER_VALIDATE_DOMAIN",
        "Predefined constant",
        "FILTER_VALIDATE_DOMAIN: int = 277",
        "Validates a 1-253 byte domain, adding an RFC 1123 label check only when `FILTER_FLAG_HOSTNAME` is set.",
        "",
    ),
    (
        "FILTER_VALIDATE_URL",
        "Predefined constant",
        "FILTER_VALIDATE_URL: int = 273",
        "Validates a URL, requiring both a scheme and a host.",
        "",
    ),
    (
        "FILTER_VALIDATE_EMAIL",
        "Predefined constant",
        "FILTER_VALIDATE_EMAIL: int = 274",
        "Validates an email address of at most 320 bytes against a dotted-domain pattern.",
        "var_dump(filter_var(\"a@b.co\", FILTER_VALIDATE_EMAIL));   // => string(6) \"a@b.co\"",
    ),
    (
        "FILTER_VALIDATE_IP",
        "Predefined constant",
        "FILTER_VALIDATE_IP: int = 275",
        "Validates an IP address with `std::net`, gated by the IPv4/IPv6 flags. The private- and reserved-range flags are not implemented.",
        "",
    ),
    (
        "FILTER_VALIDATE_MAC",
        "Predefined constant",
        "FILTER_VALIDATE_MAC: int = 276",
        "Validates a MAC address in the 17-character `:`/`-` form or the 14-character `xxxx.xxxx.xxxx` form.",
        "",
    ),
    (
        "FILTER_SANITIZE_STRING",
        "Predefined constant",
        "FILTER_SANITIZE_STRING: int = 513",
        "Strips `<…>` tags then encodes `\"` and `'` as numeric entities. Sanitizers never fail.",
        "",
    ),
    (
        "FILTER_SANITIZE_STRIPPED",
        "Predefined constant",
        "FILTER_SANITIZE_STRIPPED: int = 513",
        "The legacy alias of `FILTER_SANITIZE_STRING`, sharing its id.",
        "",
    ),
    (
        "FILTER_SANITIZE_ENCODED",
        "Predefined constant",
        "FILTER_SANITIZE_ENCODED: int = 514",
        "URL-encoding sanitizer id. DIVERGENCE: not implemented — it falls through to the `FILTER_DEFAULT` pass-through.",
        "",
    ),
    (
        "FILTER_SANITIZE_SPECIAL_CHARS",
        "Predefined constant",
        "FILTER_SANITIZE_SPECIAL_CHARS: int = 515",
        "Encodes `&`, `<`, `>`, `\"`, and `'` as numeric character references.",
        "",
    ),
    (
        "FILTER_SANITIZE_FULL_SPECIAL_CHARS",
        "Predefined constant",
        "FILTER_SANITIZE_FULL_SPECIAL_CHARS: int = 522",
        "Encodes the same five characters as named entities: `&amp;`, `&lt;`, `&gt;`, `&quot;`, `&#039;`.",
        "",
    ),
    (
        "FILTER_SANITIZE_EMAIL",
        "Predefined constant",
        "FILTER_SANITIZE_EMAIL: int = 517",
        "Keeps only characters legal in an email address, dropping everything else.",
        "",
    ),
    (
        "FILTER_SANITIZE_URL",
        "Predefined constant",
        "FILTER_SANITIZE_URL: int = 518",
        "Keeps only characters legal in a URL.",
        "",
    ),
    (
        "FILTER_SANITIZE_NUMBER_INT",
        "Predefined constant",
        "FILTER_SANITIZE_NUMBER_INT: int = 519",
        "Keeps only digits and the `+`/`-` signs.",
        "",
    ),
    (
        "FILTER_SANITIZE_NUMBER_FLOAT",
        "Predefined constant",
        "FILTER_SANITIZE_NUMBER_FLOAT: int = 520",
        "Keeps digits and signs, plus `.`, `,`, and `e`/`E` when the matching ALLOW flag is set.",
        "",
    ),
    (
        "FILTER_SANITIZE_ADD_SLASHES",
        "Predefined constant",
        "FILTER_SANITIZE_ADD_SLASHES: int = 523",
        "Backslash-escaping sanitizer id. DIVERGENCE: not implemented — it falls through to the `FILTER_DEFAULT` pass-through.",
        "",
    ),
    (
        "FILTER_FLAG_ALLOW_OCTAL",
        "Predefined constant",
        "FILTER_FLAG_ALLOW_OCTAL: int = 1",
        "Lets `FILTER_VALIDATE_INT` accept an unsigned `0`-prefixed octal literal.",
        "",
    ),
    (
        "FILTER_FLAG_ALLOW_HEX",
        "Predefined constant",
        "FILTER_FLAG_ALLOW_HEX: int = 2",
        "Lets `FILTER_VALIDATE_INT` accept an unsigned `0x`-prefixed hex literal.",
        "",
    ),
    (
        "FILTER_FLAG_STRIP_LOW",
        "Predefined constant",
        "FILTER_FLAG_STRIP_LOW: int = 4",
        "Flag asking sanitizers to drop bytes below 0x20. DIVERGENCE: not implemented.",
        "",
    ),
    (
        "FILTER_FLAG_STRIP_HIGH",
        "Predefined constant",
        "FILTER_FLAG_STRIP_HIGH: int = 8",
        "Flag asking sanitizers to drop bytes at or above 0x80. DIVERGENCE: not implemented.",
        "",
    ),
    (
        "FILTER_FLAG_ALLOW_FRACTION",
        "Predefined constant",
        "FILTER_FLAG_ALLOW_FRACTION: int = 4096",
        "Lets `FILTER_SANITIZE_NUMBER_FLOAT` keep `.`.",
        "",
    ),
    (
        "FILTER_FLAG_ALLOW_THOUSAND",
        "Predefined constant",
        "FILTER_FLAG_ALLOW_THOUSAND: int = 8192",
        "Lets `FILTER_SANITIZE_NUMBER_FLOAT` keep `,`, and lets `FILTER_VALIDATE_FLOAT` strip it before parsing.",
        "",
    ),
    (
        "FILTER_FLAG_ALLOW_SCIENTIFIC",
        "Predefined constant",
        "FILTER_FLAG_ALLOW_SCIENTIFIC: int = 16384",
        "Lets `FILTER_SANITIZE_NUMBER_FLOAT` keep `e` and `E`.",
        "",
    ),
    (
        "FILTER_FLAG_IPV4",
        "Predefined constant",
        "FILTER_FLAG_IPV4: int = 1048576",
        "Restricts `FILTER_VALIDATE_IP` to IPv4. It shares its integer with `FILTER_FLAG_HOSTNAME`, so passing it to `FILTER_VALIDATE_DOMAIN` silently enables the hostname check.",
        "",
    ),
    (
        "FILTER_FLAG_IPV6",
        "Predefined constant",
        "FILTER_FLAG_IPV6: int = 2097152",
        "Restricts `FILTER_VALIDATE_IP` to IPv6. Setting neither family flag, or both, accepts either.",
        "",
    ),
    (
        "FILTER_FLAG_HOSTNAME",
        "Predefined constant",
        "FILTER_FLAG_HOSTNAME: int = 1048576",
        "Adds an RFC 1123 label check to `FILTER_VALIDATE_DOMAIN`. Shares its integer with `FILTER_FLAG_IPV4`.",
        "",
    ),
    (
        "FILTER_NULL_ON_FAILURE",
        "Predefined constant",
        "FILTER_NULL_ON_FAILURE: int = 134217728",
        "Makes a failing `filter_var()` return null instead of false. Honoured by every validating filter.",
        "",
    ),
    (
        "FILTER_REQUIRE_SCALAR",
        "Predefined constant",
        "FILTER_REQUIRE_SCALAR: int = 33554432",
        "Flag requiring a scalar subject. Redundant here: an array subject already fails every filter.",
        "",
    ),
    (
        "FILTER_REQUIRE_ARRAY",
        "Predefined constant",
        "FILTER_REQUIRE_ARRAY: int = 16777216",
        "Flag requiring an array subject. DIVERGENCE: not implemented.",
        "",
    ),
    (
        "FILTER_FORCE_ARRAY",
        "Predefined constant",
        "FILTER_FORCE_ARRAY: int = 67108864",
        "Flag wrapping a scalar result in an array. DIVERGENCE: not implemented.",
        "",
    ),
    (
        "MB_CASE_UPPER",
        "Predefined constant",
        "MB_CASE_UPPER: int = 0",
        "`mb_convert_case()` mode uppercasing the whole string. Also the fallback for any unrecognized mode.",
        "",
    ),
    (
        "MB_CASE_LOWER",
        "Predefined constant",
        "MB_CASE_LOWER: int = 1",
        "`mb_convert_case()` mode lowercasing the whole string.",
        "",
    ),
    (
        "MB_CASE_TITLE",
        "Predefined constant",
        "MB_CASE_TITLE: int = 2",
        "`mb_convert_case()` mode title-casing each run of letters. PHP's `_SIMPLE` variants (3-5) are not distinguished and fall into the uppercase branch.",
        "",
    ),
    (
        "FILE_USE_INCLUDE_PATH",
        "Predefined constant",
        "FILE_USE_INCLUDE_PATH: int = 1",
        "Flag asking the file functions to search the include path. DIVERGENCE: not honoured — phplang has no include path.",
        "",
    ),
    (
        "FILE_APPEND",
        "Predefined constant",
        "FILE_APPEND: int = 8",
        "`file_put_contents()` flag appending instead of truncating. This is the one flag that function honours.",
        "",
    ),
    (
        "FILE_IGNORE_NEW_LINES",
        "Predefined constant",
        "FILE_IGNORE_NEW_LINES: int = 2",
        "`file()` flag stripping the trailing `\\n` (and a preceding `\\r`) from each line. Honoured.",
        "",
    ),
    (
        "FILE_SKIP_EMPTY_LINES",
        "Predefined constant",
        "FILE_SKIP_EMPTY_LINES: int = 4",
        "`file()` flag dropping empty lines. Honoured.",
        "",
    ),
    (
        "FILE_NO_DEFAULT_CONTEXT",
        "Predefined constant",
        "FILE_NO_DEFAULT_CONTEXT: int = 16",
        "Stream-context flag. Defined for compatibility; phplang has no stream contexts.",
        "",
    ),
    (
        "LOCK_SH",
        "Predefined constant",
        "LOCK_SH: int = 1",
        "Shared advisory lock. DIVERGENCE: there is no `flock()` in this build and `file_put_contents` ignores `LOCK_EX`, so no locking happens anywhere.",
        "",
    ),
    (
        "LOCK_EX",
        "Predefined constant",
        "LOCK_EX: int = 2",
        "Exclusive advisory lock. Accepted by `file_put_contents` and silently ignored.",
        "",
    ),
    (
        "LOCK_UN",
        "Predefined constant",
        "LOCK_UN: int = 3",
        "Lock release. Defined for compatibility only.",
        "",
    ),
    (
        "SCANDIR_SORT_ASCENDING",
        "Predefined constant",
        "SCANDIR_SORT_ASCENDING: int = 0",
        "`scandir()` sort order, ascending. The default; sorting is Rust byte order, not PHP's locale collation.",
        "",
    ),
    (
        "SCANDIR_SORT_DESCENDING",
        "Predefined constant",
        "SCANDIR_SORT_DESCENDING: int = 1",
        "`scandir()` sort order, descending. Honoured.",
        "",
    ),
    (
        "SCANDIR_SORT_NONE",
        "Predefined constant",
        "SCANDIR_SORT_NONE: int = 2",
        "`scandir()` mode leaving the entries unsorted. DIVERGENCE: not recognized — the result is always sorted.",
        "",
    ),
    (
        "PATHINFO_DIRNAME",
        "Predefined constant",
        "PATHINFO_DIRNAME: int = 1",
        "`pathinfo()` selector returning just the directory component as a string.",
        "",
    ),
    (
        "PATHINFO_BASENAME",
        "Predefined constant",
        "PATHINFO_BASENAME: int = 2",
        "`pathinfo()` selector returning just the final component.",
        "",
    ),
    (
        "PATHINFO_EXTENSION",
        "Predefined constant",
        "PATHINFO_EXTENSION: int = 4",
        "`pathinfo()` selector returning the text after the last dot.",
        "echo pathinfo(\"a/b.txt\", PATHINFO_EXTENSION);   // => txt",
    ),
    (
        "PATHINFO_FILENAME",
        "Predefined constant",
        "PATHINFO_FILENAME: int = 8",
        "`pathinfo()` selector returning the basename with its extension removed.",
        "",
    ),
    (
        "PATHINFO_ALL",
        "Predefined constant",
        "PATHINFO_ALL: int = 15",
        "`pathinfo()` selector returning the full associative array. This is what a call with no second argument produces.",
        "",
    ),
    (
        "ENT_NOQUOTES",
        "Predefined constant",
        "ENT_NOQUOTES: int = 0",
        "HTML-entity flag leaving both quote characters alone. Read by `get_html_translation_table()`; `htmlspecialchars()` itself ignores its flags argument.",
        "",
    ),
    (
        "ENT_COMPAT",
        "Predefined constant",
        "ENT_COMPAT: int = 2",
        "HTML-entity flag converting double quotes only.",
        "",
    ),
    (
        "ENT_QUOTES",
        "Predefined constant",
        "ENT_QUOTES: int = 3",
        "HTML-entity flag converting both quote characters. The default for `get_html_translation_table()`.",
        "",
    ),
    (
        "ENT_HTML401",
        "Predefined constant",
        "ENT_HTML401: int = 0",
        "Document-type bit selecting HTML 4.01. DIVERGENCE: the doctype bits are not read, so the single quote is always emitted as `&#039;`.",
        "",
    ),
    (
        "ENT_HTML5",
        "Predefined constant",
        "ENT_HTML5: int = 48",
        "Document-type bit selecting HTML 5. Not honoured.",
        "",
    ),
    (
        "ENT_XML1",
        "Predefined constant",
        "ENT_XML1: int = 16",
        "Document-type bit selecting XML 1. Not honoured.",
        "",
    ),
    (
        "ENT_XHTML",
        "Predefined constant",
        "ENT_XHTML: int = 32",
        "Document-type bit selecting XHTML. Not honoured.",
        "",
    ),
    (
        "ENT_SUBSTITUTE",
        "Predefined constant",
        "ENT_SUBSTITUTE: int = 8",
        "Flag replacing invalid code unit sequences with U+FFFD. Not honoured; phplang strings are always valid UTF-8.",
        "",
    ),
    (
        "ENT_IGNORE",
        "Predefined constant",
        "ENT_IGNORE: int = 4",
        "Flag discarding invalid code unit sequences. Not honoured, for the same reason as `ENT_SUBSTITUTE`.",
        "",
    ),
    (
        "M_PI",
        "Predefined constant",
        "M_PI: float = 3.141592653589793",
        "The ratio of a circle's circumference to its diameter. `pi()` returns the same value.",
        "echo round(M_PI, 4);   // => 3.1416",
    ),
    (
        "M_E",
        "Predefined constant",
        "M_E: float = 2.718281828459045",
        "Euler's number, the base of the natural logarithm.",
        "",
    ),
    (
        "M_SQRT2",
        "Predefined constant",
        "M_SQRT2: float = 1.4142135623730951",
        "The square root of 2.",
        "",
    ),
    (
        "M_SQRT1_2",
        "Predefined constant",
        "M_SQRT1_2: float = 0.7071067811865476",
        "The square root of 1/2.",
        "",
    ),
    (
        "M_SQRT3",
        "Predefined constant",
        "M_SQRT3: float = 1.7320508075688772",
        "The square root of 3.",
        "",
    ),
    (
        "M_2_SQRTPI",
        "Predefined constant",
        "M_2_SQRTPI: float = 1.1283791670955126",
        "Two divided by the square root of pi.",
        "",
    ),
    (
        "M_SQRTPI",
        "Predefined constant",
        "M_SQRTPI: float = 1.7724538509055159",
        "The square root of pi.",
        "",
    ),
    (
        "M_PI_2",
        "Predefined constant",
        "M_PI_2: float = 1.5707963267948966",
        "Pi divided by 2.",
        "",
    ),
    (
        "M_PI_4",
        "Predefined constant",
        "M_PI_4: float = 0.7853981633974483",
        "Pi divided by 4.",
        "",
    ),
    (
        "M_1_PI",
        "Predefined constant",
        "M_1_PI: float = 0.3183098861837907",
        "One divided by pi.",
        "",
    ),
    (
        "M_2_PI",
        "Predefined constant",
        "M_2_PI: float = 0.6366197723675814",
        "Two divided by pi.",
        "",
    ),
    (
        "M_LN2",
        "Predefined constant",
        "M_LN2: float = 0.6931471805599453",
        "The natural logarithm of 2.",
        "",
    ),
    (
        "M_LN10",
        "Predefined constant",
        "M_LN10: float = 2.302585092994046",
        "The natural logarithm of 10.",
        "",
    ),
    (
        "M_LOG2E",
        "Predefined constant",
        "M_LOG2E: float = 1.4426950408889634",
        "The base-2 logarithm of e.",
        "",
    ),
    (
        "M_LOG10E",
        "Predefined constant",
        "M_LOG10E: float = 0.4342944819032518",
        "The base-10 logarithm of e.",
        "",
    ),
    (
        "M_EULER",
        "Predefined constant",
        "M_EULER: float = 0.5772156649015329",
        "The Euler-Mascheroni constant.",
        "",
    ),
    // ══ Prelude class ═══════════════════════════════════════════════════════
    // Compiled from PHP source in `src/lib.rs` and merged onto every fresh host
    // before the user program, so a user declaration of the same name wins.
    (
        "Exception",
        "Prelude class",
        "class Exception {\n    protected $message = \"\"; protected $code = 0; protected $previous = null;\n    protected $file = \"\"; protected $line = 0; protected $trace = \"\";\n    __construct($message = \"\", $code = 0, $previous = null)\n    getMessage(): string   getCode(): int   getPrevious(): ?Throwable\n    getFile(): string   getLine(): int   getTraceAsString(): string\n    __toString(): string\n}",
        "One of the two disjoint roots of the exception hierarchy. `catch (Throwable)` is special-cased in the host to match this root or `Error`. `file`, `line` and `trace` are recorded when the object is *constructed*, as the reference engine records them, so `getLine()` reports the `new` site even when the `throw` is on a later line. DIVERGENCE: `getTrace()` — the structured array form — is not declared; only the rendered `getTraceAsString()` is.",
        "try { throw new Exception(\"boom\", 7); }\ncatch (Exception $e) { echo $e->getMessage(), $e->getCode(); }   // => boom7",
    ),
    (
        "Error",
        "Prelude class",
        "class Error {\n    protected $message = \"\"; protected $code = 0; protected $previous = null;\n    protected $file = \"\"; protected $line = 0; protected $trace = \"\";\n    __construct($message = \"\", $code = 0, $previous = null)\n    getMessage(): string   getCode(): int   getPrevious(): ?Throwable\n    getFile(): string   getLine(): int   getTraceAsString(): string\n    __toString(): string\n}",
        "The other root of the hierarchy, for engine-level failures. It does NOT extend `Exception` — the two roots are disjoint, exactly as in PHP, so `catch (Exception)` never catches an `Error`. A zero divisor throws `DivisionByZeroError`, and a method call on a non-object throws `Error`. Reaching the top uncaught prints the reference's `Fatal error: Uncaught <Class>: <message> in <file>:<line>` block, stack trace and all, on stdout. DIVERGENCE: most other runtime failures — a bad standard-library argument, a call to an undefined function — still abort with a host-level `php: <message>` on stderr that no `catch` block can intercept.",
        "try { throw new TypeError(\"t\"); }\ncatch (Exception $e) { echo \"E\"; } catch (Error $e) { echo \"R\"; }   // => R",
    ),
    (
        "RuntimeException",
        "Prelude class",
        "class RuntimeException extends Exception {}",
        "Thrown for an error only detectable at run time. Adds no members of its own.",
        "",
    ),
    (
        "LogicException",
        "Prelude class",
        "class LogicException extends Exception {}",
        "Thrown for an error in the program's logic that should be caught at development time.",
        "",
    ),
    (
        "InvalidArgumentException",
        "Prelude class",
        "class InvalidArgumentException extends LogicException {}",
        "Thrown when an argument does not match the expected type or value.",
        "",
    ),
    (
        "ArithmeticError",
        "Prelude class",
        "class ArithmeticError extends Error {}",
        "Thrown for an arithmetic failure, such as a shift by a negative count.",
        "",
    ),
    (
        "DivisionByZeroError",
        "Prelude class",
        "class DivisionByZeroError extends ArithmeticError {}",
        "The class raised for a zero divisor. `/` and `intdiv()` throw it with the message `Division by zero`, `%` with `Modulo by zero`, and a program may throw and catch it itself.",
        "try { throw new DivisionByZeroError(\"x\"); }\ncatch (ArithmeticError $e) { echo get_class($e); }   // => DivisionByZeroError",
    ),
    (
        "TypeError",
        "Prelude class",
        "class TypeError extends Error {}",
        "Thrown when a value has the wrong type for the operation. phplang enforces no declared parameter types, so it is raised far less often than in PHP.",
        "",
    ),
    (
        "ValueError",
        "Prelude class",
        "class ValueError extends Error {}",
        "Thrown when a value is of the right type but outside the accepted domain — the class the standard library's range and argument errors report.",
        "",
    ),
    (
        "UnhandledMatchError",
        "Prelude class",
        "class UnhandledMatchError extends Error {}",
        "Thrown by a `match` expression whose subject matched no arm and which had no `default`. The message reads `Unhandled match case <subject>`.",
        "try { echo match (5) { 1 => \"a\" }; }\ncatch (UnhandledMatchError $e) { echo $e->getMessage(); }   // => Unhandled match case 5",
    ),
    (
        "DateInterval",
        "Prelude class",
        "class DateInterval {\n    public $y, $m, $d, $h, $i, $s, $f, $invert, $days;\n    __construct($spec = \"\")\n    _seconds(): int   format($fmt): string\n}",
        "A duration parsed from an ISO 8601 spec such as `P1Y2M3DT4H5M6S`, with `W` weeks folded into days. `_seconds()` is the phplang-specific helper `DateTime::add`/`sub` use, converting with the fixed approximations of 30 days per month and 365 days per year. `format()` handles `%y %m %d %h %i %s %a %R %%`. DIVERGENCE: `$days` is only set by `DateTime::diff`, and PHP's `createFromDateString` static is absent.",
        "$i = new DateInterval(\"P1DT2H\"); echo $i->d, $i->h;   // => 12",
    ),
    (
        "DateTime",
        "Prelude class",
        "class DateTime {\n    public $ts;\n    __construct($datetime = \"now\")\n    format($format)   getTimestamp()   setTimestamp($ts)\n    modify($modifier)  setDate($y,$m,$d)  setTime($h,$i,$s = 0)\n    add($interval)     sub($interval)     diff($other)\n}",
        "A mutable date/time built on the `date`/`strtotime`/`mktime` functions, so everything it computes is UTC. The mutators return `$this` for chaining. DIVERGENCE: it stores a plain integer timestamp in the public `$ts`, has no timezone parameter or `DateTimeZone` support, no sub-second precision, and none of PHP's `createFromFormat`/`setISODate`/`getTimezone` API.",
        "$d = new DateTime(\"@0\"); echo $d->format(\"Y-m-d\");   // => 1970-01-01",
    ),
    (
        "DateTimeImmutable",
        "Prelude class",
        "class DateTimeImmutable {\n    public $ts;\n    __construct($datetime = \"now\")\n    format($format)   getTimestamp()\n    modify($modifier)  add($interval)  sub($interval)\n}",
        "The immutable counterpart of `DateTime`: `modify`, `add`, and `sub` each return a NEW instance and leave the receiver untouched. DIVERGENCE: it declares a smaller API than `DateTime` — there is no `setTimestamp`, `setDate`, `setTime`, or `diff` — and it does not share an interface with `DateTime`.",
        "$a = new DateTimeImmutable(\"@0\"); $b = $a->add(new DateInterval(\"P1D\"));\necho $a->getTimestamp(), \" \", $b->getTimestamp();   // => 0 86400",
    ),
    (
        "stdClass",
        "Prelude class",
        "class stdClass {}",
        "The empty generic object. Properties are added dynamically at assignment. Produced by `new stdClass` and by the `(object)` cast. DIVERGENCE: `json_decode` always yields arrays, so it never produces one.",
        "$o = new stdClass; $o->x = 1; echo $o->x, get_class($o);   // => 1stdClass",
    ),
    (
        "SplDoublyLinkedList",
        "Prelude class",
        "class SplDoublyLinkedList {\n    public $dll = [];\n    push($v)  pop()  shift()  unshift($v)  top()  bottom()\n    count()   isEmpty()  toArray()\n    offsetGet($i)  offsetSet($i,$v)  offsetExists($i)  offsetUnset($i)\n    getIterator()\n}",
        "A list backed by the public `$dll` array. Because phplang arrays are reference-based handles, the methods alias the property to a local and mutate it in place. DIVERGENCE: it implements no interface, so `$list[0]` array syntax and `foreach ($list as …)` do not work — use `offsetGet()` and iterate `getIterator()`.",
        "$l = new SplDoublyLinkedList; $l->push(1); $l->push(2);\necho $l->count(), $l->top();   // => 22",
    ),
    (
        "SplStack",
        "Prelude class",
        "class SplStack extends SplDoublyLinkedList {}",
        "A LIFO view over `SplDoublyLinkedList`, using `push()`/`pop()`/`top()`. It adds no members and does not reverse the iteration order.",
        "$s = new SplStack; $s->push(1); $s->push(2); echo $s->pop();   // => 2",
    ),
    (
        "SplQueue",
        "Prelude class",
        "class SplQueue extends SplDoublyLinkedList {\n    enqueue($v)   dequeue()\n}",
        "A FIFO view over `SplDoublyLinkedList`: `enqueue()` appends and `dequeue()` removes from the front.",
        "$q = new SplQueue; $q->enqueue(1); $q->enqueue(2); echo $q->dequeue();   // => 1",
    ),
    (
        "SplFixedArray",
        "Prelude class",
        "class SplFixedArray {\n    public $data = []; public $sz = 0;\n    __construct($size = 0)\n    offsetGet($i)  offsetSet($i,$v)  offsetExists($i)\n    getSize()  setSize($size)  count()  toArray()  getIterator()\n}",
        "A fixed-length array pre-filled with nulls. DIVERGENCE: `offsetSet` performs no bounds check, so writing past `getSize()` grows the backing array instead of throwing `RuntimeException`, and `setSize()` only updates the recorded size without truncating or extending the storage.",
        "$a = new SplFixedArray(3); $a->offsetSet(0, \"x\");\necho $a->getSize(), $a->offsetGet(0);   // => 3x",
    ),
    (
        "ArrayObject",
        "Prelude class",
        "class ArrayObject {\n    public $storage = [];\n    __construct($array = [])\n    offsetGet($k)  offsetSet($k,$v)  offsetExists($k)  offsetUnset($k)\n    append($v)  count()  getArrayCopy()  getIterator()\n}",
        "An object wrapper around an array. DIVERGENCE: `getArrayCopy()` returns the backing handle rather than a copy, so mutating the result also mutates the object; and because no interface is implemented, `$obj[$k]` and `foreach` over the object do not work.",
        "$o = new ArrayObject([\"a\" => 1]); $o->append(2);\necho $o->count(), $o->offsetGet(\"a\");   // => 21",
    ),
    (
        "ArrayIterator",
        "Prelude class",
        "class ArrayIterator extends ArrayObject {}",
        "An alias of `ArrayObject` with no added members. DIVERGENCE: it implements no `Iterator` interface and has none of PHP's `current`/`key`/`next`/`valid`/`rewind` cursor methods.",
        "",
    ),
    (
        "SplObjectStorage",
        "Prelude class",
        "class SplObjectStorage {\n    public $store = [];\n    attach($obj, $data = null)   detach($obj)\n    contains($obj)   count()\n}",
        "A set of objects with optional attached data, keyed by `spl_object_id()`. DIVERGENCE: it has no `offsetGet`/`offsetSet` accessors, so the attached data cannot be read back, and it is neither countable nor iterable through the language's own syntax.",
        "$s = new SplObjectStorage; $o = new stdClass; $s->attach($o);\nvar_dump($s->contains($o), $s->count());   // => bool(true) int(1)",
    ),
    (
        "SplPriorityQueue",
        "Prelude class",
        "class SplPriorityQueue {\n    public $items = [];\n    insert($value, $priority)   extract()   top()\n    count()   isEmpty()   _best()\n}",
        "A priority queue storing `[priority, value]` pairs. DIVERGENCE: it is not a heap — `_best()` performs a LINEAR scan for the highest priority on every `top()`/`extract()`, making those operations O(n). Priorities are compared with `>`, so ties resolve to the earliest inserted element.",
        "$q = new SplPriorityQueue; $q->insert(\"lo\", 1); $q->insert(\"hi\", 9);\necho $q->extract();   // => hi",
    ),
    (
        "SplHeap",
        "Prelude class",
        "class SplHeap {\n    public $items = [];\n    insert($v)   extract()   top()\n    count()   isEmpty()   compare($a, $b)   _best()\n}",
        "The base heap class. DIVERGENCE: it is concrete rather than abstract and stores an unordered list, so `_best()` linear-scans with `compare()` on every `top()`/`extract()`. Override `compare()` to change the ordering; the base implementation is `$a <=> $b`, i.e. max-first.",
        "$h = new SplHeap; $h->insert(3); $h->insert(9); echo $h->extract();   // => 9",
    ),
    (
        "SplMaxHeap",
        "Prelude class",
        "class SplMaxHeap extends SplHeap {\n    compare($a, $b): int   //  $a <=> $b\n}",
        "A heap whose `extract()` yields the largest element first.",
        "$h = new SplMaxHeap; $h->insert(1); $h->insert(5); echo $h->extract();   // => 5",
    ),
    (
        "SplMinHeap",
        "Prelude class",
        "class SplMinHeap extends SplHeap {\n    compare($a, $b): int   //  $b <=> $a\n}",
        "A heap whose `extract()` yields the smallest element first, achieved by reversing the base comparison.",
        "$h = new SplMinHeap; $h->insert(5); $h->insert(1); echo $h->extract();   // => 1",
    ),
    // ══ Core library — strings ══════════════════════════════════════════════
    // Handled by the core `call_library` match in `src/builtins.rs`, which wins
    // over the `stdlib` chain for every name it claims.
    (
        "strlen",
        "Core library — strings",
        "strlen(string $string): int",
        "Length of the string in BYTES, not characters — `strlen(\"héllo\")` is 6. Use `mb_strlen()` for the codepoint count.",
        "echo strlen(\"abc\"), \" \", strlen(\"héllo\");   // => 3 6",
    ),
    (
        "strtoupper",
        "Core library — strings",
        "strtoupper(string $string): string",
        "Uppercases the ASCII letters in the string, leaving every other byte alone — so `strtoupper(\"héllo\")` is `\"HéLLO\"`, as in PHP 8. Use `mb_strtoupper` for the Unicode-aware form.",
        "echo strtoupper(\"abc\");   // => ABC",
    ),
    (
        "strtolower",
        "Core library — strings",
        "strtolower(string $string): string",
        "Lowercases the string with Rust's full Unicode `to_lowercase`, with the same non-ASCII divergence from PHP as `strtoupper`.",
        "echo strtolower(\"ABC\");   // => abc",
    ),
    (
        "ucfirst",
        "Core library — strings",
        "ucfirst(string $string): string",
        "Uppercases the first character and leaves the rest untouched. The conversion is full Unicode, so the first character may expand to several codepoints.",
        "echo ucfirst(\"hello\");   // => Hello",
    ),
    (
        "lcfirst",
        "Core library — strings",
        "lcfirst(string $string): string",
        "Lowercases the first character and leaves the rest untouched.",
        "echo lcfirst(\"Hello\");   // => hello",
    ),
    (
        "ucwords",
        "Core library — strings",
        "ucwords(string $string): string",
        "Uppercases the first letter of each word. Words are separated by whitespace only — the `$separators` argument PHP accepts is not read, so `-` and `.` do not start a new word.",
        "echo ucwords(\"hello world-foo\");   // => Hello World-foo",
    ),
    (
        "trim",
        "Core library — strings",
        "trim(string $string): string",
        "Removes leading and trailing characters, defaulting to PHP's set `\" \\t\\n\\r\\0\\x0B\"`. The optional `$characters` argument replaces that set and understands `a..z` inclusive ranges; a malformed range warns `trim(): Invalid '..'-range, …` and contributes nothing. Byte-oriented.",
        "echo trim(\"  hi  \");   // => hi",
    ),
    (
        "ltrim",
        "Core library — strings",
        "ltrim(string $string): string",
        "Removes leading whitespace only. The `$characters` argument is not read.",
        "echo ltrim(\"  hi\");   // => hi",
    ),
    (
        "rtrim",
        "Core library — strings",
        "rtrim(string $string): string",
        "Removes trailing whitespace only. The `$characters` argument is not read.",
        "echo rtrim(\"hi  \") . \"!\";   // => hi!",
    ),
    (
        "chop",
        "Core library — strings",
        "chop(string $string): string",
        "The historical alias of `rtrim`, sharing its match arm and therefore its behaviour exactly.",
        "",
    ),
    (
        "str_repeat",
        "Core library — strings",
        "str_repeat(string $string, int $times): string",
        "Concatenates the string with itself `$times` times. A count of zero yields the empty string; a negative count throws `ValueError: str_repeat(): Argument #2 ($times) must be greater than or equal to 0`. When `strlen * $times + 32` overflows the address space the engine stops with the UNCATCHABLE fatal `Possible integer overflow in memory allocation (len * times + 32)`, as the reference does.",
        "echo str_repeat(\"ab\", 3);   // => ababab",
    ),
    (
        "strrev",
        "Core library — strings",
        "strrev(string $string): string",
        "Reverses the string by CHARACTER, not by byte. DIVERGENCE: PHP reverses bytes, which corrupts multibyte text; this version leaves each character intact.",
        "echo strrev(\"abc\");   // => cba",
    ),
    (
        "wordwrap",
        "Core library — strings",
        "wordwrap(string $string, int $width = 75, string $break = \"\\n\", bool $cut = false): string",
        "Wraps the text to `$width` columns, breaking at spaces. With `$cut` true a word longer than the width is split rather than left overlong; a zero `$width` with `$cut` true has no answer and raises `ValueError: wordwrap(): Argument #4 ($cut_long_words) cannot be true when argument #2 ($width) is 0`.",
        "echo wordwrap(\"a b c\", 3, \"|\", true);   // => a b|c",
    ),
    (
        "substr",
        "Core library — strings",
        "substr(string $string, int $offset, ?int $length = null): string",
        "A substring counted in CHARACTERS. A negative offset counts from the end and a negative length omits that many trailing characters. DIVERGENCE: PHP's `substr` uses byte offsets, so results differ on multibyte input. It never returns `false`.",
        "echo substr(\"hello\", 1, 3);   // => ell",
    ),
    (
        "strpos",
        "Core library — strings",
        "strpos(string $haystack, string $needle): int|false",
        "BYTE offset of the first occurrence at or after `$offset`, or `false` when absent. A negative `$offset` counts from the end; one outside `[-strlen, strlen]` raises `ValueError: strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)` rather than reporting no match. An empty needle returns the offset itself.",
        "var_dump(strpos(\"hello\", \"l\"), strpos(\"hello\", \"z\"));   // => int(2) bool(false)",
    ),
    (
        "str_replace",
        "Core library — strings",
        "str_replace(string $search, string $replace, string $subject): string",
        "Replaces every occurrence of the search string. `$search`/`$replace` may be arrays (paired by position, or one replacement for every needle), an array `$subject` is processed element-wise, and the by-reference `$count` receives the number of replacements.",
        "echo str_replace(\"a\", \"b\", \"aaa\");   // => bbb",
    ),
    (
        "str_split",
        "Core library — strings",
        "str_split(string $string, int $length = 1): array",
        "Splits the string into chunks of `$length` characters; the last chunk may be shorter.",
        "echo str_split(\"ab\")[0];   // => a",
    ),
    (
        "str_pad",
        "Core library — strings",
        "str_pad(string $string, int $length, string $pad = \" \", int $type = STR_PAD_RIGHT): string",
        "Pads the string to `$length` by cycling `$pad`. `STR_PAD_RIGHT`, `STR_PAD_LEFT`, and `STR_PAD_BOTH` are all honoured; a string already at least that long is returned unchanged.",
        "echo str_pad(\"5\", 3, \"0\"), \" \", str_pad(\"5\", 3, \"0\", STR_PAD_LEFT);   // => 500 005",
    ),
    (
        "str_contains",
        "Core library — strings",
        "str_contains(string $haystack, string $needle): bool",
        "True when the haystack contains the needle. An empty needle is always found.",
        "var_dump(str_contains(\"hello\", \"ell\"));   // => bool(true)",
    ),
    (
        "str_starts_with",
        "Core library — strings",
        "str_starts_with(string $haystack, string $needle): bool",
        "True when the haystack begins with the needle.",
        "var_dump(str_starts_with(\"hello\", \"he\"));   // => bool(true)",
    ),
    (
        "str_ends_with",
        "Core library — strings",
        "str_ends_with(string $haystack, string $needle): bool",
        "True when the haystack ends with the needle.",
        "var_dump(str_ends_with(\"hello\", \"lo\"));   // => bool(true)",
    ),
    (
        "number_format",
        "Core library — strings",
        "number_format(float $num, int $decimals = 0, string $decimal_separator = \".\", string $thousands_separator = \",\"): string",
        "Formats a number with grouped thousands and a fixed number of decimals, rounding half away from zero.",
        "echo number_format(1234.567, 2);   // => 1,234.57",
    ),
    (
        "htmlspecialchars",
        "Core library — strings",
        "htmlspecialchars(string $string): string",
        "Escapes `&`, `<`, `>`, and — as `$flags` selects — `\"` (`ENT_COMPAT`) and `'` (`ENT_QUOTES`, the default since PHP 8.1, written as the numeric `&#039;` under `ENT_HTML401`). DIVERGENCE: `$encoding` and `$double_encode` are not read, so `&` is always re-encoded.",
        "echo htmlspecialchars(\"a<b\");   // => a&lt;b",
    ),
    (
        "htmlentities",
        "Core library — strings",
        "htmlentities(string $string): string",
        "`htmlspecialchars` plus the full HTML 4.01 named-entity table, so `é` becomes `&eacute;`, `€` `&euro;`, and `α` `&alpha;`. `$flags` selects quote handling as it does there. DIVERGENCE: `$encoding` and `$double_encode` are not read.",
        "echo htmlentities(\"café\");   // => caf&eacute;",
    ),
    (
        "strcmp",
        "Core library — strings",
        "strcmp(string $string1, string $string2): int",
        "Byte comparison returning only the sign: `-1`, `0`, or `1`. PHP 8 also normalizes to the sign, so this matches.",
        "echo strcmp(\"a\", \"b\");   // => -1",
    ),
    (
        "strcasecmp",
        "Core library — strings",
        "strcasecmp(string $string1, string $string2): int",
        "Compares after lowercasing both operands with full Unicode folding, returning `-1`, `0`, or `1`.",
        "echo strcasecmp(\"A\", \"a\");   // => 0",
    ),
    (
        "strncmp",
        "Core library — strings",
        "strncmp(string $string1, string $string2, int $length): int",
        "Compares at most the first `$length` BYTES of each string, returning the sign. A length beyond either string simply compares what is there.",
        "echo strncmp(\"abcd\", \"abzz\", 2);   // => 0",
    ),
    (
        "substr_compare",
        "Core library — strings",
        "substr_compare(string $haystack, string $needle, int $offset, ?int $length = null, bool $case_insensitive = false): int",
        "Compares `$needle` against the slice of `$haystack` starting at `$offset` (negatives count from the end), over `$length` bytes or, when that is null, `max(strlen($needle), strlen($haystack) - $offset)`. The result is NOT normalized: differing bytes answer their signed difference, and only a tie on content falls back to -1/0/1 on length. An `$offset` past the haystack, or a negative `$length`, throws `ValueError`; a `$length` of 0 answers 0.",
        "echo substr_compare(\"Hello\", \"llo\", 2);   // => 0",
    ),
    (
        "chr",
        "Core library — strings",
        "chr(int $codepoint): string",
        "The one-character string for a byte value, reduced modulo 256 so any integer is accepted — a value outside `0..=255` raises `Deprecated: chr(): Providing a value not in-between 0 and 255 is deprecated…` first. DIVERGENCE: the result is that CODEPOINT, so `chr(233)` yields a two-byte UTF-8 `é` rather than PHP's single 0xE9 byte.",
        "echo chr(65);   // => A",
    ),
    (
        "ord",
        "Core library — strings",
        "ord(string $character): int",
        "The value of the first BYTE of the string, so a multibyte character reports its leading byte (`ord(\"é\")` is 195). The empty string returns 0 and raises `Deprecated: ord(): Providing an empty string is deprecated`.",
        "echo ord(\"A\");   // => 65",
    ),
    (
        "dechex",
        "Core library — strings",
        "dechex(int $num): string",
        "Lowercase hexadecimal rendering of an integer. DIVERGENCE: a negative number renders as `-` plus the magnitude, where PHP renders the unsigned 64-bit two's-complement form.",
        "echo dechex(255);   // => ff",
    ),
    (
        "hexdec",
        "Core library — strings",
        "hexdec(string $hex_string): int",
        "The integer value of a hexadecimal string, after trimming surrounding whitespace. A leading `0x`/`0X` is dropped. Characters that are not hex digits are skipped, and skipping ANY raises `Deprecated: Invalid characters passed for attempted conversion, these have been ignored` before returning. The result is an integer when it fits `PHP_INT_MAX` and a float otherwise.",
        "echo hexdec(\"ff\");   // => 255",
    ),
    (
        "bin2hex",
        "Core library — strings",
        "bin2hex(string $string): string",
        "Two lowercase hex digits per byte of the string's UTF-8 encoding.",
        "echo bin2hex(\"AB\");   // => 4142",
    ),
    (
        "sprintf",
        "Core library — strings",
        "sprintf(string $format, mixed ...$values): string",
        "Formats the arguments into a string. Supports the `%b %c %d %u %e %E %f %F %g %G %o %s %x %X %%` conversions with width, precision, `-` left-align, `0` and `'` custom padding, `+` sign, and `%n$` argument reordering.",
        "echo sprintf(\"%05.2f|%s|%x|%b\", 3.14159, \"s\", 255, 5);   // => 03.14|s|ff|101",
    ),
    // ══ Core library — arrays ═══════════════════════════════════════════════
    (
        "count",
        "Core library — arrays",
        "count(Countable|array $value, int $mode = COUNT_NORMAL): int",
        "Number of elements in an array, or what a `Countable`'s own `count()` returns. Anything else is a `TypeError` — PHP 8 stopped answering 1 for a scalar. `$mode` is `COUNT_NORMAL` or `COUNT_RECURSIVE`, and any other value is a `ValueError`.",
        "echo count([1, 2, 3]);   // => 3",
    ),
    (
        "sizeof",
        "Core library — arrays",
        "sizeof(Countable|array $value, int $mode = COUNT_NORMAL): int",
        "The alias of `count`, sharing its match arm and therefore its modes and its errors exactly.",
        "",
    ),
    (
        "array_keys",
        "Core library — arrays",
        "array_keys(array $array): array",
        "A new list of the array's keys in insertion order. DIVERGENCE: the `$filter_value` and `$strict` arguments are not read, so the filtered form is unavailable.",
        "echo implode(\",\", array_keys([\"a\" => 1, \"b\" => 2]));   // => a,b",
    ),
    (
        "array_values",
        "Core library — arrays",
        "array_values(array $array): array",
        "A new list of the array's values, reindexed from 0.",
        "echo implode(\",\", array_values([5 => \"a\", 9 => \"b\"]));   // => a,b",
    ),
    (
        "array_push",
        "Core library — arrays",
        "array_push(array $array, mixed ...$values): int",
        "Appends each value with the next integer key and returns the new element count. The array is a shared handle, so the caller's variable sees the change.",
        "$a = [1]; array_push($a, 2); echo implode(\",\", $a);   // => 1,2",
    ),
    (
        "in_array",
        "Core library — arrays",
        "in_array(mixed $needle, array $haystack, bool $strict = false): bool",
        "True when the value occurs in the array, comparing loosely by default and with `===` when `$strict` is truthy.",
        "var_dump(in_array(\"2\", [1, 2, 3], true));   // => bool(false)",
    ),
    (
        "range",
        "Core library — arrays",
        "range(mixed $start, mixed $end, int|float $step = 1): array",
        "An inclusive sequence, ported from `PHP_FUNCTION(range)`. `$step` is validated FIRST and independently of the bounds, with a distinct message for each fault: `cannot be 0`, `must be greater than -9223372036854775808`, `must be a finite number, NAN|INF provided`, `must be greater than 0 for increasing ranges`, and `must be less than the range spanned by argument #1 ($start) and argument #2 ($end)`. Each bound is then classified: a one-byte NUMERIC string is ambiguous and is read as a character only when the other bound is also a string, so `range(\"1\", \"3\")` yields strings while `range(\"1.5\", \"3\")` yields floats. A character range walks BYTES using only the first byte of each bound (a longer bound warns `must be a single byte, subsequent bytes are ignored`), an empty string warns `must not be empty, casted to 0`, and a whole-valued float step keeps an int range int. A span too large for a hash table raises `The supplied range exceeds the maximum array size by N elements: …`.",
        "echo implode(\",\", range(1, 4)), \" \", implode(\"\", range(\"a\", \"c\"));   // => 1,2,3,4 abc",
    ),
    (
        "array_merge",
        "Core library — arrays",
        "array_merge(array ...$arrays): array",
        "Concatenates the arrays. Integer keys are renumbered from 0 and string keys are overwritten by later arrays.",
        "echo implode(\",\", array_merge([1], [2, 3]));   // => 1,2,3",
    ),
    (
        "array_map",
        "Core library — arrays",
        "array_map(?callable $callback, array $array, array ...$arrays): array",
        "Applies the callback to each element and returns the results. With several arrays it walks them in parallel, and a null callback zips them into tuples.",
        "echo implode(\",\", array_map(\"strtoupper\", [\"a\", \"b\"]));   // => A,B",
    ),
    (
        "array_filter",
        "Core library — arrays",
        "array_filter(array $array, ?callable $callback = null, int $mode = 0): array",
        "Keeps the elements for which the callback is truthy, PRESERVING keys. With no callback it keeps the truthy values. `$mode` selects what the callback receives: the value (0), the value and the key (`ARRAY_FILTER_USE_BOTH`), or the key alone (`ARRAY_FILTER_USE_KEY`).",
        "echo implode(\",\", array_filter([0, 1, 2]));   // => 1,2",
    ),
    (
        "array_reduce",
        "Core library — arrays",
        "array_reduce(array $array, callable $callback, mixed $initial = null): mixed",
        "Folds the array to a single value, calling `$callback($carry, $item)` for each element.",
        "echo array_reduce([1, 2, 3], fn($c, $x) => $c + $x, 0);   // => 6",
    ),
    (
        "array_slice",
        "Core library — arrays",
        "array_slice(array $array, int $offset, ?int $length = null, bool $preserve_keys = false): array",
        "Extracts a run of elements. A negative offset counts from the end and a negative length stops that many elements from the end.",
        "echo implode(\",\", array_slice([1, 2, 3, 4], 1, 2));   // => 2,3",
    ),
    (
        "array_reverse",
        "Core library — arrays",
        "array_reverse(array $array, bool $preserve_keys = false): array",
        "A new array with the elements in reverse order. String keys are always preserved; integer keys are renumbered unless `$preserve_keys` is truthy.",
        "echo implode(\",\", array_reverse([1, 2, 3]));   // => 3,2,1",
    ),
    (
        "array_sum",
        "Core library — arrays",
        "array_sum(array $array): int|float",
        "Sum of the values as numbers. The result is an integer while every addend is one, and a float as soon as any is. An entry the `+` operator would reject warns `array_sum(): Addition is not supported on type <type>`; an array or an object with no numeric cast then contributes nothing, while a non-numeric string keeps the pre-8 behaviour of counting as 0.",
        "var_dump(array_sum([1, 2.5]));   // => float(3.5)",
    ),
    (
        "array_product",
        "Core library — arrays",
        "array_product(array $array): int|float",
        "Product of the values as numbers, following the same integer-until-a-float rule as `array_sum`, and the same `Multiplication is not supported on type <type>` warning for an entry `*` would reject — which is why `array_product([2, \"a\"])` is 0, the non-numeric string counting as a factor of 0. An empty array yields 1.",
        "echo array_product([2, 3, 4]);   // => 24",
    ),
    (
        "array_flip",
        "Core library — arrays",
        "array_flip(array $array): array",
        "Swaps keys and values. A later duplicate value overwrites the entry the earlier one produced.",
        "echo array_flip([\"a\", \"b\"])[\"a\"];   // => 0",
    ),
    (
        "array_unique",
        "Core library — arrays",
        "array_unique(array $array): array",
        "Keeps the first occurrence of each distinct value, preserving keys. DIVERGENCE: the `$flags` argument is not read, so the comparison mode is fixed.",
        "echo implode(\",\", array_unique([1, 1, 2]));   // => 1,2",
    ),
    (
        "array_key_exists",
        "Core library — arrays",
        "array_key_exists(mixed $key, array $array): bool",
        "True when the key is present, even if its value is null — the difference from `isset()`.",
        "var_dump(array_key_exists(\"a\", [\"a\" => null]), isset([\"a\" => null][\"a\"]));   // => bool(true) bool(false)",
    ),
    (
        "key_exists",
        "Core library — arrays",
        "key_exists(mixed $key, array $array): bool",
        "The alias of `array_key_exists`, sharing its match arm.",
        "",
    ),
    (
        "array_search",
        "Core library — arrays",
        "array_search(mixed $needle, array $haystack, bool $strict = false): mixed",
        "The key of the first matching value, or `false` when none matches. `$strict` selects `===` over loose comparison.",
        "echo array_search(2, [1, 2, 3]);   // => 1",
    ),
    (
        "sort",
        "Core library — arrays",
        "sort(array $array): bool",
        "Sorts ascending in place and reindexes the keys from 0. The `$flags` argument selects the comparison (`SORT_REGULAR`, `SORT_NUMERIC`, `SORT_STRING`, `SORT_NATURAL`, optionally `|SORT_FLAG_CASE`). The sort is stable, as PHP 8's is.",
        "$a = [3, 1, 2]; sort($a); echo implode(\",\", $a);   // => 1,2,3",
    ),
    (
        "rsort",
        "Core library — arrays",
        "rsort(array $array): bool",
        "Sorts descending in place and reindexes the keys from 0.",
        "$a = [1, 3, 2]; rsort($a); echo implode(\",\", $a);   // => 3,2,1",
    ),
    (
        "asort",
        "Core library — arrays",
        "asort(array $array): bool",
        "Sorts by value ascending while preserving the key association.",
        "$a = [\"b\" => 2, \"a\" => 1]; asort($a); echo implode(\",\", array_keys($a));   // => a,b",
    ),
    (
        "arsort",
        "Core library — arrays",
        "arsort(array $array): bool",
        "Sorts by value descending while preserving the key association.",
        "$a = [\"a\" => 1, \"b\" => 2]; arsort($a); echo implode(\",\", array_keys($a));   // => b,a",
    ),
    (
        "ksort",
        "Core library — arrays",
        "ksort(array $array): bool",
        "Sorts by key ascending, keeping each key with its value.",
        "$a = [\"b\" => 1, \"a\" => 2]; ksort($a); echo implode(\",\", array_keys($a));   // => a,b",
    ),
    (
        "krsort",
        "Core library — arrays",
        "krsort(array $array): bool",
        "Sorts by key descending.",
        "$a = [\"a\" => 1, \"b\" => 2]; krsort($a); echo implode(\",\", array_keys($a));   // => b,a",
    ),
    (
        "array_fill",
        "Core library — arrays",
        "array_fill(int $start_index, int $count, mixed $value): array",
        "An array of `$count` copies of the value, keyed from `$start_index` upward. A negative `$count` raises `ValueError: array_fill(): Argument #2 ($count) must be greater than or equal to 0` and one past `INT_MAX` raises `… is too large`; a `$start_index` high enough that the last key would pass `PHP_INT_MAX` raises `Error: Cannot add element to the array as the next element is already occupied`, before any element is written.",
        "echo implode(\",\", array_fill(0, 3, \"x\"));   // => x,x,x",
    ),
    (
        "array_combine",
        "Core library — arrays",
        "array_combine(array $keys, array $values): array",
        "Pairs one array's values as keys with another's as values. Mismatched lengths throw `ValueError: array_combine(): Argument #1 ($keys) and argument #2 ($values) must have the same number of elements`.",
        "echo array_combine([\"a\"], [1])[\"a\"];   // => 1",
    ),
    (
        "array_diff",
        "Core library — arrays",
        "array_diff(array $array, array ...$excludes): array",
        "The entries of the first array whose VALUE (compared by string form) appears in none of the others. Keys are preserved.",
        "echo implode(\",\", array_diff([1, 2, 3], [2]));   // => 1,3",
    ),
    (
        "array_intersect",
        "Core library — arrays",
        "array_intersect(array $array, array ...$others): array",
        "The entries of the first array whose value appears in every other array, compared by string form. Keys are preserved.",
        "echo implode(\",\", array_intersect([1, 2, 3], [2, 3, 4]));   // => 2,3",
    ),
    (
        "implode",
        "Core library — arrays",
        "implode(string $separator, array $array): string\nimplode(array $array): string",
        "Joins the array's values into a string. Passing only the array joins with no separator.",
        "echo implode(\",\", [1, 2, 3]);   // => 1,2,3",
    ),
    (
        "join",
        "Core library — arrays",
        "join(string $separator, array $array): string",
        "The alias of `implode`, sharing its match arm.",
        "",
    ),
    (
        "explode",
        "Core library — arrays",
        "explode(string $separator, string $string): array",
        "Splits the string on every occurrence of the separator. A positive `$limit` caps the number of parts with the last holding the remainder, a negative one drops that many parts off the end, and `0` behaves as `1`. An empty separator returns a single-element array rather than raising `ValueError`.",
        "echo explode(\",\", \"a,b\")[1];   // => b",
    ),
    // ══ Core library — math ═════════════════════════════════════════════════
    (
        "abs",
        "Core library — math",
        "abs(int|float $num): int|float",
        "Absolute value, preserving the operand's numeric type.",
        "echo abs(-5);   // => 5",
    ),
    (
        "floor",
        "Core library — math",
        "floor(int|float $num): float",
        "The largest integral value not greater than the operand, returned as a float.",
        "echo floor(3.7);   // => 3",
    ),
    (
        "ceil",
        "Core library — math",
        "ceil(int|float $num): float",
        "The smallest integral value not less than the operand, returned as a float.",
        "echo ceil(3.2);   // => 4",
    ),
    (
        "round",
        "Core library — math",
        "round(int|float $num, int $precision = 0): float",
        "Rounds to `$precision` decimal places, halves away from zero unless the PHP 8.4 `$mode` selects another rule; all four `PHP_ROUND_HALF_*` constants are honoured.",
        "echo round(3.14159, 2);   // => 3.14",
    ),
    (
        "sqrt",
        "Core library — math",
        "sqrt(int|float $num): float",
        "The non-negative square root. A negative operand yields NAN.",
        "echo sqrt(16);   // => 4",
    ),
    (
        "pow",
        "Core library — math",
        "pow(int|float $base, int|float $exp): int|float",
        "The base raised to the exponent. Two integers with a non-negative exponent give an integer result; anything else gives a float.",
        "echo pow(2, 10);   // => 1024",
    ),
    (
        "intdiv",
        "Core library — math",
        "intdiv(int $num1, int $num2): int",
        "Integer division truncated toward zero. A zero divisor throws a catchable `DivisionByZeroError` with the message `Division by zero`.",
        "echo intdiv(7, 2);   // => 3",
    ),
    (
        "fmod",
        "Core library — math",
        "fmod(float $num1, float $num2): float",
        "The floating-point remainder of the division, keeping the sign of the dividend.",
        "echo fmod(7.5, 2);   // => 1.5",
    ),
    (
        "sin",
        "Core library — math",
        "sin(float $num): float",
        "Sine of an angle in radians.",
        "echo sin(0);   // => 0",
    ),
    (
        "cos",
        "Core library — math",
        "cos(float $num): float",
        "Cosine of an angle in radians.",
        "echo cos(0);   // => 1",
    ),
    (
        "tan",
        "Core library — math",
        "tan(float $num): float",
        "Tangent of an angle in radians.",
        "echo tan(0);   // => 0",
    ),
    (
        "exp",
        "Core library — math",
        "exp(float $num): float",
        "e raised to the given power.",
        "echo exp(0);   // => 1",
    ),
    (
        "log",
        "Core library — math",
        "log(float $num, ?float $base = M_E): float",
        "The natural logarithm, or the logarithm in `$base` when a second argument is supplied.",
        "echo log(8, 2);   // => 3",
    ),
    (
        "log10",
        "Core library — math",
        "log10(float $num): float",
        "The base-10 logarithm.",
        "echo log10(1000);   // => 3",
    ),
    (
        "pi",
        "Core library — math",
        "pi(): float",
        "Returns pi, the same value as the `M_PI` constant.",
        "echo round(pi(), 2);   // => 3.14",
    ),
    (
        "max",
        "Core library — math",
        "max(mixed ...$values): mixed\nmax(array $values): mixed",
        "The largest argument, or the largest element when a single array is passed. Comparison follows PHP's loose ordering rules.",
        "echo max(3, 1, 2);   // => 3",
    ),
    (
        "min",
        "Core library — math",
        "min(mixed ...$values): mixed\nmin(array $values): mixed",
        "The smallest argument, or the smallest element of a single array argument.",
        "echo min(3, 1, 2);   // => 1",
    ),
    // ══ Core library — types and output ═════════════════════════════════════
    (
        "settype",
        "Core library — types and output",
        "settype(mixed &$var, string $type): bool",
        "Converts `$var` in place to `$type` and returns true. Accepts `bool`/`boolean`, `int`/`integer`, `float`/`double`, `string`, `array`, `object` and `null`; the conversion is the one the matching cast performs, so a non-numeric string becomes `0` and a scalar becomes a one-element array. Any other type name is a `ValueError`.",
        "$n = \"12abc\"; settype($n, \"integer\"); var_dump($n);   // => int(12)",
    ),
    (
        "gettype",
        "Core library — types and output",
        "gettype(mixed $value): string",
        "The legacy type name: `boolean`, `integer`, `double`, `string`, `array`, `object`, `NULL`, or `unknown type`. Use `get_debug_type()` for the modern short names.",
        "echo gettype(1.0), \"|\", gettype(null);   // => double|NULL",
    ),
    (
        "is_array",
        "Core library — types and output",
        "is_array(mixed $value): bool",
        "True when the value is an array. Arrays and objects share one handle representation, so this asks the host which kind the handle points at.",
        "var_dump(is_array([1]));   // => bool(true)",
    ),
    (
        "is_int",
        "Core library — types and output",
        "is_int(mixed $value): bool",
        "True only for a real integer — a numeric string is not one.",
        "var_dump(is_int(5), is_int(\"5\"));   // => bool(true) bool(false)",
    ),
    (
        "is_integer",
        "Core library — types and output",
        "is_integer(mixed $value): bool",
        "The alias of `is_int`, sharing its match arm.",
        "",
    ),
    (
        "is_long",
        "Core library — types and output",
        "is_long(mixed $value): bool",
        "The second alias of `is_int`, sharing the same arm.",
        "",
    ),
    (
        "is_float",
        "Core library — types and output",
        "is_float(mixed $value): bool",
        "True only for a real float value.",
        "var_dump(is_float(1.5));   // => bool(true)",
    ),
    (
        "is_double",
        "Core library — types and output",
        "is_double(mixed $value): bool",
        "The alias of `is_float`, sharing its match arm.",
        "",
    ),
    (
        "is_string",
        "Core library — types and output",
        "is_string(mixed $value): bool",
        "True only for a string value.",
        "var_dump(is_string(\"x\"));   // => bool(true)",
    ),
    (
        "is_bool",
        "Core library — types and output",
        "is_bool(mixed $value): bool",
        "True only for `true` or `false`.",
        "var_dump(is_bool(true), is_bool(1));   // => bool(true) bool(false)",
    ),
    (
        "is_null",
        "Core library — types and output",
        "is_null(mixed $value): bool",
        "True for null, which is also what an unset variable and a missing array key read as.",
        "var_dump(is_null(null));   // => bool(true)",
    ),
    (
        "is_numeric",
        "Core library — types and output",
        "is_numeric(mixed $value): bool",
        "True for an integer, a float, or a string that parses as a number — including leading whitespace, a sign, hex-free decimals, and exponent notation.",
        "var_dump(is_numeric(\"3.5\"), is_numeric(\"3.5px\"));   // => bool(true) bool(false)",
    ),
    (
        "is_callable",
        "Core library — types and output",
        "is_callable(mixed $value): bool",
        "True for a closure handle, and for ANY non-empty string. DIVERGENCE: the host exposes no function-table lookup here, so `is_callable(\"no_such_function\")` is true — the name is never resolved.",
        "var_dump(is_callable(\"strlen\"), is_callable(\"nope\"));   // => bool(true) bool(true)",
    ),
    (
        "intval",
        "Core library — types and output",
        "intval(mixed $value): int",
        "The integer value, taking the leading numeric prefix of a string and yielding 0 when there is none. DIVERGENCE: the `$base` argument is not read, so `intval(\"ff\", 16)` is 0.",
        "echo intval(\"42px\");   // => 42",
    ),
    (
        "floatval",
        "Core library — types and output",
        "floatval(mixed $value): float",
        "The float value, taking the leading numeric prefix of a string.",
        "echo floatval(\"3.5kg\");   // => 3.5",
    ),
    (
        "doubleval",
        "Core library — types and output",
        "doubleval(mixed $value): float",
        "The alias of `floatval`, sharing its match arm.",
        "",
    ),
    (
        "strval",
        "Core library — types and output",
        "strval(mixed $value): string",
        "The string value. DIVERGENCE: an object stringifies to `Array` because `__toString` is never consulted.",
        "echo strval(42);   // => 42",
    ),
    (
        "__cast_array",
        "Core library — types and output",
        "__cast_array(mixed $value): array",
        "Internal target of the `(array)` cast — not a PHP function, and not meant to be called by name. An array passes through, `null` becomes the empty array, an object yields its properties keyed by name, and any other scalar becomes a one-element list. DIVERGENCE: PHP mangles private/protected property names in an object cast (`\\0Class\\0prop`, `\\0*\\0prop`); this returns the plain names.",
        "var_dump((array)\"a\");   // => array(1) { [0]=> string(1) \"a\" }",
    ),
    (
        "__cast_object",
        "Core library — types and output",
        "__cast_object(mixed $value): object",
        "Internal target of the `(object)` cast — not a PHP function, and not meant to be called by name. An array becomes a `stdClass` whose keys are properties, `null` an empty `stdClass`, and any other scalar a `stdClass` with the value in a `scalar` property. An object passes through unchanged.",
        "$o = (object)[\"a\" => 1]; echo $o->a;   // => 1",
    ),
    (
        "boolval",
        "Core library — types and output",
        "boolval(mixed $value): bool",
        "The boolean value. Falsey values are `0`, `0.0`, `\"\"`, `\"0\"`, the empty array, and null.",
        "var_dump(boolval(\"\"), boolval(\"0\"), boolval(\"a\"));   // => bool(false) bool(false) bool(true)",
    ),
    (
        "print_r",
        "Core library — types and output",
        "print_r(mixed $value, bool $return = false): string|true",
        "Renders a value in PHP's indented human-readable form. With `$return` truthy the text is returned instead of printed. A structure that contains itself prints its head and then ` *RECURSION*` in place of the repeated block.",
        "echo print_r([1, 2], true);   // => Array\\n(\\n    [0] => 1\\n    [1] => 2\\n)",
    ),
    (
        "var_dump",
        "Core library — types and output",
        "var_dump(mixed ...$values): void",
        "Prints each value with its type and structure — `bool(true)`, `int(3)`, `float(1.5)`, `string(3) \"abc\"`, and nested `array(n) { … }`. A repeated element in a self-referential structure is replaced entirely by `*RECURSION*`, type header included.",
        "var_dump(true);   // => bool(true)",
    ),
    (
        "var_export",
        "Core library — types and output",
        "var_export(mixed $value, bool $return = false): string|null",
        "Renders a value as parsable PHP source. With `$return` truthy the text is returned; otherwise it is printed and null is returned. A circular reference raises `Warning: var_export does not handle circular references` and writes `NULL` in that position, so the output stays parsable but no longer rebuilds the original.",
        "var_export(1);   // => 1",
    ),
    (
        "printf",
        "Core library — types and output",
        "printf(string $format, mixed ...$values): int",
        "Writes a `sprintf`-formatted string to output and returns its length in BYTES.",
        "printf(\"%d\", 7);   // => 7",
    ),
    (
        "json_encode",
        "Core library — types and output",
        "json_encode(mixed $value): string",
        "Encodes a value as JSON, escaping `/` and non-ASCII characters by default and returning `false` (with `json_last_error()` set) for a NAN or INF (`JSON_ERROR_INF_OR_NAN`) or a structure containing itself (`JSON_ERROR_RECURSION`). `JSON_PRETTY_PRINT`, `JSON_UNESCAPED_SLASHES`, `JSON_UNESCAPED_UNICODE` and `JSON_THROW_ON_ERROR` are honoured. DIVERGENCE: the `$depth` argument is not read. `json_decode` lives in the `json` module, not here.",
        "echo json_encode([1, 2, 3]);   // => [1,2,3]",
    ),
    // ══ Strings (stdlib::strings) ═══════════════════════════════════════════
    // Second-tier string helpers. Names the core `call_library` match already
    // claims never reach this module.
    (
        "substr_count",
        "Strings",
        "substr_count(string $haystack, string $needle, int $offset = 0, ?int $length = null): int",
        "Counts non-overlapping matches inside the byte window `[$offset, $offset + $length)`. Negative offsets and lengths count from the end. An empty needle throws `ValueError: substr_count(): Argument #2 ($needle) must not be empty`. The window is a raw byte slice, so a multibyte haystack can be cut mid-character.",
        "echo substr_count(\"aaa\", \"aa\");   // => 1",
    ),
    (
        "substr_replace",
        "Strings",
        "substr_replace(array|string $string, array|string $replace, array|int $offset, array|int|null $length = null): string|array",
        "Splices the replacement over the byte range starting at `$offset`. An array `$string` returns an array spliced element-wise, with `$replace`, `$offset` and `$length` consumed positionally and falling back to `\"\"` / `0` / to-the-end once exhausted. The result is rebuilt lossily, so splicing at a non-character boundary yields U+FFFD.",
        "echo substr_replace(\"Hello\", \"XY\", 1, 3);   // => HXYo",
    ),
    (
        "addcslashes",
        "Strings",
        "addcslashes(string $string, string $characters): string",
        "Backslash-escapes every byte listed in `$characters`, which may use `a..z` inclusive ranges. Outside printable ASCII the escape is the C mnemonic (`\\n`, `\\t`, `\\r`, `\\a`, `\\v`, `\\b`, `\\f`) or a three-digit octal. A malformed range warns `addcslashes(): Invalid '..'-range, …` and contributes nothing.",
        "echo addcslashes(\"foo[bar]\", \"A..z\");   // => \\f\\o\\o\\[\\b\\a\\r\\]",
    ),
    (
        "stripcslashes",
        "Strings",
        "stripcslashes(string $string): string",
        "The inverse of `addcslashes`: understands the C mnemonics plus `\\xHH` (one or two hex digits) and `\\NNN` (up to three octal digits). An unrecognized escape yields the escaped character itself, so `\\z` is `z`.",
        "echo stripcslashes('\\101\\x42');   // => AB",
    ),
    (
        "count_chars",
        "Strings",
        "count_chars(string $string, int $mode = 0): array|string",
        "Per-byte histogram. Mode 0 reports all 256 counters, 1 only the non-zero ones, 2 only the zero ones; modes 3 and 4 return a STRING of the bytes that did / did not occur. A `$mode` outside 0-4 throws `ValueError`. DIVERGENCE: modes 3 and 4 can name bytes above 0x7F, which this engine's UTF-8 strings widen to two bytes each (see BUGS.md).",
        "print_r(count_chars(\"aab\", 3));   // => ab",
    ),
    (
        "strtok",
        "Strings",
        "strtok(string $string, ?string $token = null): string|false",
        "Stateful tokenizer. Two arguments install a new subject and answer its first token; one argument continues the saved subject with a (possibly different) delimiter set. Running out of tokens answers `false` AND discards the subject, so a further one-argument call keeps answering `false` rather than restarting.",
        "echo strtok(\"a b\", \" \"), strtok(\" \");   // => ab",
    ),
    (
        "strtr",
        "Strings",
        "strtr(string $string, array $pairs): string\nstrtr(string $string, string $from, string $to): string",
        "Two-argument form: longest-key-first, non-overlapping substring replacement in a single left-to-right pass, dropping empty keys. Three-argument form: byte-wise translation with both sets truncated to the shorter length. DIVERGENCE: in the two-argument form an unmatched byte at or above 0x80 is re-encoded as its Latin-1 codepoint, so untouched non-ASCII text is mangled.",
        "echo strtr(\"hi all\", [\"hi\" => \"bye\"]);   // => bye all",
    ),
    (
        "strstr",
        "Strings",
        "strstr(string $haystack, string $needle, bool $before_needle = false): string|false",
        "The part of the haystack from the first match onward, or the part before it when `$before_needle` is truthy; `false` when absent. An empty needle matches at offset 0 (PHP 8 semantics).",
        "echo strstr(\"user@example.com\", \"@\");   // => @example.com",
    ),
    (
        "strchr",
        "Strings",
        "strchr(string $haystack, string $needle, bool $before_needle = false): string|false",
        "The alias of `strstr`, sharing its match arm — the same alias relationship PHP has.",
        "",
    ),
    (
        "stristr",
        "Strings",
        "stristr(string $haystack, string $needle, bool $before_needle = false): string|false",
        "Case-insensitive `strstr`. DIVERGENCE: the folding is ASCII-only, so non-ASCII letters never match case-insensitively.",
        "echo stristr(\"HELLO\", \"ell\");   // => ELLO",
    ),
    (
        "strrchr",
        "Strings",
        "strrchr(string $haystack, string $needle): string|false",
        "The substring from the LAST occurrence of the needle's FIRST BYTE through the end; `false` when absent or the needle is empty. DIVERGENCE: PHP 8.3's `$before_needle` parameter is not read.",
        "echo strrchr(\"a/b/c\", \"/\");   // => /c",
    ),
    (
        "strpbrk",
        "Strings",
        "strpbrk(string $string, string $characters): string|false",
        "The substring beginning at the first byte that belongs to the character set, through the end; `false` when no byte matches.",
        "echo strpbrk(\"This is a test\", \"st\");   // => s is a test",
    ),
    (
        "strspn",
        "Strings",
        "strspn(string $string, string $characters, int $offset = 0, ?int $length = null): int",
        "Length in bytes of the initial run within the window whose bytes all belong to the set. Set membership is byte-oriented, so a multibyte mask character is matched byte by byte.",
        "echo strspn(\"42 apples\", \"0123456789\");   // => 2",
    ),
    (
        "strcspn",
        "Strings",
        "strcspn(string $string, string $characters, int $offset = 0, ?int $length = null): int",
        "The complement of `strspn`: the length of the initial run of bytes NOT in the set. It shares the same match arm with the membership test inverted.",
        "echo strcspn(\"abc123\", \"0123456789\");   // => 3",
    ),
    (
        "stripos",
        "Strings",
        "stripos(string $haystack, string $needle, int $offset = 0): int|false",
        "Byte offset of the first ASCII-case-insensitive match at or after the offset, or `false`. A negative offset counts from the end and an empty needle returns the offset. DIVERGENCE: folding is ASCII-only.",
        "echo stripos(\"Hello\", \"L\");   // => 2",
    ),
    (
        "strrpos",
        "Strings",
        "strrpos(string $haystack, string $needle, int $offset = 0): int|false",
        "Byte offset of the LAST match. A non-negative offset requires the match to start at or after it; a negative one caps how late it may start. An empty needle returns the string length (PHP 8 semantics).",
        "echo strrpos(\"hello\", \"l\");   // => 3",
    ),
    (
        "strripos",
        "Strings",
        "strripos(string $haystack, string $needle, int $offset = 0): int|false",
        "`strrpos` with ASCII case-insensitive comparison; it shares the same match arm. DIVERGENCE: folding is ASCII-only.",
        "echo strripos(\"HELLO\", \"l\");   // => 3",
    ),
    (
        "strncasecmp",
        "Strings",
        "strncasecmp(string $string1, string $string2, int $length): int",
        "Compares the first `$length` bytes after ASCII-lowercasing, returning `-1`, `0`, or `1`. A negative length raises `strncasecmp(): Argument #3 ($length) must be greater than or equal to 0`.",
        "echo strncasecmp(\"Hello\", \"HELLO world\", 5);   // => 0",
    ),
    (
        "str_ireplace",
        "Strings",
        "str_ireplace(array|string $search, array|string $replace, string $subject): string",
        "ASCII-case-insensitive `str_replace`. An array `$search` is applied in sequence, index-matched against an array `$replace` (missing entries become `\"\"`) or with one scalar for all. DIVERGENCE: an array `$subject` is string-cast rather than mapped, and there is no `$count` out-parameter.",
        "echo str_ireplace(\"WORLD\", \"there\", \"Hello world\");   // => Hello there",
    ),
    (
        "nl2br",
        "Strings",
        "nl2br(string $string): string",
        "Inserts a `<br />` before each `\\r\\n`, `\\n\\r`, `\\r`, or `\\n`, keeping the original break. DIVERGENCE: the `$use_xhtml` argument is not read, so the output is always the XHTML `<br />`.",
        "echo nl2br(\"a\\nb\");   // => a<br />\\nb",
    ),
    (
        "chunk_split",
        "Strings",
        "chunk_split(string $string, int $length = 76, string $separator = \"\\r\\n\"): string",
        "Appends the separator after every `$length` units. DIVERGENCE: chunking counts CODEPOINTS, not bytes as PHP does, so multibyte input chunks differently. A non-positive length throws `ValueError: chunk_split(): Argument #2 ($length) must be greater than 0`.",
        "echo chunk_split(\"abcdef\", 2, \"-\");   // => ab-cd-ef-",
    ),
    (
        "quotemeta",
        "Strings",
        "quotemeta(string $string): string",
        "Backslash-escapes each of `. \\ + * ? [ ^ ] $ ( )`. The escape set is ASCII, so the result matches PHP's byte behaviour.",
        "echo quotemeta(\"1+1=2\");   // => 1\\+1=2",
    ),
    (
        "addslashes",
        "Strings",
        "addslashes(string $string): string",
        "Backslash-escapes `'`, `\"`, and `\\`, and maps a NUL byte to the two-character sequence `\\0`.",
        "echo addslashes(\"O'Reilly\");   // => O\\'Reilly",
    ),
    (
        "stripslashes",
        "Strings",
        "stripslashes(string $string): string",
        "Removes one level of backslashes, keeping the escaped character — except `\\0`, which becomes a real NUL. A trailing lone backslash is dropped.",
        "echo stripslashes(\"O\\\\'Reilly\");   // => O'Reilly",
    ),
    (
        "str_rot13",
        "Strings",
        "str_rot13(string $string): string",
        "Rotates ASCII letters by 13 places. Every other character, including all non-ASCII, passes through untouched. Applying it twice restores the input.",
        "echo str_rot13(\"abc\");   // => nop",
    ),
    (
        "similar_text",
        "Strings",
        "similar_text(string $string1, string $string2): int",
        "The number of matching characters, using PHP's own recursive longest-common-substring algorithm. DIVERGENCE: the by-reference `$percent` out-parameter does not exist, so only the count is available.",
        "echo similar_text(\"World\", \"word\");   // => 3",
    ),
    (
        "levenshtein",
        "Strings",
        "levenshtein(string $string1, string $string2, int $insertion_cost = 1, int $replacement_cost = 1, int $deletion_cost = 1): int",
        "Weighted edit distance over BYTES, so a multibyte character counts as several edits. Note the cost defaults apply only when the argument is absent — passing an explicit null coerces that cost to 0.",
        "echo levenshtein(\"kitten\", \"sitting\");   // => 3",
    ),
    (
        "vsprintf",
        "Strings",
        "vsprintf(string $format, array $values): string",
        "`sprintf` with the arguments supplied as one array, spread in iteration order with keys discarded.",
        "echo vsprintf(\"%d-%s\", [1, \"x\"]);   // => 1-x",
    ),
    (
        "vprintf",
        "Strings",
        "vprintf(string $format, array $values): int",
        "Writes a `vsprintf` result to output and returns its length in BYTES.",
        "vprintf(\"%d\", [7]);   // => 7",
    ),
    (
        "sscanf",
        "Strings",
        "sscanf(string $string, string $format, mixed &...$vars): array|int|null",
        "Parses the string against the format. With two arguments the result is an array of the converted values, padded with nulls to one entry per non-suppressed specifier; with by-reference arguments it is the number of specifiers processed, and a variable no conversion reached is left untouched. Supports `%d %D %i %o %x %X %u %f %e %E %g %s %c %n %[…] %%`, `*` suppression, field widths, the ignored `l`/`L`/`h` size modifiers, literal text and whitespace runs. When the input runs out before any conversion the answer is `null` (two-argument) or `-1` (by-reference). DIVERGENCE: the `%n$` positional form is not implemented, and no format is rejected up front the way PHP's `ValidateFormat` does.",
        "print_r(sscanf(\"age:42\", \"age:%d\"));   // => Array\\n(\\n    [0] => 42\\n)",
    ),
    (
        "htmlspecialchars_decode",
        "Strings",
        "htmlspecialchars_decode(string $string): string",
        "Decodes only what `htmlspecialchars` can produce — `&lt;`, `&gt;`, `&amp;`, `&quot;` and the numeric single quote — and `$flags` gates the two quote entities. A named entity like `&eacute;` and any other numeric reference are left standing, which is what separates it from `html_entity_decode`.",
        "echo htmlspecialchars_decode(\"a&lt;b\");   // => a<b",
    ),
    (
        "html_entity_decode",
        "Strings",
        "html_entity_decode(string $string): string",
        "Decodes the full HTML 4.01 named-entity table plus decimal (`&#233;`) and hexadecimal (`&#xE9;`) references; an unknown entity, and an `&` with no terminating `;`, are copied through verbatim. `$flags` gates the quote entities. DIVERGENCE: `$encoding` is not read (input is treated as UTF-8).",
        "echo html_entity_decode(\"caf&eacute;\");   // => café",
    ),
    (
        "strip_tags",
        "Strings",
        "strip_tags(string $string): string",
        "A port of `php_strip_tags_ex`, so its five-state scanner — HTML tag, `<? … ?>`, `<! … >`, `<!-- … -->`, and the `<?xml` / `<!DOCTYPE` re-entries — matches the reference on quoted attributes containing `>`, nested `<`, and unterminated tags. `$allowed_tags` is honoured in both spellings, the string `\"<b><i>\"` and the array `[\"b\", \"i\"]`; an allowed tag is re-emitted verbatim, attributes included.",
        "echo strip_tags(\"<p>hi</p>\");   // => hi",
    ),
    (
        "mb_strlen",
        "Strings",
        "mb_strlen(string $string): int",
        "The number of Unicode CODEPOINTS, the multibyte counterpart of `strlen`. The `$encoding` argument is accepted and ignored — phplang strings are always UTF-8.",
        "echo mb_strlen(\"héllo\");   // => 5",
    ),
    (
        "mb_strtoupper",
        "Strings",
        "mb_strtoupper(string $string): string",
        "Full Unicode uppercase, which can change the string's length (German sharp s becomes `SS`). The `$encoding` argument is ignored.",
        "echo mb_strtoupper(\"héllo\");   // => HÉLLO",
    ),
    (
        "mb_strtolower",
        "Strings",
        "mb_strtolower(string $string): string",
        "Full Unicode lowercase. The `$encoding` argument is ignored.",
        "echo mb_strtolower(\"HÉLLO\");   // => héllo",
    ),
    (
        "mb_substr",
        "Strings",
        "mb_substr(string $string, int $start, ?int $length = null): string",
        "Codepoint-aware substring. A negative start counts from the end, a negative length omits that many trailing codepoints, and the end is clamped. The `$encoding` argument is ignored.",
        "echo mb_substr(\"héllo\", 1, 3);   // => éll",
    ),
    // ══ Multibyte strings (stdlib::mbstring) ════════════════════════════════
    (
        "mb_str_split",
        "Multibyte strings",
        "mb_str_split(string $string, int $length = 1): array",
        "Splits into chunks of `$length` CODEPOINTS; the final chunk may be shorter. A length below 1 throws `ValueError: mb_str_split(): Argument #2 ($length) must be greater than 0`.",
        "echo mb_str_split(\"héllo\")[1];   // => é",
    ),
    (
        "mb_convert_case",
        "Multibyte strings",
        "mb_convert_case(string $string, int $mode): string",
        "Mode 1 lowercases, mode 2 title-cases, and mode 0 — plus every UNRECOGNIZED mode — uppercases. Title-casing uppercases the first letter of each WORD and lowercases the rest of it; a Unicode case-ignorable character (an apostrophe, `.`, `:`) is transparent rather than a word break, so `\"who's who\"` becomes `\"Who's Who\"` while `\"x,y\"` becomes `\"X,Y\"`. DIVERGENCE: PHP's `MB_CASE_*_SIMPLE` modes (3-5) are not distinguished.",
        "echo mb_convert_case(\"hello world\", MB_CASE_TITLE);   // => Hello World",
    ),
    (
        "mb_strpos",
        "Multibyte strings",
        "mb_strpos(string $haystack, string $needle, int $offset = 0): int|false",
        "The CODEPOINT index of the first match at or after the offset, or `false`. An offset outside `[-len, len]` raises `mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)`.",
        "echo mb_strpos(\"héllo\", \"llo\");   // => 2",
    ),
    (
        "mb_stripos",
        "Multibyte strings",
        "mb_stripos(string $haystack, string $needle, int $offset = 0): int|false",
        "Case-insensitive `mb_strpos`. DIVERGENCE: folding keeps only the first codepoint of each character's lowercase expansion so that indexes stay 1:1, which differs from PHP's full case mapping for characters like U+0130.",
        "echo mb_stripos(\"HÉLLO\", \"é\");   // => 1",
    ),
    (
        "mb_strrpos",
        "Multibyte strings",
        "mb_strrpos(string $haystack, string $needle, int $offset = 0): int|false",
        "The codepoint index of the LAST match, with the same offset rules and out-of-range error as `mb_strpos`. An empty needle returns the codepoint length.",
        "echo mb_strrpos(\"héllo\", \"l\");   // => 3",
    ),
    (
        "mb_strripos",
        "Multibyte strings",
        "mb_strripos(string $haystack, string $needle, int $offset = 0): int|false",
        "Case-insensitive `mb_strrpos`, using the same single-codepoint folding as `mb_stripos`.",
        "",
    ),
    (
        "mb_substr_count",
        "Multibyte strings",
        "mb_substr_count(string $haystack, string $needle): int",
        "Non-overlapping match count in codepoints. An empty needle throws `ValueError: mb_substr_count(): Argument #2 ($needle) must not be empty`.",
        "echo mb_substr_count(\"ababa\", \"aba\");   // => 1",
    ),
    (
        "mb_str_pad",
        "Multibyte strings",
        "mb_str_pad(string $string, int $length, string $pad_string = \" \", int $pad_type = STR_PAD_RIGHT): string",
        "Pads to `$length` CODEPOINTS by cycling the pad string. All three `STR_PAD_*` modes are honoured, with `STR_PAD_BOTH` flooring the left side. An empty pad string throws `ValueError: mb_str_pad(): Argument #3 ($pad_string) must not be empty`, and only when padding is actually needed.",
        "echo mb_str_pad(\"é\", 3, \"-\");   // => é--",
    ),
    (
        "mb_ord",
        "Multibyte strings",
        "mb_ord(string $string): int|false",
        "The Unicode codepoint of the first character, or `false` for an empty string — the multibyte counterpart of `ord`, which reports a byte instead.",
        "echo mb_ord(\"é\");   // => 233",
    ),
    (
        "mb_chr",
        "Multibyte strings",
        "mb_chr(int $codepoint): string|false",
        "The character for a codepoint, or `false` when it is negative, a surrogate, or above U+10FFFF.",
        "echo mb_chr(233);   // => é",
    ),
    (
        "mb_lcfirst",
        "Multibyte strings",
        "mb_lcfirst(string $string): string",
        "Lowercases the first character with full Unicode folding and leaves the remainder untouched; the empty string maps to itself.",
        "echo mb_lcfirst(\"École\");   // => école",
    ),
    (
        "mb_ucfirst",
        "Multibyte strings",
        "mb_ucfirst(string $string): string",
        "Uppercases the first character with full Unicode folding, which may expand it to several codepoints.",
        "echo mb_ucfirst(\"école\");   // => École",
    ),
    (
        "mb_scrub",
        "Multibyte strings",
        "mb_scrub(string $string): string",
        "Returns the string verbatim. It is a genuine no-op here: a phplang string is always valid UTF-8, so there is never an ill-formed sequence to substitute.",
        "",
    ),
    (
        "mb_strcut",
        "Multibyte strings",
        "mb_strcut(string $string, int $start, ?int $length = null): string",
        "A BYTE-offset substring that never splits a character: the offsets count bytes, then both endpoints are floored to the nearest UTF-8 boundary.",
        "echo mb_strcut(\"héllo\", 0, 2);   // => h",
    ),
    (
        "mb_split",
        "Multibyte strings",
        "mb_split(string $pattern, string $string, int $limit = -1): array|false",
        "Splits on a regular expression. A positive limit caps the piece count with the last piece holding the remainder. DIVERGENCE: the Rust `regex` crate replaces Oniguruma, so backreferences and lookaround are unsupported and an uncompilable pattern returns `false`.",
        "print_r(mb_split(\"[,;]\", \"a,b;c\"));   // => Array\\n(\\n    [0] => a\\n    [1] => b\\n    [2] => c\\n)",
    ),
    (
        "mb_convert_kana",
        "Multibyte strings",
        "mb_convert_kana(string $string, string $mode = \"KV\"): string",
        "Converts between fullwidth and halfwidth ASCII by codepoint arithmetic: `a`/`r`/`n` fold fullwidth to halfwidth for printables, letters, and digits, `A`/`R`/`N` do the reverse, and `s`/`S` map the ideographic space. DIVERGENCE: the kana modes `k K h H c C v V` are unimplemented, which includes the DEFAULT mode `\"KV\"` — calling it with no mode is a no-op.",
        "",
    ),
    (
        "mb_strwidth",
        "Multibyte strings",
        "mb_strwidth(string $string): int",
        "The display width, counting 2 for codepoints in the 23 East-Asian wide and fullwidth ranges ported from PHP's own table and 1 for everything else. DIVERGENCE: combining marks and zero-width characters count as 1, not 0.",
        "echo mb_strwidth(\"ab\");   // => 2",
    ),
    (
        "mb_convert_encoding",
        "Multibyte strings",
        "mb_convert_encoding(string $string, string $to_encoding): string",
        "Maps unrepresentable characters to `?`: everything at or above U+0080 for `ASCII`, above U+00FF for `ISO-8859-1`/`Latin-1`. `UTF-8` returns the string unchanged; any OTHER target raises `ValueError: mb_convert_encoding(): Argument #2 ($to_encoding) must be a valid encoding, \"…\" given`. DIVERGENCE: `$from_encoding` is ignored, true single-byte output is impossible in a UTF-8 runtime, and the array form is unsupported.",
        "echo mb_convert_encoding(\"héllo\", \"ASCII\");   // => h?llo",
    ),
    (
        "mb_detect_encoding",
        "Multibyte strings",
        "mb_detect_encoding(string $string, array|string|null $encodings = null): string|false",
        "The first candidate the string satisfies, where `ASCII` requires every byte below 0x80 and `UTF-8` always succeeds; any other candidate never matches and an exhausted list yields `false`. The default order is ASCII then UTF-8. DIVERGENCE: `$strict` is ignored, and real detection is impossible because strings are always valid UTF-8.",
        "echo mb_detect_encoding(\"abc\");   // => ASCII",
    ),
    (
        "mb_check_encoding",
        "Multibyte strings",
        "mb_check_encoding(string $value = \"\", ?string $encoding = null): bool",
        "Returns true unless the encoding normalizes to `ASCII`, in which case it checks that every byte is below 0x80. DIVERGENCE: a missing `$value` checks the empty string rather than all previous output, and the array form is unsupported.",
        "var_dump(mb_check_encoding(\"héllo\", \"ASCII\"));   // => bool(false)",
    ),
    (
        "mb_internal_encoding",
        "Multibyte strings",
        "mb_internal_encoding(?string $encoding = null): string|bool",
        "With no argument returns the stored encoding, defaulting to `UTF-8`; with one it stores the raw string and returns true. DIVERGENCE: the name is never validated, the stored value only affects `mb_check_encoding`, and the state is thread-local and NOT reset between evaluations on the same thread.",
        "echo mb_internal_encoding();   // => UTF-8",
    ),
    // ══ Text formatting (stdlib::textx) ═════════════════════════════════════
    (
        "fprintf",
        "Text formatting",
        "fprintf(resource $stream, string $format, mixed ...$values): int|false",
        "Formats with `sprintf`, writes the bytes to the stream, flushes a dirty file resource to disk, and returns the byte count — or `false` when the write fails.",
        "$f = fopen(\"/tmp/x.txt\", \"w\"); echo fprintf($f, \"%d\", 42); fclose($f);   // => 2",
    ),
    (
        "vfprintf",
        "Text formatting",
        "vfprintf(resource $stream, string $format, array $values): int|false",
        "`fprintf` with the format arguments supplied as one array, spread in iteration order with keys discarded.",
        "",
    ),
    (
        "fscanf",
        "Text formatting",
        "fscanf(resource $stream, string $format): array|false",
        "Reads one line from the stream and parses it with `sscanf`. DIVERGENCE: at end of file it returns `false`, not PHP's `-1`, deliberately so that `while ($r = fscanf(…))` terminates. The by-reference extra-argument form does not exist — unlike `sscanf`, which does implement it.",
        "",
    ),
    (
        "array_change_key_case",
        "Text formatting",
        "array_change_key_case(array $array, int $case = CASE_LOWER): array",
        "A copy with every STRING key ASCII-lowercased (case 0, the default and the fallback) or ASCII-uppercased (case 1). Integer keys pass through. Folding is ASCII-only and locale-independent, matching PHP, so key length never changes.",
        "print_r(array_change_key_case([\"AbC\" => 1]));   // => Array\\n(\\n    [abc] => 1\\n)",
    ),
    (
        "get_html_translation_table",
        "Text formatting",
        "get_html_translation_table(int $table = HTML_SPECIALCHARS, int $flags = ENT_QUOTES): array",
        "The character-to-entity map: `&`, `<`, and `>` always, plus `\"` and `'` per the quote bits of `$flags`. With `$table` = 1 (`HTML_ENTITIES`) it appends the 96-entry ISO-8859-1 supplement U+00A0-U+00FF. DIVERGENCE: only the Latin-1 supplement is included, the `$encoding` argument is not read, and the doctype bits are ignored so `'` is always `&#039;`.",
        "",
    ),
    // ══ Arrays (stdlib::arrays) ═════════════════════════════════════════════
    (
        "array_column",
        "Arrays",
        "array_column(array $rows, ?string $column_key, ?string $index_key = null): array",
        "Plucks one column out of a list of rows, optionally re-keying by another column. A null column key keeps the whole row, and a row missing the column is skipped. Rows may be arrays or objects.",
        "echo implode(\",\", array_column([[\"id\" => 1], [\"id\" => 2]], \"id\"));   // => 1,2",
    ),
    (
        "array_chunk",
        "Arrays",
        "array_chunk(array $array, int $size, bool $preserve_keys = false): array",
        "Splits into a list of sub-arrays of at most `$size` elements. A size below 1 throws `ValueError: array_chunk(): Argument #2 ($length) must be greater than 0`.",
        "echo count(array_chunk([1, 2, 3], 2));   // => 2",
    ),
    (
        "array_fill_keys",
        "Arrays",
        "array_fill_keys(array $keys, mixed $value): array",
        "An array using each element of `$keys` as a key, every entry set to the same value.",
        "print_r(array_fill_keys([\"a\"], 0));   // => Array\\n(\\n    [a] => 0\\n)",
    ),
    (
        "array_pad",
        "Arrays",
        "array_pad(array $array, int $size, mixed $value): array",
        "Pads to `abs($size)` elements — a positive size pads on the right, a negative one on the left. Integer keys are renumbered and string keys preserved, as `array_merge` does.",
        "echo implode(\",\", array_pad([1], 3, 0));   // => 1,0,0",
    ),
    (
        "array_key_first",
        "Arrays",
        "array_key_first(array $array): mixed",
        "The first key in insertion order, or null for an empty array.",
        "var_dump(array_key_first([\"a\" => 1, \"b\" => 2]));   // => string(1) \"a\"",
    ),
    (
        "array_key_last",
        "Arrays",
        "array_key_last(array $array): mixed",
        "The last key in insertion order, or null for an empty array.",
        "var_dump(array_key_last([\"a\" => 1, \"b\" => 2]));   // => string(1) \"b\"",
    ),
    (
        "array_is_list",
        "Arrays",
        "array_is_list(array $array): bool",
        "True when the keys are exactly `0, 1, …, n-1` in order. A non-array argument returns false rather than raising a `TypeError`.",
        "var_dump(array_is_list([1, 2]), array_is_list([1 => 1]));   // => bool(true) bool(false)",
    ),
    (
        "array_diff_key",
        "Arrays",
        "array_diff_key(array $array, array ...$excludes): array",
        "The entries of the first array whose KEY is absent from every other array. Keys are compared by their string form.",
        "print_r(array_diff_key([\"a\" => 1, \"b\" => 2], [\"a\" => 9]));   // => Array\\n(\\n    [b] => 2\\n)",
    ),
    (
        "array_intersect_key",
        "Arrays",
        "array_intersect_key(array $array, array ...$others): array",
        "The entries of the first array whose key is present in every other array. It shares the `array_diff_key` arm with the test inverted.",
        "print_r(array_intersect_key([\"a\" => 1, \"b\" => 2], [\"a\" => 9]));   // => Array\\n(\\n    [a] => 1\\n)",
    ),
    (
        "array_diff_assoc",
        "Arrays",
        "array_diff_assoc(array $array, array ...$excludes): array",
        "Like `array_diff_key` but matching on key AND value, both compared by string form.",
        "",
    ),
    (
        "array_intersect_assoc",
        "Arrays",
        "array_intersect_assoc(array $array, array ...$others): array",
        "Keeps the entries whose key-and-value pair appears in every other array, comparing both by string form.",
        "",
    ),
    (
        "array_merge_recursive",
        "Arrays",
        "array_merge_recursive(array ...$arrays): array",
        "Merges arrays, recursing into shared STRING keys: two arrays under one key merge, and anything else under a duplicate string key is gathered into a flat list. Integer keys always append. Nested arrays are deep-copied, so the inputs are never mutated.",
        "print_r(array_merge_recursive([\"k\" => \"a\"], [\"k\" => \"b\"]));\n// => Array\\n(\\n    [k] => Array\\n        (\\n            [0] => a\\n            [1] => b\\n        )\\n\\n)",
    ),
    (
        "array_replace",
        "Arrays",
        "array_replace(array $base, array ...$rest): array",
        "Starts from `$base`, then overwrites or inserts every entry of each later array by key. There is no recursion into nested arrays.",
        "print_r(array_replace([\"a\" => 1], [\"a\" => 2]));   // => Array\\n(\\n    [a] => 2\\n)",
    ),
    (
        "array_replace_recursive",
        "Arrays",
        "array_replace_recursive(array $base, array ...$rest): array",
        "As `array_replace`, except that when both sides hold an array under the same key the two are merged recursively instead of the later one replacing the earlier wholesale. Any other type pairing, or a key present on only one side, replaces.",
        "print_r(array_replace_recursive([\"a\" => [\"b\" => 1, \"c\" => 2]], [\"a\" => [\"b\" => 9]]));   // => Array\\n(\\n    [a] => Array\\n        (\\n            [b] => 9\\n            [c] => 2\\n        )\\n\\n)",
    ),
    (
        "array_count_values",
        "Arrays",
        "array_count_values(array $array): array",
        "Tallies how often each value occurs. Only integer and string values are counted; every other value type is skipped, matching PHP.",
        "print_r(array_count_values([\"a\", \"a\", \"b\"]));   // => Array\\n(\\n    [a] => 2\\n    [b] => 1\\n)",
    ),
    (
        "usort",
        "Arrays",
        "usort(array $array, callable $callback): bool",
        "Sorts by value with a user comparator, then reindexes from 0. The sort is stable, as PHP's is, and tolerates a comparator that contradicts itself (`fn() => random_int(-1, 1)`) by answering with some permutation rather than failing. The comparator runs the VM, so an exception it throws stops the sort.",
        "$a = [3, 1, 2]; usort($a, fn($x, $y) => $x <=> $y); echo implode(\",\", $a);   // => 1,2,3",
    ),
    (
        "uasort",
        "Arrays",
        "uasort(array $array, callable $callback): bool",
        "Sorts by value with a user comparator while preserving the key association.",
        "$a = [\"b\" => 2, \"a\" => 1]; uasort($a, fn($x, $y) => $x <=> $y);\necho implode(\",\", array_keys($a));   // => a,b",
    ),
    (
        "uksort",
        "Arrays",
        "uksort(array $array, callable $callback): bool",
        "Sorts by KEY with a user comparator while preserving the key association.",
        "$a = [\"b\" => 1, \"a\" => 2]; uksort($a, fn($x, $y) => strcmp($x, $y));\necho implode(\",\", array_keys($a));   // => a,b",
    ),
    (
        "natsort",
        "Arrays",
        "natsort(array $array): bool",
        "Natural-order sort by value, preserving keys. Digit runs compare numerically, so `img12` sorts after `img2`. A run with a leading zero compares left-aligned, matching PHP's `strnatcmp`.",
        "$a = [\"img12\", \"img2\"]; natsort($a); echo implode(\",\", $a);   // => img2,img12",
    ),
    (
        "natcasesort",
        "Arrays",
        "natcasesort(array $array): bool",
        "`natsort` with case folded before comparison.",
        "",
    ),
    (
        "shuffle",
        "Arrays",
        "shuffle(array $array): bool",
        "Randomizes the order in place with Fisher-Yates and reindexes from 0. DIVERGENCE: the generator is a thread-local xorshift64 seeded lazily from the wall clock, not PHP's Mt19937, so `mt_srand()` does not make the order reproducible.",
        "",
    ),
    (
        "array_rand",
        "Arrays",
        "array_rand(array $array, int $num = 1): mixed",
        "One random key, or an array of `$num` distinct keys in their original order. An EMPTY array raises `ValueError: array_rand(): Argument #1 ($array) must not be empty` — there is no `$num` that would work — while a `$num` outside `1..count($array)` on a non-empty array names argument #2 instead. Uses the same non-reproducible xorshift64 generator as `shuffle`.",
        "",
    ),
    (
        "array_walk",
        "Arrays",
        "array_walk(array $array, callable $callback, mixed $extra = null): bool",
        "Calls `$callback($value, $key[, $extra])` for every element and returns true. The value is passed through a reference cell, so a `function (&$v)` callback writes back into the array, scalars included.",
        "$a = [1, 2]; array_walk($a, function ($v, $k) { echo $k . $v; });   // => 0112",
    ),
    (
        "compact",
        "Arrays",
        "compact(string|array ...$names): array",
        "Builds an array from the named variables, pulling each bound value out of the current scope. A name may itself be an array of names, recursively. A name that is not BOUND is skipped with `Warning: compact(): Undefined variable $x` — a variable holding null is bound, so it is captured with no warning — and an argument that is neither a string nor an array is skipped with `Warning: compact(): Argument #N must be string or array of strings, <type> given`, numbered by the top-level argument even when it is nested inside an array of names.",
        "$x = 1; $y = 2; print_r(compact(\"x\", \"y\"));   // => Array\\n(\\n    [x] => 1\\n    [y] => 2\\n)",
    ),
    (
        "extract",
        "Arrays",
        "extract(array $array): int",
        "Imports each string-keyed entry as a variable in the current scope and returns how many were set. Integer keys are skipped because they are not valid variable names. DIVERGENCE: the `$flags` and `$prefix` arguments do not exist.",
        "extract([\"n\" => 7]); echo $n;   // => 7",
    ),
    (
        "end",
        "Arrays",
        "end(array $array): mixed",
        "Moves the array's internal pointer to the last element and returns its value; `false` for an empty array. The cursor lives in a side table keyed by the array handle with an append-invariant fingerprint, so appending does not rewind it — matching PHP.",
        "$a = [1, 2, 3]; echo end($a);   // => 3",
    ),
    (
        "reset",
        "Arrays",
        "reset(array $array): mixed",
        "Moves the internal pointer to the first element and returns its value; `false` for an empty array.",
        "$a = [1, 2, 3]; end($a); echo reset($a);   // => 1",
    ),
    (
        "current",
        "Arrays",
        "current(array $array): mixed",
        "The value at the internal pointer without moving it, or `false` once the pointer has fallen off either end.",
        "$a = [1, 2]; echo current($a);   // => 1",
    ),
    (
        "pos",
        "Arrays",
        "pos(array $array): mixed",
        "The alias of `current`, sharing its match arm.",
        "",
    ),
    (
        "key",
        "Arrays",
        "key(array $array): mixed",
        "The key at the internal pointer, or null once the pointer is off the end.",
        "$a = [\"a\" => 1]; echo key($a);   // => a",
    ),
    (
        "next",
        "Arrays",
        "next(array $array): mixed",
        "Advances the internal pointer and returns the new element's value, or `false` once it runs past the end. The off-the-end state is sticky, as in PHP: further `next`/`prev` calls stay invalid until `reset` or `end`.",
        "$a = [1, 2]; echo next($a);   // => 2",
    ),
    (
        "prev",
        "Arrays",
        "prev(array $array): mixed",
        "Steps the internal pointer back one element and returns its value, or `false` once it runs past the start, entering the same sticky invalid state.",
        "$a = [1, 2]; end($a); echo prev($a);   // => 1",
    ),
    // ══ Math (stdlib::math) ═════════════════════════════════════════════════
    (
        "expm1",
        "Math",
        "expm1(float $num): float",
        "Computes `exp($num) - 1` with the precision-preserving `exp_m1`, which matters for arguments near zero.",
        "echo expm1(0);   // => 0",
    ),
    (
        "log1p",
        "Math",
        "log1p(float $num): float",
        "Computes `log(1 + $num)` precisely for arguments near zero.",
        "echo log1p(0);   // => 0",
    ),
    (
        "sinh",
        "Math",
        "sinh(float $num): float",
        "Hyperbolic sine.",
        "echo sinh(0);   // => 0",
    ),
    (
        "cosh",
        "Math",
        "cosh(float $num): float",
        "Hyperbolic cosine.",
        "echo cosh(0);   // => 1",
    ),
    (
        "tanh",
        "Math",
        "tanh(float $num): float",
        "Hyperbolic tangent.",
        "echo tanh(0);   // => 0",
    ),
    (
        "asinh",
        "Math",
        "asinh(float $num): float",
        "Inverse hyperbolic sine.",
        "echo asinh(0);   // => 0",
    ),
    (
        "acosh",
        "Math",
        "acosh(float $num): float",
        "Inverse hyperbolic cosine. An argument below 1 yields NAN rather than raising.",
        "echo acosh(1);   // => 0",
    ),
    (
        "atanh",
        "Math",
        "atanh(float $num): float",
        "Inverse hyperbolic tangent. An argument outside `(-1, 1)` yields NAN or an infinity rather than raising.",
        "echo atanh(0);   // => 0",
    ),
    (
        "asin",
        "Math",
        "asin(float $num): float",
        "Arc sine in radians; `|$num| > 1` yields NAN.",
        "echo asin(0);   // => 0",
    ),
    (
        "acos",
        "Math",
        "acos(float $num): float",
        "Arc cosine in radians; `|$num| > 1` yields NAN.",
        "echo acos(1);   // => 0",
    ),
    (
        "atan",
        "Math",
        "atan(float $num): float",
        "Arc tangent in radians.",
        "echo atan(0);   // => 0",
    ),
    (
        "atan2",
        "Math",
        "atan2(float $y, float $x): float",
        "The two-argument arc tangent of `$y / $x` in radians, using the signs of both operands to select the quadrant. Note the first argument is the ordinate.",
        "echo atan2(0, 1);   // => 0",
    ),
    (
        "deg2rad",
        "Math",
        "deg2rad(float $num): float",
        "Converts degrees to radians as `$num * PI / 180`.",
        "echo deg2rad(0);   // => 0",
    ),
    (
        "rad2deg",
        "Math",
        "rad2deg(float $num): float",
        "Converts radians to degrees as `$num * 180 / PI`.",
        "echo rad2deg(0);   // => 0",
    ),
    (
        "hypot",
        "Math",
        "hypot(float $x, float $y): float",
        "The Euclidean length `sqrt($x**2 + $y**2)`, computed without intermediate overflow.",
        "echo hypot(3, 4);   // => 5",
    ),
    (
        "fdiv",
        "Math",
        "fdiv(float $num1, float $num2): float",
        "Plain IEEE-754 division with no zero check, so a zero divisor yields `INF`, `-INF`, or `NAN` rather than aborting the way `/` does.",
        "echo fdiv(1, 0);   // => INF",
    ),
    (
        "is_nan",
        "Math",
        "is_nan(float $num): bool",
        "True when the float cast of the argument is IEEE not-a-number.",
        "var_dump(is_nan(NAN));   // => bool(true)",
    ),
    (
        "is_finite",
        "Math",
        "is_finite(float $num): bool",
        "True when the value is neither infinite nor NAN.",
        "var_dump(is_finite(1.0));   // => bool(true)",
    ),
    (
        "is_infinite",
        "Math",
        "is_infinite(float $num): bool",
        "True for positive or negative infinity.",
        "var_dump(is_infinite(INF));   // => bool(true)",
    ),
    (
        "decbin",
        "Math",
        "decbin(int $num): string",
        "The binary rendering of an integer. DIVERGENCE: PHP treats the value as unsigned 64-bit, so a negative argument gives PHP's two's-complement bit string; here it gives a leading `-` followed by the magnitude.",
        "echo decbin(5);   // => 101",
    ),
    (
        "decoct",
        "Math",
        "decoct(int $num): string",
        "The octal rendering of an integer, with the same negative-number divergence as `decbin`.",
        "echo decoct(8);   // => 10",
    ),
    (
        "bindec",
        "Math",
        "bindec(string $binary_string): int|float",
        "Parses a base-2 string, dropping a leading `0b`/`0B` and skipping any character that is not a binary digit — skipping any raises `Deprecated: Invalid characters passed for attempted conversion, these have been ignored`. The result is an integer when it fits `PHP_INT_MAX` and a float otherwise; accumulation saturates rather than wrapping.",
        "echo bindec(\"101\");   // => 5",
    ),
    (
        "octdec",
        "Math",
        "octdec(string $octal_string): int|float",
        "Parses a base-8 string, dropping a leading `0o`/`0O` and skipping invalid digits (which raises the same `Invalid characters passed for attempted conversion` deprecation as `bindec`), with the same integer-or-float result rule.",
        "echo octdec(\"10\");   // => 8",
    ),
    (
        "base_convert",
        "Math",
        "base_convert(string $num, int $from_base, int $to_base): string",
        "Re-renders a number from one base to another with lowercase digits, silently dropping invalid digits. A base outside `2..36` is an error. Accumulation is 128-bit and saturating, so enormous values clamp instead of wrapping.",
        "echo base_convert(\"ff\", 16, 2);   // => 11111111",
    ),
    (
        "mt_getrandmax",
        "Math",
        "mt_getrandmax(): int",
        "Returns the constant 2147483647, the largest value `mt_rand()` produces with no arguments.",
        "echo mt_getrandmax();   // => 2147483647",
    ),
    (
        "getrandmax",
        "Math",
        "getrandmax(): int",
        "Returns the same constant 2147483647 for `rand()`.",
        "echo getrandmax();   // => 2147483647",
    ),
    (
        "srand",
        "Math",
        "srand(?int $seed = null): void",
        "Reseeds the shared generator, or reseeds from clock and counter entropy when called with no argument. DIVERGENCE: the generator is SplitMix64, not PHP's libc or Mt19937, so a given seed does not reproduce PHP's sequence — and `srand` and `mt_srand` share one generator.",
        "",
    ),
    (
        "mt_srand",
        "Math",
        "mt_srand(?int $seed = null, int $mode = MT_RAND_MT19937): void",
        "Shares the `srand` arm and therefore the same SplitMix64 state. The `$mode` argument is accepted and ignored.",
        "",
    ),
    (
        "rand",
        "Math",
        "rand(int $min = 0, int $max = 2147483647): int",
        "A value in the inclusive range. Inverted bounds are swapped rather than raising. DIVERGENCE: SplitMix64 rather than PHP's generator, and the modulo range mapping is slightly biased for spans that do not divide evenly into 2^64.",
        "",
    ),
    (
        "mt_rand",
        "Math",
        "mt_rand(int $min = 0, int $max = 2147483647): int",
        "The same generator and range mapping as `rand`, except that `$min > $max` raises `Argument #2 ($max) must be greater than or equal to argument #1 ($min)`. It is NOT Mt19937.",
        "",
    ),
    (
        "random_int",
        "Math",
        "random_int(int $min, int $max): int",
        "Draws fresh bits rather than using the seeded generator, and raises when `$min > $max`. DIVERGENCE: NOT cryptographically secure — the bits come from clock nanoseconds XOR an atomic counter, mixed with SplitMix64. Do not use it for keys, tokens, or salts.",
        "",
    ),
    // ══ Arbitrary precision — bcmath (stdlib::bcmath) ═══════════════════════
    (
        "bcadd",
        "Arbitrary precision — bcmath",
        "bcadd(string $num1, string $num2, ?int $scale = null): string",
        "Exact arbitrary-precision decimal addition. The result is truncated toward zero to `$scale` fractional digits and rendered with exactly that many. `$scale` defaults to the `bcscale()` value and is clamped to `0..1048576`. An unparseable operand reads as `0` rather than raising PHP 8's `ValueError`.",
        "echo bcadd(\"1.234\", \"5\", 2);   // => 6.23",
    ),
    (
        "bcsub",
        "Arbitrary precision — bcmath",
        "bcsub(string $num1, string $num2, ?int $scale = null): string",
        "Exact decimal subtraction, with the same truncation, clamping, and lenient operand parsing as `bcadd`.",
        "echo bcsub(\"5\", \"1.234\", 2);   // => 3.76",
    ),
    (
        "bcmul",
        "Arbitrary precision — bcmath",
        "bcmul(string $num1, string $num2, ?int $scale = null): string",
        "Exact decimal multiplication, truncated toward zero to `$scale` fractional digits and padded to exactly that many.",
        "echo bcmul(\"2\", \"3\");   // => 6",
    ),
    (
        "bcdiv",
        "Arbitrary precision — bcmath",
        "bcdiv(string $num1, string $num2, ?int $scale = null): string",
        "Decimal division; a zero divisor throws `DivisionByZeroError: Division by zero`. DIVERGENCE: the quotient is computed at a 100-significant-digit context before truncation, so this is BOUNDED precision — a `$scale` needing more than about 100 significant digits is not reliable.",
        "echo bcdiv(\"10\", \"3\", 4);   // => 3.3333",
    ),
    (
        "bcmod",
        "Arbitrary precision — bcmath",
        "bcmod(string $num1, string $num2, ?int $scale = null): string",
        "The remainder `a - b * trunc(a / b)`, following PHP 7.2+ semantics. A zero divisor throws `DivisionByZeroError: Modulo by zero`. The intermediate division inherits the same bounded context as `bcdiv`.",
        "echo bcmod(\"10\", \"3\");   // => 1",
    ),
    (
        "bcpow",
        "Arbitrary precision — bcmath",
        "bcpow(string $num, string $exponent, ?int $scale = null): string",
        "Exponentiation by squaring on exact decimals. DIVERGENCE: a fractional exponent is silently truncated toward zero instead of raising PHP 8's `ValueError`, and an exponent beyond the 64-bit range saturates. A negative exponent yields the reciprocal, and zero to a negative power throws `DivisionByZeroError: Negative power of zero`.",
        "echo bcpow(\"2\", \"10\");   // => 1024",
    ),
    (
        "bcsqrt",
        "Arbitrary precision — bcmath",
        "bcsqrt(string $num, ?int $scale = null): string",
        "The square root truncated to `$scale` fractional digits. A negative operand throws `ValueError: bcsqrt(): Argument #1 ($num) must be greater than or equal to 0`. DIVERGENCE: computed at the same bounded 100-significant-digit context as `bcdiv`.",
        "echo bcsqrt(\"2\", 4);   // => 1.4142",
    ),
    (
        "bccomp",
        "Arbitrary precision — bcmath",
        "bccomp(string $num1, string $num2, ?int $scale = null): int",
        "Truncates both operands to `$scale` fractional digits and compares them, returning `-1`, `0`, or `1`. `$scale` defaults to the `bcscale()` value.",
        "echo bccomp(\"1.001\", \"1\", 2);   // => 0",
    ),
    (
        "bcscale",
        "Arbitrary precision — bcmath",
        "bcscale(?int $scale = null): int",
        "With no argument returns the current default scale; with one it sets the scale to `max(0, $scale)` and returns the PREVIOUS value. The scale is per-thread state, mirroring PHP's per-request scale.",
        "bcscale(3); echo bcadd(\"1\", \"2\");   // => 3.000",
    ),
    (
        "bcpowmod",
        "Arbitrary precision — bcmath",
        "bcpowmod(string $num, string $exponent, string $modulus, ?int $scale = null): string",
        "Modular exponentiation at TRUE arbitrary precision — all three operands are truncated to integers and a big-integer `modpow` does the work. A zero modulus throws `DivisionByZeroError: Modulo by zero`; a negative exponent throws `ValueError: bcpowmod(): Argument #2 ($exponent) must be greater than or equal to 0`. Because the result is an integer, `$scale` only controls how many trailing zero digits are appended.",
        "echo bcpowmod(\"4\", \"13\", \"497\");   // => 445",
    ),
    // ══ Arbitrary precision — GMP (stdlib::gmp) ═════════════════════════════
    // Every function here takes and returns DECIMAL STRINGS, not GMP objects:
    // phplang has no GMP resource type, and because a returned string is a valid
    // operand, calls still chain normally.
    (
        "gmp_init",
        "Arbitrary precision — GMP",
        "gmp_init(string|int $num, int $base = 0): string",
        "Parses the operand and returns its decimal representation as a plain STRING, not a GMP object. DIVERGENCE: `$base` is accepted and ignored — the parser auto-detects a `0x`/`0b` prefix and otherwise assumes decimal, yielding `0` for anything unparseable.",
        "echo gmp_init(\"0xff\");   // => 255",
    ),
    (
        "gmp_add",
        "Arbitrary precision — GMP",
        "gmp_add(string|int $num1, string|int $num2): string",
        "True arbitrary-precision addition, returning the sum as a decimal string.",
        "echo gmp_add(\"123456789012345678901234567890\", \"1\");   // => 123456789012345678901234567891",
    ),
    (
        "gmp_sub",
        "Arbitrary precision — GMP",
        "gmp_sub(string|int $num1, string|int $num2): string",
        "Arbitrary-precision subtraction as a decimal string.",
        "echo gmp_sub(\"100\", \"1\");   // => 99",
    ),
    (
        "gmp_mul",
        "Arbitrary precision — GMP",
        "gmp_mul(string|int $num1, string|int $num2): string",
        "Arbitrary-precision multiplication as a decimal string.",
        "echo gmp_mul(\"99999999999\", \"99999999999\");   // => 9999999999800000000001",
    ),
    (
        "gmp_div_q",
        "Arbitrary precision — GMP",
        "gmp_div_q(string|int $num1, string|int $num2, int $rounding_mode = GMP_ROUND_ZERO): string",
        "Integer quotient truncated toward zero; a zero divisor throws `DivisionByZeroError: gmp_div_q(): Argument #2 ($num2) Division by zero`. DIVERGENCE: `$rounding_mode` is accepted and ignored — only truncation is implemented.",
        "echo gmp_div_q(\"10\", \"3\");   // => 3",
    ),
    (
        "gmp_div",
        "Arbitrary precision — GMP",
        "gmp_div(string|int $num1, string|int $num2, int $rounding_mode = GMP_ROUND_ZERO): string",
        "Shares the `gmp_div_q` arm, so its zero-divisor message still reads `gmp_div_q(): Division by zero` and `$rounding_mode` is ignored.",
        "",
    ),
    (
        "gmp_div_r",
        "Arbitrary precision — GMP",
        "gmp_div_r(string|int $num1, string|int $num2, int $rounding_mode = GMP_ROUND_ZERO): string",
        "DIVERGENCE: it shares the `gmp_mod` arm, so it returns the SIGN-OF-DIVISOR remainder — for a positive modulus the result lies in `[0, |m|)` — not the truncating remainder PHP's `gmp_div_r` gives for a negative dividend.",
        "",
    ),
    (
        "gmp_mod",
        "Arbitrary precision — GMP",
        "gmp_mod(string|int $num1, string|int $num2): string",
        "A remainder whose sign follows the DIVISOR: the raw remainder has `|m|` added when it is negative, so a positive modulus always yields a result in `[0, |m|)`. A zero modulus throws `DivisionByZeroError: gmp_mod(): Argument #2 ($num2) Modulo by zero`.",
        "echo gmp_mod(\"-7\", \"3\");   // => 2",
    ),
    (
        "gmp_pow",
        "Arbitrary precision — GMP",
        "gmp_pow(string|int $num, int $exponent): string",
        "Arbitrary-precision exponentiation. DIVERGENCE: a negative exponent returns `\"0\"` instead of raising PHP's `ValueError`, and the exponent is narrowed to 32 bits, so values at or above 2^32 wrap silently.",
        "echo gmp_pow(\"2\", \"64\");   // => 18446744073709551616",
    ),
    (
        "gmp_powm",
        "Arbitrary precision — GMP",
        "gmp_powm(string|int $num, string|int $exponent, string|int $modulus): string",
        "Modular exponentiation at true arbitrary precision. A zero modulus throws `DivisionByZeroError: Modulo by zero` and a negative exponent raises `Negative exponent not supported`.",
        "echo gmp_powm(\"4\", \"13\", \"497\");   // => 445",
    ),
    (
        "gmp_gcd",
        "Arbitrary precision — GMP",
        "gmp_gcd(string|int $num1, string|int $num2): string",
        "The greatest common divisor by the Euclidean algorithm on absolute values, so the result is never negative.",
        "echo gmp_gcd(\"12\", \"18\");   // => 6",
    ),
    (
        "gmp_lcm",
        "Arbitrary precision — GMP",
        "gmp_lcm(string|int $num1, string|int $num2): string",
        "The least common multiple, computed as `|a / gcd(a,b) * b|`. It returns `\"0\"` when either operand is zero.",
        "echo gmp_lcm(\"4\", \"6\");   // => 12",
    ),
    (
        "gmp_abs",
        "Arbitrary precision — GMP",
        "gmp_abs(string|int $num): string",
        "The absolute value as a decimal string.",
        "echo gmp_abs(\"-42\");   // => 42",
    ),
    (
        "gmp_neg",
        "Arbitrary precision — GMP",
        "gmp_neg(string|int $num): string",
        "Arithmetic negation as a decimal string.",
        "echo gmp_neg(\"42\");   // => -42",
    ),
    (
        "gmp_and",
        "Arbitrary precision — GMP",
        "gmp_and(string|int $num1, string|int $num2): string",
        "Bitwise AND of the two big integers, using two's-complement semantics.",
        "echo gmp_and(\"6\", \"3\");   // => 2",
    ),
    (
        "gmp_or",
        "Arbitrary precision — GMP",
        "gmp_or(string|int $num1, string|int $num2): string",
        "Bitwise OR of the two big integers.",
        "echo gmp_or(\"6\", \"3\");   // => 7",
    ),
    (
        "gmp_xor",
        "Arbitrary precision — GMP",
        "gmp_xor(string|int $num1, string|int $num2): string",
        "Bitwise XOR of the two big integers.",
        "echo gmp_xor(\"6\", \"3\");   // => 5",
    ),
    (
        "gmp_cmp",
        "Arbitrary precision — GMP",
        "gmp_cmp(string|int $num1, string|int $num2): int",
        "Compares the two big integers and returns `-1`, `0`, or `1` as a plain PHP int.",
        "echo gmp_cmp(\"10\", \"9\");   // => 1",
    ),
    (
        "gmp_sign",
        "Arbitrary precision — GMP",
        "gmp_sign(string|int $num): int",
        "The sign of the value: `-1`, `0`, or `1`.",
        "echo gmp_sign(\"-5\");   // => -1",
    ),
    (
        "gmp_sqrt",
        "Arbitrary precision — GMP",
        "gmp_sqrt(string|int $num): string",
        "The integer (floor) square root. There is no negative-input guard, so behaviour for a negative operand is whatever the underlying big-integer library does.",
        "echo gmp_sqrt(\"17\");   // => 4",
    ),
    (
        "gmp_root",
        "Arbitrary precision — GMP",
        "gmp_root(string|int $num, int $nth): string",
        "The integer (floor) nth root. `$nth` is clamped to at least 1, and `$nth == 2` takes the dedicated square-root path while every other value uses a binary search. `$nth` is narrowed to 32 bits.",
        "echo gmp_root(\"27\", 3);   // => 3",
    ),
    (
        "gmp_fact",
        "Arbitrary precision — GMP",
        "gmp_fact(int $num): string",
        "The factorial, computed as a plain iterative big-integer product. A negative argument is clamped to 0, returning `\"1\"`, rather than raising. The running time is linear in `$num`.",
        "echo gmp_fact(20);   // => 2432902008176640000",
    ),
    (
        "gmp_pow2",
        "Arbitrary precision — GMP",
        "gmp_pow2(int $exponent): string",
        "Two raised to the given power, with a negative exponent clamped to 0. DIVERGENCE: reference PHP's GMP extension has NO `gmp_pow2()` — this function exists only in phplang. The exponent is narrowed to 32 bits.",
        "echo gmp_pow2(10);   // => 1024",
    ),
    (
        "gmp_strval",
        "Arbitrary precision — GMP",
        "gmp_strval(string|int $num, int $base = 10): string",
        "Renders the value in the requested base. DIVERGENCE: only bases 16, 2, and 8 are special-cased — every other base, including PHP-supported ones such as 36, silently falls through to decimal instead of raising.",
        "echo gmp_strval(\"255\", 16);   // => ff",
    ),
    (
        "gmp_intval",
        "Arbitrary precision — GMP",
        "gmp_intval(string|int $num): int",
        "Converts to a PHP int. DIVERGENCE: a value too large SATURATES to `PHP_INT_MAX` or `PHP_INT_MIN` rather than wrapping or truncating as PHP does.",
        "echo gmp_intval(\"42\");   // => 42",
    ),
    (
        "gmp_prob_prime",
        "Arbitrary precision — GMP",
        "gmp_prob_prime(string|int $num, int $repetitions = 10): int",
        "Returns 0 for composite, 1 for probably prime, and 2 for definitely prime. It trial-divides by odd divisors up to `min(sqrt(n), 100000)` — reporting 2 when that fully covers the root — then runs Miller-Rabin with the FIXED bases 2, 3, 5, 7, 11, 13, 17. DIVERGENCE: `$repetitions` is accepted and ignored, so the error bound is not tunable.",
        "echo gmp_prob_prime(\"97\");   // => 2",
    ),
    (
        "gmp_perfect_square",
        "Arbitrary precision — GMP",
        "gmp_perfect_square(string|int $num): bool",
        "True when the value is non-negative and its integer square root squared equals it.",
        "var_dump(gmp_perfect_square(\"16\"));   // => bool(true)",
    ),
    // ══ Character classes (stdlib::ctype) ═══════════════════════════════════
    // Every function here shares one argument rule: a STRING passes only when it
    // is non-empty and every BYTE satisfies the class (so the empty string is
    // always false); an INT in -128..255 is treated as a single character code
    // (negatives get +256); any other int is classified as its decimal string;
    // any other value type is false. A byte at or above 0x80 satisfies no class.
    (
        "ctype_alpha",
        "Character classes",
        "ctype_alpha(mixed $text): bool",
        "True when every byte is an ASCII letter.",
        "var_dump(ctype_alpha(\"abc\"), ctype_alpha(\"ab1\"));   // => bool(true) bool(false)",
    ),
    (
        "ctype_digit",
        "Character classes",
        "ctype_digit(mixed $text): bool",
        "True when every byte is an ASCII digit `0`-`9`.",
        "var_dump(ctype_digit(\"123\"));   // => bool(true)",
    ),
    (
        "ctype_alnum",
        "Character classes",
        "ctype_alnum(mixed $text): bool",
        "True when every byte is an ASCII letter or digit.",
        "var_dump(ctype_alnum(\"a1\"));   // => bool(true)",
    ),
    (
        "ctype_space",
        "Character classes",
        "ctype_space(mixed $text): bool",
        "True when every byte is space, tab, newline, vertical tab, form feed, or carriage return — matching C's `isspace`, deliberately including the vertical tab that Rust's own ASCII-whitespace test omits.",
        "var_dump(ctype_space(\" \\t\\n\"));   // => bool(true)",
    ),
    (
        "ctype_upper",
        "Character classes",
        "ctype_upper(mixed $text): bool",
        "True when every byte is an ASCII uppercase letter.",
        "var_dump(ctype_upper(\"ABC\"));   // => bool(true)",
    ),
    (
        "ctype_lower",
        "Character classes",
        "ctype_lower(mixed $text): bool",
        "True when every byte is an ASCII lowercase letter.",
        "var_dump(ctype_lower(\"abc\"));   // => bool(true)",
    ),
    (
        "ctype_punct",
        "Character classes",
        "ctype_punct(mixed $text): bool",
        "True when every byte is printable ASCII punctuation — graphic and not alphanumeric.",
        "var_dump(ctype_punct(\"!?\"));   // => bool(true)",
    ),
    (
        "ctype_xdigit",
        "Character classes",
        "ctype_xdigit(mixed $text): bool",
        "True when every byte is a hexadecimal digit in either case.",
        "var_dump(ctype_xdigit(\"1aF\"));   // => bool(true)",
    ),
    (
        "ctype_cntrl",
        "Character classes",
        "ctype_cntrl(mixed $text): bool",
        "True when every byte is an ASCII control character — 0x00-0x1F or 0x7F.",
        "var_dump(ctype_cntrl(\"\\n\"));   // => bool(true)",
    ),
    (
        "ctype_graph",
        "Character classes",
        "ctype_graph(mixed $text): bool",
        "True when every byte is printable and not a space — 0x21-0x7E.",
        "var_dump(ctype_graph(\"a!\"), ctype_graph(\"a \"));   // => bool(true) bool(false)",
    ),
    (
        "ctype_print",
        "Character classes",
        "ctype_print(mixed $text): bool",
        "True when every byte is printable, space included — 0x20-0x7E.",
        "var_dump(ctype_print(\"a \"));   // => bool(true)",
    ),
    // ══ Types and serialization (stdlib::types) ═════════════════════════════
    (
        "is_scalar",
        "Types and serialization",
        "is_scalar(mixed $value): bool",
        "True only for an int, float, string, or bool. Null, arrays, objects, and closures are all false, matching PHP.",
        "var_dump(is_scalar(1), is_scalar([]));   // => bool(true) bool(false)",
    ),
    (
        "is_object",
        "Types and serialization",
        "is_object(mixed $value): bool",
        "True for an object OR a closure; arrays are excluded. DIVERGENCE: PHP also reports true for a closure, so this matches — but note phplang arrays and objects share one handle representation, and the distinction is asked of the host.",
        "var_dump(is_object(new stdClass), is_object([]));   // => bool(true) bool(false)",
    ),
    (
        "is_iterable",
        "Types and serialization",
        "is_iterable(mixed $value): bool",
        "True only for an array. DIVERGENCE: no object is ever iterable here, because the runtime has no `Traversable` or `Iterator` interface.",
        "var_dump(is_iterable([1]), is_iterable(new stdClass));   // => bool(true) bool(false)",
    ),
    (
        "is_countable",
        "Types and serialization",
        "is_countable(mixed $value): bool",
        "Shares the `is_iterable` arm, so it is true only for an array. DIVERGENCE: there is no `Countable` interface to honour.",
        "var_dump(is_countable([1]));   // => bool(true)",
    ),
    (
        "get_debug_type",
        "Types and serialization",
        "get_debug_type(mixed $value): string",
        "The modern short type name: `null`, `bool`, `int`, `float`, `string`, `array`, `Closure`, or the class name. Use `gettype()` for PHP's legacy long names.",
        "echo get_debug_type(1.5), \"|\", get_debug_type(null);   // => float|null",
    ),
    (
        "serialize",
        "Types and serialization",
        "serialize(mixed $value): string",
        "Emits PHP's serialization format using `serialize_precision=-1` float rules: `a:` for arrays, `O:` for objects (with the engine's NUL-mangled visibility keys), `E:` for enum cases. DIVERGENCE: a structure that contains ITSELF is written as `N;` at the repeat, where the reference emits an `r:`/`R:` back-reference — the output stays finite and valid but no longer round-trips a cycle.",
        "echo serialize([1, \"a\"]);   // => a:2:{i:0;i:1;i:1;s:1:\"a\";}",
    ),
    (
        "unserialize",
        "Types and serialization",
        "unserialize(string $data): mixed",
        "Parses the `N b i d s a` tags and returns `false` on malformed input, trailing bytes, or a negative array count. DIVERGENCE: object (`O:`/`C:`/`E:`) and reference (`R:`/`r:`) records are unsupported, an oversized `i:` saturates rather than failing, and the `$options` argument is not read.",
        "print_r(unserialize('a:1:{i:0;i:5;}'));   // => Array\\n(\\n    [0] => 5\\n)",
    ),
    // ══ Regular expressions (stdlib::preg) ══════════════════════════════════
    // Backed by TWO engines, NOT PCRE: the Rust `regex` crate first, and
    // `fancy-regex` for the patterns it will not take — look-around,
    // backreferences, atomic groups, possessive quantifiers. A pattern on the
    // second engine matches as if `/u` were set (it works over `&str`), and
    // pattern RECURSION exists on neither. Matching is otherwise on BYTES unless
    // the `u` modifier is given, so `.` is one byte and every reported offset is
    // a byte offset. A named group is published in `$matches` under its name and
    // its index both, the name first. Delimiters: any
    // non-alphanumeric, non-backslash character, with `()`, `{}`, `[]`, and `<>`
    // matched as pairs and NESTED (so `{a{b}` is unterminated). The closing
    // delimiter is found by scanning FORWARD honouring backslash escapes, so
    // `/a\\//` has the body `a\\/`.
    //
    // Modifiers: the accepted set is `imnrsuxADJSUX`, matching the reference;
    // any other letter is `Unknown modifier '<c>'`. Of those, `i m s x U u` are
    // implemented, `n` (no auto-capture) is applied by rewriting each capturing
    // group, and `A` (anchored) is applied per search: the engine has no
    // anchored flag, but it is leftmost-first, so a search from `pos` returns
    // the match starting at `pos` when one exists. `A` retries at each
    // successive offset and stops at the first failure, so
    // `preg_match_all("/a/A", "aab")` is 2 while `"bab"` is 0.
    // DIVERGENCE: `D J S X r` are accepted as NO-OPS. Only `D` is observable,
    // and inversely — both engines' `$` is already end-of-haystack only, so
    // `/a$/D` is right by accident and the unmodified `/a$/` is what differs:
    // `preg_match("/a$/", "a\n")` is 1 in the reference and 0 here.
    //
    // A pattern the engine rejects is a `Warning` naming the calling function and
    // the function's error sentinel — NOT an exception — and leaves
    // `preg_last_error()` at `PREG_INTERNAL_ERROR`. The delimiter and modifier
    // faults are ported from `php_pcre.c`; five structural body faults are ported
    // from PCRE2 with the offsets the reference reports. A body that is malformed
    // in some OTHER way, or that uses a construct NEITHER engine has (pattern
    // recursion, a conditional group), still returns the sentinel but does so
    // SILENTLY, since the reference would have compiled most of them.
    (
        "preg_match",
        "Regular expressions",
        "preg_match(string $pattern, string $subject, array &$matches = [], int $flags = 0, int $offset = 0): int|false",
        "Returns 1 on a match, 0 on none, or `false` for a pattern that will not compile — which also raises `Warning: preg_match(): <reason>` and leaves `preg_last_error()` at `PREG_INTERNAL_ERROR`. `$matches` is a real by-reference out-parameter and is written whether or not the caller initialised it. `PREG_OFFSET_CAPTURE` and `PREG_UNMATCHED_AS_NULL` are both honoured. `$offset` moves where the SEARCH starts without slicing the subject, so `^` still anchors to the real start and reported offsets are measured from it.",
        "preg_match(\"/(\\d+)/\", \"ab 42\", $m); echo $m[1];   // => 42",
    ),
    (
        "preg_match_all",
        "Regular expressions",
        "preg_match_all(string $pattern, string $subject, array &$matches = [], int $flags = PREG_PATTERN_ORDER, int $offset = 0): int|false",
        "Returns the number of matches, or `false` for a pattern that will not compile, with the same `Warning` and `preg_last_error()` state as `preg_match`. `$matches` is a real by-reference out-parameter, keyed by group name as well as index. `PREG_SET_ORDER` truncates each set at its own last participating group, so its rows are ragged where `PREG_PATTERN_ORDER`'s columns are full width. `PREG_OFFSET_CAPTURE` and `PREG_UNMATCHED_AS_NULL` are honoured alongside the order bit, and `$offset` moves where the search starts without slicing the subject.",
        "$m = []; echo preg_match_all(\"/\\d/\", \"a1b2\", $m), $m[0][1];   // => 22",
    ),
    (
        "preg_replace",
        "Regular expressions",
        "preg_replace(string|array $pattern, string|array $replacement, string|array $subject, int $limit = -1, int &$count = null): string|array|null",
        "Applies each pattern in turn. `$replacement` may be one string for every pattern or an array index-matched to the patterns (surplus patterns replace with `\"\"`). The `$1`, `${1}`, and `\\1` back-reference forms all work in the REPLACEMENT even though back-references in the pattern do not. The first pattern that will not compile ends the whole call at null, raising `Warning: preg_replace(): <reason>`; `&$count` receives the total number of replacements across every pattern, and is written even when that total is zero.",
        "echo preg_replace(\"/\\d+/\", \"#\", \"a1b22\");   // => a#b#",
    ),
    (
        "preg_replace_callback",
        "Regular expressions",
        "preg_replace_callback(string|array $pattern, callable $callback, string|array $subject, int $limit = -1, int &$count = null, int $flags = 0): string|array|null",
        "Calls the callback for each match with a fully POPULATED `$matches` array. `$limit` is honoured, and a pattern that will not compile returns null after raising `Warning: preg_replace_callback(): <reason>`. `&$count` receives the number of replacements, and `$flags` takes `PREG_OFFSET_CAPTURE`/`PREG_UNMATCHED_AS_NULL`, which reshape the `$matches` the callback receives.",
        "echo preg_replace_callback(\"/\\d/\", fn($m) => $m[0] * 2, \"a1b2\");   // => a2b4",
    ),
    (
        "preg_split",
        "Regular expressions",
        "preg_split(string $pattern, string $subject, int $limit = -1, int $flags = 0): array|false",
        "Splits on each match. All three flag bits are honoured: `PREG_SPLIT_NO_EMPTY`, `PREG_SPLIT_DELIM_CAPTURE`, and `PREG_SPLIT_OFFSET_CAPTURE`. A zero-width match sitting right after a non-empty one is emitted, as PCRE does, so `/x*/` and `/\\d*/` split the way the reference splits them. The captured delimiters `PREG_SPLIT_DELIM_CAPTURE` interleaves are positional — unlike `$matches`, they are not keyed by group name.",
        "echo implode(\"-\", preg_split(\"/[\\s,]+/\", \"a, b  c\"));   // => a-b-c",
    ),
    (
        "preg_quote",
        "Regular expressions",
        "preg_quote(string $str, ?string $delimiter = null): string",
        "Backslash-escapes the PCRE special set `.\\+*?[^]$(){}=!<>|:-#`, plus the first character of `$delimiter` when supplied. A NUL byte becomes the four-character sequence `\\000`. It compiles nothing, so it never touches `preg_last_error()`.",
        "echo preg_quote(\"1+1\");   // => 1\\+1",
    ),
    (
        "preg_grep",
        "Regular expressions",
        "preg_grep(string $pattern, array $array, int $flags = 0): array|false",
        "The entries whose string value matches the pattern, PRESERVING keys. The `PREG_GREP_INVERT` bit inverts the test. A non-array subject yields an empty array rather than raising.",
        "echo implode(\",\", preg_grep(\"/^a/\", [\"apple\", \"pear\"]));   // => apple",
    ),
    (
        "preg_last_error",
        "Regular expressions",
        "preg_last_error(): int",
        "The outcome of the last `preg_*` call that reached the regex compiler: `PREG_INTERNAL_ERROR` (1) after a pattern the engine rejected, `PREG_NO_ERROR` (0) after one it accepted. The state is STICKY and cleared only by another compile — reading it does not clear it, and `preg_quote()` does not touch it — so a pattern that compiles resets it even when the match then finds nothing. DIVERGENCE: only these two codes are produced; the reference also reports backtrack- and recursion-limit exhaustion, which this engine has no equivalent of.",
        "@preg_match(\"/[a\", \"x\"); echo preg_last_error();   // => 1",
    ),
    (
        "preg_last_error_msg",
        "Regular expressions",
        "preg_last_error_msg(): string",
        "The message for the `preg_last_error()` code, and like it a pure reader that clears nothing. `\"No error\"` or `\"Internal error\"` in practice, the two codes this engine produces.",
        "@preg_match(\"/[a\", \"x\"); echo preg_last_error_msg();   // => Internal error",
    ),
    // ══ JSON (stdlib::json) ═════════════════════════════════════════════════
    (
        "json_decode",
        "JSON",
        "json_decode(string $json, ?bool $associative = null, int $depth = 512, int $flags = 0): mixed",
        "A hand-written recursive-descent parser over the raw bytes. A JSON array always decodes to a PHP array; a JSON object decodes to a `stdClass` unless `$associative` is truthy, or it is left null and `$flags` carries `JSON_OBJECT_AS_ARRAY`. Objects take their creation-order handles where `ext/json` allocates them — as each object's first member closes — so `json_decode('{\"a\":{\"b\":1}}')` numbers the inner `#1` and the outer `#2`. `$depth` is honoured and RANGE-CHECKED: below 1 raises `ValueError: json_decode(): Argument #3 ($depth) must be greater than 0` and past `INT_MAX` raises `… must be less than 2147483647`. `JSON_THROW_ON_ERROR` is honoured; other `$flags` are ignored. Integral numbers become ints; anything with a `.`/`e` or beyond the 64-bit range becomes a float. Any other failure returns null and records the code for `json_last_error()`. DIVERGENCE: the parser recurses on the native stack, so nesting deeper than 1024 reports `JSON_ERROR_DEPTH` whatever `$depth` asked for.",
        "echo json_decode('{\"a\":1}')->a;   // => 1",
    ),
    (
        "json_validate",
        "JSON",
        "json_validate(string $json, int $depth = 512, int $flags = 0): bool",
        "Runs the same grammar without allocating any array and returns whether the input is well-formed, setting `json_last_error()` either way. `$depth` follows the same default-512, clamp-to-1 rule; `$flags` is ignored.",
        "var_dump(json_validate('{\"a\":1}'), json_validate('{'));   // => bool(true) bool(false)",
    ),
    (
        "json_last_error",
        "JSON",
        "json_last_error(): int",
        "The `JSON_ERROR_*` code from the last decode or validation. DIVERGENCE: PHP keeps this per request; here it is thread-local state that lives for the thread's lifetime, and `json_encode()` never touches it.",
        "json_decode(\"{\"); echo json_last_error();   // => 4",
    ),
    (
        "json_last_error_msg",
        "JSON",
        "json_last_error_msg(): string",
        "The message matching `json_last_error()`, using PHP's own wording — `No error`, `Maximum stack depth exceeded`, `State mismatch (invalid or malformed JSON)`, `Control character error, possibly incorrectly encoded`, `Syntax error`, `Malformed UTF-8 characters, possibly incorrectly encoded`, or `Single unpaired UTF-16 surrogate in unicode escape`.",
        "json_decode(\"{\"); echo json_last_error_msg();   // => Syntax error",
    ),
    // ══ Encoding (stdlib::encoding) ═════════════════════════════════════════
    // These functions decode to one Latin-1 CHARACTER per byte, because a
    // phplang string is always valid UTF-8 and cannot hold a raw byte at or above
    // 0x80. ASCII payloads round-trip exactly; binary payloads do not, and
    // `strlen()` of such a result exceeds the true byte count.
    (
        "base64_encode",
        "Encoding",
        "base64_encode(string $string): string",
        "Standard padded base64 with the `+`/`/` alphabet, over the UTF-8 bytes of the argument.",
        "echo base64_encode(\"abc\");   // => YWJj",
    ),
    (
        "base64_decode",
        "Encoding",
        "base64_decode(string $string, bool $strict = false): string|false",
        "A faithful port of PHP's own decoder, including its reverse table which skips tab, newline, carriage return, and space. `$strict` is honoured and rejects an invalid character, data after padding, a truncated final group, and wrong padding length. Non-strict mode silently skips unrecognized bytes.",
        "echo base64_decode(\"YWJj\");   // => abc",
    ),
    (
        "hex2bin",
        "Encoding",
        "hex2bin(string $string): string|false",
        "Decodes a hex string to bytes, returning `false` on an odd length or a non-hex character. The counterpart `bin2hex` lives in the core library, not this module.",
        "echo hex2bin(\"616263\");   // => abc",
    ),
    (
        "quoted_printable_encode",
        "Encoding",
        "quoted_printable_encode(string $string): string",
        "A port of PHP's encoder: soft-wraps at 75 columns with `=` and CRLF, and emits `=XX` in uppercase hex for control bytes, 0x7F, high bytes, `=` itself, and a space directly before a carriage return.",
        "echo quoted_printable_encode(\"a=b\");   // => a=3Db",
    ),
    (
        "quoted_printable_decode",
        "Encoding",
        "quoted_printable_decode(string $string): string",
        "Decodes `=XX` sequences, removes soft line breaks, drops a trailing bare `=`, and passes any other malformed `=` through verbatim — matching PHP.",
        "echo quoted_printable_decode(\"a=3Db\");   // => a=b",
    ),
    (
        "convert_uuencode",
        "Encoding",
        "convert_uuencode(string $string): string",
        "A port of PHP's uuencoder: 45-byte lines each prefixed by an encoded length character, three bytes to four printable characters, sextet zero mapped to a backtick, and a backtick-plus-newline trailer.",
        "echo trim(convert_uudecode(convert_uuencode(\"abc\")));   // => abc",
    ),
    (
        "convert_uudecode",
        "Encoding",
        "convert_uudecode(string $string): string|false",
        "A port of PHP's uudecoder including its sanity checks: `false` for empty input, a declared line length larger than the buffer, an overrunning encoded span, or nothing decoded. A zero-length (backtick) line terminates.",
        "",
    ),
    (
        "utf8_encode",
        "Encoding",
        "utf8_encode(string $string): string",
        "The deprecated Latin-1 to UTF-8 shim: each BYTE is widened to the codepoint of the same value. Exact for ASCII; already-multibyte input is widened byte by byte into mojibake, which is what real PHP does to the same byte sequence.",
        "echo utf8_encode(\"abc\");   // => abc",
    ),
    (
        "utf8_decode",
        "Encoding",
        "utf8_decode(string $string): string",
        "The deprecated UTF-8 to Latin-1 shim: each codepoint at or below U+00FF is narrowed to one byte and anything above becomes `?`. DIVERGENCE: the byte string is then re-widened one Latin-1 character per byte, so a Latin-1-representable argument round-trips to ITSELF rather than shrinking — `utf8_decode(\"é\")` is still `\"é\"` and `strlen()` of it is still 2. Only codepoints above U+00FF actually change.",
        "echo utf8_decode(\"héllo\"), \"|\", utf8_decode(\"€\");   // => héllo|?",
    ),
    // ══ URL (stdlib::url) ═══════════════════════════════════════════════════
    (
        "urlencode",
        "URL",
        "urlencode(string $string): string",
        "RFC 1738 percent-encoding over the string's bytes: letters, digits, `-`, `_`, and `.` pass through, a space becomes `+`, and everything else — the tilde included — becomes an uppercase `%XX`.",
        "echo urlencode(\"a b&c\");   // => a+b%26c",
    ),
    (
        "urldecode",
        "URL",
        "urldecode(string $string): string",
        "Decodes `%XX` escapes and maps `+` back to a space. A `%` not followed by two hex digits is emitted verbatim, matching PHP. Note a `%XX` sitting at the very END of the string is not decoded.",
        "echo urldecode(\"a+b%26c\");   // => a b&c",
    ),
    (
        "rawurlencode",
        "URL",
        "rawurlencode(string $string): string",
        "RFC 3986 percent-encoding: letters, digits, `-`, `_`, `.`, and `~` pass through (the tilde is preserved, unlike `urlencode`), and a space becomes `%20`.",
        "echo rawurlencode(\"a b~c\");   // => a%20b~c",
    ),
    (
        "rawurldecode",
        "URL",
        "rawurldecode(string $string): string",
        "The `urldecode` decoder with plus-to-space turned off, so `+` stays literal. It shares the same end-of-string `%XX` behaviour.",
        "echo rawurldecode(\"a%20b+c\");   // => a b+c",
    ),
    (
        "http_build_query",
        "URL",
        "http_build_query(array $data, string $numeric_prefix = \"\", ?string $arg_separator = \"&\", int $encoding_type = PHP_QUERY_RFC1738): string|false",
        "Serializes recursively to `k=v` pairs, url-encoding keys and values. All four arguments are honoured: `$numeric_prefix` is prepended to top-level integer keys, an explicit empty separator is respected, and `$encoding_type == 2` switches to `rawurlencode`. Nested arrays become `key[sub]` segments, null leaves are skipped, and booleans serialize as `1`/`0`. A non-array subject returns `false`.",
        "echo http_build_query([\"a\" => 1, \"b\" => 2]);   // => a=1&b=2",
    ),
    (
        "parse_url",
        "URL",
        "parse_url(string $url, int $component = -1): array|string|int|null|false",
        "A faithful port of PHP's own parser, so relative schemes, `mailto:`, bracketed IPv6 hosts, schemeless `host:port`, and the `file:///c:/` drive case all match reference PHP. Control bytes in each component are replaced with `_`. A non-negative `$component` selects one piece by its `PHP_URL_*` ordinal; ANY negative one asks for the whole array, and a positive one past `PHP_URL_FRAGMENT` raises `ValueError: parse_url(): Argument #2 ($component) must be a valid URL component identifier, N given` before the URL is even parsed. An out-of-range port, an empty host, or a bad authority returns `false`.",
        "echo parse_url(\"https://example.com/p?q=1\")[\"host\"];   // => example.com",
    ),
    (
        "parse_str",
        "URL",
        "parse_str(string $string): array",
        "Parses a query string into an array, handling `key[]` appends, `key[sub]` nesting, and PHP's mangling of interior `.` and space to `_` in top-level keys. DIVERGENCE: PHP writes into a by-reference second argument and returns void; phplang has no by-reference out-parameter, so this RETURNS the array instead — write `$r = parse_str($s);`.",
        "$r = parse_str(\"a=1&b=2\"); echo $r[\"a\"], $r[\"b\"];   // => 12",
    ),
    // ══ Hashing (stdlib::hash) ══════════════════════════════════════════════
    (
        "md5",
        "Hashing",
        "md5(string $string, bool $binary = false): string",
        "MD5 of the argument's UTF-8 bytes, as 32 lowercase hex characters. DIVERGENCE: `$binary` returns the digest mapped one Latin-1 character per byte, so `strlen()` of it is not 16 whenever a digest byte reaches 0x80.",
        "echo md5(\"abc\");   // => 900150983cd24fb0d6963f7d28e17f72",
    ),
    (
        "sha1",
        "Hashing",
        "sha1(string $string, bool $binary = false): string",
        "SHA-1 as 40 lowercase hex characters, with the same raw-output caveat as `md5` when `$binary` is truthy.",
        "echo sha1(\"abc\");   // => a9993e364706816aba3e25717850c26c9cd0d89d",
    ),
    (
        "crc32",
        "Hashing",
        "crc32(string $string): int",
        "The reflected CRC-32 (the zlib polynomial) as a PHP integer. No second argument is read.",
        "echo crc32(\"abc\");   // => 891568578",
    ),
    (
        "hash",
        "Hashing",
        "hash(string $algo, string $data, bool $binary = false): string",
        "Digests the data with one of exactly six algorithms: `md5`, `sha1`, `sha256`, `sha512`, `crc32b`, `crc32`. DIVERGENCE: `sha384` is NOT accepted here even though `hash_hmac`, `hash_file`, and `hash_pbkdf2` accept it. An unknown name throws `ValueError: hash(): Argument #1 ($algo) must be a valid hashing algorithm`. PHP 8.1's `$options` array does not exist.",
        "echo hash(\"sha256\", \"\");   // => e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
    ),
    (
        "hash_hmac",
        "Hashing",
        "hash_hmac(string $algo, string $data, string $key, bool $binary = false): string",
        "RFC 2104 HMAC over the same digests, with the block size paired per algorithm. Exactly five names are accepted — `md5`, `sha1`, `sha256`, `sha384`, `sha512` — so the CRC variants `hash()` allows are rejected. An unknown name throws `ValueError: hash_hmac(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm`. `$key` is `#[\\SensitiveParameter]`, so a backtrace prints it as `Object(SensitiveParameterValue)` rather than the key itself.",
        "echo strlen(hash_hmac(\"sha256\", \"m\", \"k\"));   // => 64",
    ),
    (
        "hash_algos",
        "Hashing",
        "hash_algos(): array",
        "The fixed six-element list `md5, sha1, sha256, sha512, crc32, crc32b`. DIVERGENCE: it is an accurate roster only for `hash()` — it omits `sha384`, which `hash_hmac`, `hash_file`, `hash_hmac_file`, and `hash_pbkdf2` all accept.",
        "echo count(hash_algos());   // => 6",
    ),
    // ══ Hashing — files and key derivation (stdlib::hashext) ════════════════
    (
        "md5_file",
        "Hashing — files and key derivation",
        "md5_file(string $filename, bool $binary = false): string|false",
        "MD5 of the file's RAW bytes read straight off disk, so unlike the string functions this is byte-faithful for binary files. Any I/O error returns `false` with no warning.",
        "",
    ),
    (
        "sha1_file",
        "Hashing — files and key derivation",
        "sha1_file(string $filename, bool $binary = false): string|false",
        "SHA-1 of the file's raw bytes, returning `false` on any I/O error.",
        "",
    ),
    (
        "hash_file",
        "Hashing — files and key derivation",
        "hash_file(string $algo, string $filename, bool $binary = false): string|false",
        "Validates the algorithm BEFORE touching the filesystem, matching PHP. Six names are accepted: `md5`, `sha1`, `sha256`, `sha384`, `sha512`, `crc32b` — a set that is neither a subset nor a superset of what `hash()` takes, since it adds `sha384` and drops the non-reflected `crc32`. An unreadable file returns `false`.",
        "",
    ),
    (
        "hash_hmac_file",
        "Hashing — files and key derivation",
        "hash_hmac_file(string $algo, string $filename, string $key, bool $binary = false): string|false",
        "HMACs the file's raw bytes under the key. The same five names as `hash_hmac` are accepted, validated before the read; an unreadable file returns `false`.",
        "",
    ),
    (
        "hash_equals",
        "Hashing — files and key derivation",
        "hash_equals(string $known_string, string $user_string): bool",
        "A timing-safe comparison: it returns false immediately on a length mismatch (length is not treated as secret, as in PHP) and otherwise ORs the per-byte XOR across the whole length, so the running time does not reveal where the first difference is.",
        "var_dump(hash_equals(\"abc\", \"abc\"));   // => bool(true)",
    ),
    (
        "hash_pbkdf2",
        "Hashing — files and key derivation",
        "hash_pbkdf2(string $algo, string $password, string $salt, int $iterations, int $length = 0, bool $binary = false): string",
        "PBKDF2 per RFC 2898 over the local HMAC, accepting `md5`, `sha1`, `sha256`, `sha384`, `sha512`. `$length` is the length of the OUTPUT STRING — derived bytes for binary output, hex characters otherwise — and 0 emits the full digest. Throws a `ValueError` on an unknown algorithm, non-positive iterations, or a negative length. `$password` is `#[\\SensitiveParameter]`, so a backtrace prints it as `Object(SensitiveParameterValue)`. DIVERGENCE: a length above 16777216 is refused (PHP instead attempts the allocation and dies on the memory limit).",
        "echo strlen(hash_pbkdf2(\"sha256\", \"p\", \"s\", 10, 20));   // => 20",
    ),
    (
        "random_bytes",
        "Hashing — files and key derivation",
        "random_bytes(int $length): string",
        "DIVERGENCE — NOT A CSPRNG. No OS-entropy dependency is available to this crate, so the bytes come from a SplitMix64 generator seeded from wall-clock nanoseconds XOR the process id. Use it for tests and filler only, never for keys, tokens, or salts. Output is the Latin-1 raw mapping, so `strlen()` exceeds `$length` whenever a generated byte reaches 0x80. A length below 1 throws `ValueError: random_bytes(): Argument #1 ($length) must be greater than 0`. DIVERGENCE: a length above 16 MiB is refused with a `ValueError` too (PHP instead attempts the allocation and dies on the memory limit).",
        "",
    ),
    // ══ Date and time (stdlib::datetime) ════════════════════════════════════
    // EVERYTHING in this module computes in UTC. There is no timezone database,
    // so `date()` and `gmdate()` are the same function and
    // `date_default_timezone_set()` shifts nothing.
    (
        "time",
        "Date and time",
        "time(): int",
        "The current Unix timestamp in whole seconds. Any arguments passed are ignored.",
        "var_dump(time() > 1700000000);   // => bool(true)",
    ),
    (
        "mktime",
        "Date and time",
        "mktime(int $hour = ?, int $minute = ?, int $second = ?, int $month = ?, int $day = ?, int $year = ?): int|false",
        "Builds a timestamp in UTC ONLY, with each omitted field defaulting to the corresponding component of the current UTC time. Out-of-range fields normalize (month 13 rolls to next January, day 0 to the previous month's last day), and two-digit years map 0-69 to 2000-2069 and 70-100 to 1970-2000. DIVERGENCE: an overflow returns `false` rather than a far-future timestamp.",
        "echo mktime(0, 0, 0, 1, 1, 1970);   // => 0",
    ),
    (
        "gmmktime",
        "Date and time",
        "gmmktime(int $hour = ?, int $minute = ?, int $second = ?, int $month = ?, int $day = ?, int $year = ?): int|false",
        "Shares the `mktime` arm and is therefore identical to it, because every computation in this module is already UTC.",
        "echo gmmktime(0, 0, 0, 1, 1, 1970);   // => 0",
    ),
    (
        "date",
        "Date and time",
        "date(string $format, int $timestamp = time()): string",
        "Formats in UTC regardless of `date_default_timezone_set()`. Handled format characters, exactly: `d j D l N w S z W F M m n t L Y y a A g G h H i s U o u v c r`; a backslash escapes the next character. Every OTHER character — including the timezone specifiers `e T O P p Z I` — is emitted LITERALLY. `u`/`v` always render zeros, `c` always ends `+00:00`, and `r` always ends `+0000`.",
        "echo date(\"Y-m-d H:i:s\", 0);   // => 1970-01-01 00:00:00",
    ),
    (
        "gmdate",
        "Date and time",
        "gmdate(string $format, int $timestamp = time()): string",
        "Shares the `date` arm — same UTC formatting, same exact set of supported format characters.",
        "echo gmdate(\"Y-m-d\", 0);   // => 1970-01-01",
    ),
    (
        "checkdate",
        "Date and time",
        "checkdate(int $month, int $day, int $year): bool",
        "True when the month is 1-12, the year is 1-32767, and the day is within that month under the proleptic Gregorian leap rule. Missing arguments read as 0 and therefore fail.",
        "var_dump(checkdate(2, 29, 2024), checkdate(2, 30, 2024));   // => bool(true) bool(false)",
    ),
    (
        "microtime",
        "Date and time",
        "microtime(bool $as_float = false): float|string",
        "With a truthy argument the timestamp as a float; otherwise the classic `\"0.12345678 1712345678\"` string with the fraction first.",
        "var_dump(microtime(true) > 0);   // => bool(true)",
    ),
    (
        "strtotime",
        "Date and time",
        "strtotime(string $datetime, int $baseTimestamp = time()): int|false",
        "Parses only this SUBSET, all in UTC: the keywords `now`, `today`, `midnight`, `yesterday`, `tomorrow`; `@<int>` for explicit Unix seconds; the absolute forms `YYYY-MM-DD HH:MM:SS` and `YYYY-MM-DD`; and chained relative tokens matching `[+-]N (sec|min|hour|day|week|month|year)[s] [ago]`. Anything else — a month name, a slashed date, `next monday`, a timezone suffix — returns `false`. Month and year arithmetic uses PHP's OVERFLOWING day rule, so `2011-01-31 +1 month` lands in March.",
        "echo strtotime(\"1970-01-02\");   // => 86400",
    ),
    (
        "getdate",
        "Date and time",
        "getdate(int $timestamp = time()): array",
        "A UTC-computed map with the keys `seconds minutes hours mday wday mon year yday weekday month` plus the integer key `0` holding the timestamp. DIVERGENCE: only key `0` is numeric — PHP's other numeric indices are absent.",
        "echo getdate(0)[\"year\"], getdate(0)[\"weekday\"];   // => 1970Thursday",
    ),
    (
        "date_default_timezone_set",
        "Date and time",
        "date_default_timezone_set(string $timezoneId): true",
        "Stores the name and ALWAYS returns true. DIVERGENCE: an unknown name is not rejected (PHP returns false), and setting a non-UTC zone shifts NOTHING — every calculation in the module stays UTC.",
        "var_dump(date_default_timezone_set(\"America/New_York\"));   // => bool(true)",
    ),
    (
        "date_default_timezone_get",
        "Date and time",
        "date_default_timezone_get(): string",
        "The name last stored, defaulting to `UTC`. It round-trips whatever string was set, valid or not.",
        "echo date_default_timezone_get();   // => UTC",
    ),
    // ══ Date and time — procedural object API (stdlib::datefn) ══════════════
    (
        "date_create",
        "Date and time — object API",
        "date_create(string $datetime = \"now\"): object",
        "Constructs a prelude `DateTime`. DIVERGENCE: PHP's `$timezone` parameter does not exist.",
        "echo date_create(\"@0\")->format(\"Y\");   // => 1970",
    ),
    (
        "date_create_immutable",
        "Date and time — object API",
        "date_create_immutable(string $datetime = \"now\"): object",
        "Constructs a prelude `DateTimeImmutable`, again with no `$timezone` parameter.",
        "echo date_create_immutable(\"@0\")->getTimestamp();   // => 0",
    ),
    (
        "date_interval_create_from_date_string",
        "Date and time — object API",
        "date_interval_create_from_date_string(string $datetime): object",
        "DIVERGENCE: it constructs a `DateInterval` from the EMPTY string — the `$datetime` argument is accepted and ignored, so the returned interval always carries a zero duration regardless of what you pass.",
        "echo date_interval_create_from_date_string(\"1 day\")->d;   // => 0",
    ),
    (
        "date_format",
        "Date and time — object API",
        "date_format(object $object, string $format): string|false",
        "Calls `->format($format)` on the receiver's own class. A non-object first argument returns `false`.",
        "echo date_format(date_create(\"@0\"), \"Y-m-d\");   // => 1970-01-01",
    ),
    (
        "date_add",
        "Date and time — object API",
        "date_add(object $object, object $interval): mixed",
        "Calls `->add($interval)`. On a `DateTime` this mutates and returns the receiver; on a `DateTimeImmutable` it returns a new instance.",
        "echo date_add(date_create(\"@0\"), new DateInterval(\"P1D\"))->getTimestamp();   // => 86400",
    ),
    (
        "date_sub",
        "Date and time — object API",
        "date_sub(object $object, object $interval): mixed",
        "Calls `->sub($interval)` with the same mutable-versus-immutable behaviour as `date_add`.",
        "echo date_sub(date_create(\"@86400\"), new DateInterval(\"P1D\"))->getTimestamp();   // => 0",
    ),
    (
        "date_diff",
        "Date and time — object API",
        "date_diff(object $baseObject, object $targetObject): mixed",
        "Calls `->diff($target)` and returns a `DateInterval`. DIVERGENCE: PHP's `$absolute` third parameter is not forwarded, so the interval's `invert` flag is always the one `diff` computes.",
        "echo date_diff(date_create(\"@0\"), date_create(\"@86400\"))->d;   // => 1",
    ),
    (
        "date_modify",
        "Date and time — object API",
        "date_modify(object $object, string $modifier): mixed",
        "Calls `->modify($modifier)`, which routes through `strtotime` and therefore accepts only that function's documented subset.",
        "echo date_modify(date_create(\"@0\"), \"+1 day\")->getTimestamp();   // => 86400",
    ),
    (
        "date_timestamp_get",
        "Date and time — object API",
        "date_timestamp_get(object $object): mixed",
        "Calls `->getTimestamp()`, returning `false` for a non-object argument.",
        "echo date_timestamp_get(date_create(\"@42\"));   // => 42",
    ),
    (
        "date_timestamp_set",
        "Date and time — object API",
        "date_timestamp_set(object $object, int $timestamp): mixed",
        "Calls `->setTimestamp($timestamp)`. Only `DateTime` declares that method, so an immutable receiver has nothing to dispatch to.",
        "echo date_timestamp_set(date_create(\"@0\"), 99)->getTimestamp();   // => 99",
    ),
    (
        "date_interval_format",
        "Date and time — object API",
        "date_interval_format(object $object, string $format): mixed",
        "Calls `->format($format)` on a `DateInterval` — the identical code path as `date_format`, differing only in which class resolves the method.",
        "echo date_interval_format(new DateInterval(\"P2D\"), \"%d\");   // => 2",
    ),
    (
        "date_offset_get",
        "Date and time — object API",
        "date_offset_get(object $object): int",
        "DIVERGENCE: always returns 0 and ignores its argument, because the runtime is UTC-only and has no offset to report.",
        "echo date_offset_get(date_create(\"@0\"));   // => 0",
    ),
    // ══ By-reference array mutators (compiler.rs) ═══════════════════════════
    // A third registration table: `array_mutator_subop()` in `src/compiler.rs`
    // maps these five names to `ops::ARR_MUT` sub-ops. They lower specially —
    // the array is passed by VARIABLE NAME, not by value — which is how they
    // mutate the caller's variable without by-reference parameters existing.
    // Because they never reach `call_library`, they are the one part of the
    // library surface that a dynamic `call_user_func("array_pop", …)` cannot use.
    (
        "array_pop",
        "By-reference array mutators",
        "array_pop(array $array): mixed",
        "Removes and returns the LAST element, shortening the caller's array in place. An empty array yields null.",
        "$a = [1, 2, 3]; echo array_pop($a), count($a);   // => 32",
    ),
    (
        "array_shift",
        "By-reference array mutators",
        "array_shift(array $array): mixed",
        "Removes and returns the FIRST element, reindexing the remaining integer keys from 0. An empty array yields null.",
        "$a = [1, 2, 3]; echo array_shift($a), implode(\",\", $a);   // => 12,3",
    ),
    (
        "array_unshift",
        "By-reference array mutators",
        "array_unshift(array $array, mixed ...$values): int",
        "Prepends the values, reindexing integer keys from 0, and returns the new element count.",
        "$a = [2, 3]; array_unshift($a, 1); echo implode(\",\", $a);   // => 1,2,3",
    ),
    (
        "array_splice",
        "By-reference array mutators",
        "array_splice(array $array, int $offset, ?int $length = null, mixed $replacement = []): array",
        "Removes a run of elements in place and optionally substitutes a replacement, returning the extracted run. Negative offsets and lengths count from the end.",
        "$a = [1, 2, 3, 4]; array_splice($a, 1, 2); echo implode(\",\", $a);   // => 1,4",
    ),
    // ══ Built-in object methods (host.rs) ═══════════════════════════════════
    // These are synthesized by the runtime rather than declared by any class, so
    // they appear in no class table: `Generator` and `Closure` have no PHP-source
    // definition, and the enum statics are generated per enum. `get_class_methods`
    // therefore does not list them.
    (
        "Generator::current",
        "Built-in object methods",
        "$generator->current(): mixed",
        "The value the generator is currently suspended on, running it up to its first `yield` if it has not started. Generator bodies run on their own native stack, so a `yield` deep inside nested calls suspends the whole VM in one stack switch.",
        "function g() { yield 1; yield 2; } $x = g(); echo $x->current();   // => 1",
    ),
    (
        "Generator::key",
        "Built-in object methods",
        "$generator->key(): mixed",
        "The key of the current element — the auto-incrementing integer for a bare `yield`, or the explicit key from a `yield $k => $v`.",
        "function g() { yield \"k\" => \"v\"; } $x = g(); echo $x->key();   // => k",
    ),
    (
        "Generator::next",
        "Built-in object methods",
        "$generator->next(): void",
        "Resumes the generator until its next `yield` or its return. Equivalent to `send(null)` with the result discarded.",
        "function g() { yield 1; yield 2; } $x = g(); $x->next(); echo $x->current();   // => 2",
    ),
    (
        "Generator::valid",
        "Built-in object methods",
        "$generator->valid(): bool",
        "False once the body has run to completion, which is what ends a `foreach` over the generator.",
        "function g() { yield 1; } $x = g(); $x->next(); var_dump($x->valid());   // => bool(false)",
    ),
    (
        "Generator::rewind",
        "Built-in object methods",
        "$generator->rewind(): void",
        "Runs the generator up to its first `yield` if it has not started. It cannot actually rewind an already-advanced generator, matching PHP.",
        "",
    ),
    (
        "Generator::send",
        "Built-in object methods",
        "$generator->send(mixed $value): mixed",
        "Resumes the generator, making the suspended `yield` expression evaluate to `$value`, and returns the next yielded value. A missing argument sends null.",
        "function g() { $a = yield 1; echo \"got:$a\"; }\n$x = g(); echo $x->current(); $x->send(\"Z\");   // => 1got:Z",
    ),
    (
        "Generator::throw",
        "Built-in object methods",
        "$generator->throw(object $exception): mixed",
        "Resumes the generator by raising the exception AT the suspended `yield`, so a `try`/`catch` inside the body can handle it.",
        "function g() { try { yield 1; } catch (Exception $e) { echo \"C:\" . $e->getMessage(); } }\n$x = g(); $x->current(); $x->throw(new Exception(\"boom\"));   // => C:boom",
    ),
    (
        "Generator::getReturn",
        "Built-in object methods",
        "$generator->getReturn(): mixed",
        "The value the generator body returned. It reads the stored slot directly and does NOT raise when the generator has not finished — it simply reports whatever is there, which differs from PHP's `Exception`.",
        "function g() { yield 1; return 9; } $x = g(); $x->next(); echo $x->getReturn();   // => 9",
    ),
    (
        "Closure::bind",
        "Built-in object methods",
        "Closure::bind(Closure $closure, ?object $newThis, object|string|null $newScope = null): Closure",
        "Static form of `bindTo`: returns a copy of the closure with `$this` rebound and, when a scope is given, private-member access granted for that class.",
        "class C { private $p = 7; }\n$f = function () { return $this->p; };\necho Closure::bind($f, new C, C::class)();   // => 7",
    ),
    (
        "Closure::fromCallable",
        "Built-in object methods",
        "Closure::fromCallable(callable $callback): Closure",
        "DIVERGENCE: it returns its argument UNCHANGED rather than wrapping it. That works because a callable string is already dispatchable through the runtime's `call_value`, but it means `Closure::fromCallable(\"strlen\")` yields the string `\"strlen\"`, not a `Closure` — so `is_object()` on the result is false.",
        "$c = Closure::fromCallable(\"strlen\"); echo $c(\"abcd\");   // => 4",
    ),
    (
        "Closure::bindTo",
        "Built-in object methods",
        "$closure->bindTo(?object $newThis, object|string|null $newScope = null): Closure",
        "Returns a copy of the closure with `$this` rebound. Both arguments are optional; omitting the object unbinds `$this`.",
        "class C { public $p = 3; }\n$f = function () { return $this->p; };\necho $f->bindTo(new C)();   // => 3",
    ),
    (
        "Closure::call",
        "Built-in object methods",
        "$closure->call(object $newThis, mixed ...$args): mixed",
        "Binds and invokes in one step. The scope is ALWAYS the bound object's own class, so the closure can reach that class's private members without naming a scope.",
        "class C { private $p = 8; }\n$f = function () { return $this->p; };\necho $f->call(new C);   // => 8",
    ),
    (
        "enum::cases",
        "Built-in object methods",
        "EnumName::cases(): array",
        "A list of every case object of the enum, in declaration order. Synthesized per enum rather than declared, so it exists on both pure and backed enums.",
        "enum S: string { case A = \"a\"; case B = \"b\"; } echo count(S::cases());   // => 2",
    ),
    (
        "enum::from",
        "Built-in object methods",
        "EnumName::from(string|int $value): EnumName",
        "The case whose backing value equals the argument. An unmatched value is an error — use `tryFrom` for the null-returning form.",
        "enum S: string { case A = \"a\"; } echo S::from(\"a\")->name;   // => A",
    ),
    (
        "enum::tryFrom",
        "Built-in object methods",
        "EnumName::tryFrom(string|int $value): ?EnumName",
        "The case whose backing value equals the argument, or null when none matches. It shares `from`'s implementation with the error path turned into a null return.",
        "enum S: string { case A = \"a\"; } var_dump(S::tryFrom(\"z\"));   // => NULL",
    ),
    (
        "enum->name",
        "Built-in object methods",
        "$case->name: string",
        "The declared case name, present on every enum case — pure and backed alike.",
        "enum S { case A; } echo S::A->name;   // => A",
    ),
    (
        "enum->value",
        "Built-in object methods",
        "$case->value: string|int",
        "The backing value of a case. Present only on a backed enum (one declared with a `: string` or `: int` backing type); a pure enum's cases carry only `name`.",
        "enum S: string { case A = \"a\"; } echo S::A->value;   // => a",
    ),
    // ══ Filesystem (stdlib::fileio) ════════════════════════════════════════
    // Path-based operations. Every read converts with `from_utf8_lossy`, so these
    // functions are NOT binary-safe: a byte sequence that is not valid UTF-8
    // becomes U+FFFD. No `$context` argument is read anywhere in this module,
    // because phplang has no stream contexts.
    (
        "file_get_contents",
        "Filesystem",
        "file_get_contents(string $filename): string|false",
        "Reads the whole file and returns it as a string, or `false` on any I/O error with no warning. DIVERGENCE: `$use_include_path`, `$context`, `$offset`, and `$length` are never read — a partial read is not possible — and the lossy UTF-8 conversion makes it binary-unsafe.",
        "file_put_contents(\"/tmp/php_ref.txt\", \"hi\"); echo file_get_contents(\"/tmp/php_ref.txt\");   // => hi",
    ),
    (
        "file_put_contents",
        "Filesystem",
        "file_put_contents(string $filename, mixed $data, int $flags = 0): int|false",
        "Writes the data — an array is string-cast element-wise and concatenated with no separator — and returns the byte count. Only `FILE_APPEND` is honoured; `LOCK_EX` and `FILE_USE_INCLUDE_PATH` are accepted and ignored, so no locking happens.",
        "echo file_put_contents(\"/tmp/php_ref.txt\", \"abc\");   // => 3",
    ),
    (
        "file",
        "Filesystem",
        "file(string $filename, int $flags = 0): array|false",
        "Splits the file on `\\n`, keeping each terminator by default. `FILE_IGNORE_NEW_LINES` and `FILE_SKIP_EMPTY_LINES` are honoured; `FILE_USE_INCLUDE_PATH` is ignored. A read failure returns `false`.",
        "file_put_contents(\"/tmp/php_ref.txt\", \"a\\nb\");\necho count(file(\"/tmp/php_ref.txt\", FILE_IGNORE_NEW_LINES));   // => 2",
    ),
    (
        "readfile",
        "Filesystem",
        "readfile(string $filename): int|false",
        "Writes the file's contents to output and returns the RAW byte count read from disk — which can exceed the length of what was emitted, since the text goes through the lossy conversion. `$use_include_path` and `$context` are not read.",
        "file_put_contents(\"/tmp/php_ref.txt\", \"hi\"); echo readfile(\"/tmp/php_ref.txt\");   // => hi2",
    ),
    (
        "file_exists",
        "Filesystem",
        "file_exists(string $filename): bool",
        "Stats the path, following symlinks, so a broken symlink reports false. There is no stat cache to invalidate.",
        "var_dump(file_exists(\"/\"));   // => bool(true)",
    ),
    (
        "is_file",
        "Filesystem",
        "is_file(string $filename): bool",
        "True when the path stats to a regular file, following symlinks. A failed stat is false.",
        "var_dump(is_file(\"/\"));   // => bool(false)",
    ),
    (
        "is_dir",
        "Filesystem",
        "is_dir(string $filename): bool",
        "True when the path stats to a directory, following symlinks.",
        "var_dump(is_dir(\"/\"));   // => bool(true)",
    ),
    (
        "is_link",
        "Filesystem",
        "is_link(string $filename): bool",
        "True when an `lstat` reports a symlink; the link is not followed.",
        "var_dump(is_link(\"/\"));   // => bool(false)",
    ),
    (
        "is_readable",
        "Filesystem",
        "is_readable(string $filename): bool",
        "DIVERGENCE: it does NOT call `access(2)` with `R_OK` — it only checks that the path can be stat'd. A file that exists but cannot be opened by the current user still reports true.",
        "var_dump(is_readable(\"/\"));   // => bool(true)",
    ),
    (
        "is_writable",
        "Filesystem",
        "is_writable(string $filename): bool",
        "DIVERGENCE: no `access(2)` call. It stats the path and reports the inverse of the read-only mode bit, so it ignores the effective uid and gid, ACLs, and read-only mounts. A missing path is false.",
        "",
    ),
    (
        "is_writeable",
        "Filesystem",
        "is_writeable(string $filename): bool",
        "The alias of `is_writable`, sharing its match arm and its mode-bits-only limitation.",
        "",
    ),
    (
        "is_executable",
        "Filesystem",
        "is_executable(string $filename): bool",
        "A REAL `access(2)` check with `X_OK` for the current user — the one predicate in this module that consults the effective credentials. A path containing an interior NUL, or a missing path, is false.",
        "",
    ),
    (
        "filetype",
        "Filesystem",
        "filetype(string $filename): string|false",
        "One of `dir`, `file`, `link`, `fifo`, `char`, `block`, `socket`, or `unknown`. It uses `lstat`, so a symlink reports `link` rather than its target's type. A failed stat returns `false`.",
        "echo filetype(\"/\");   // => dir",
    ),
    (
        "filesize",
        "Filesystem",
        "filesize(string $filename): int|false",
        "The file's size in bytes from a real stat, following symlinks. A failed stat returns `false`.",
        "file_put_contents(\"/tmp/php_ref.txt\", \"abc\"); echo filesize(\"/tmp/php_ref.txt\");   // => 3",
    ),
    (
        "filemtime",
        "Filesystem",
        "filemtime(string $filename): int|false",
        "The modification time truncated to whole Unix seconds. Any failure returns `false` — including a pre-1970 mtime, which cannot be represented by the underlying duration.",
        "",
    ),
    (
        "fileperms",
        "Filesystem",
        "fileperms(string $filename): int|false",
        "The full `st_mode`, file-type bits included rather than just the permission bits — mask with `0777` to get what `chmod` would take. A failed stat returns `false`.",
        "",
    ),
    (
        "stat",
        "Filesystem",
        "stat(string $filename): array|false",
        "A real `stat(2)`, following symlinks. Returns the full 26-entry PHP array: the 13 fields `dev ino mode nlink uid gid rdev size atime mtime ctime blksize blocks` under numeric keys `0`-`12`, then the same values again under their names. No field is synthesized.",
        "echo count(stat(\"/\"));   // => 26",
    ),
    (
        "lstat",
        "Filesystem",
        "lstat(string $filename): array|false",
        "The same 26-entry array as `stat`, built from an `lstat` so it describes the symlink itself rather than its target.",
        "echo count(lstat(\"/\"));   // => 26",
    ),
    (
        "clearstatcache",
        "Filesystem",
        "clearstatcache(bool $clear_realpath_cache = false, string $filename = \"\"): null",
        "A no-op returning null. There is no stat cache in this implementation, so nothing is invalidated and neither argument is read.",
        "var_dump(clearstatcache());   // => NULL",
    ),
    (
        "unlink",
        "Filesystem",
        "unlink(string $filename): bool",
        "Removes a file. Returns `false` on any error, including an attempt to remove a directory. `$context` is not read.",
        "",
    ),
    (
        "mkdir",
        "Filesystem",
        "mkdir(string $directory, int $permissions = 0777, bool $recursive = false): bool",
        "Creates a directory. `$recursive` is honoured and selects the create-all path. DIVERGENCE: `$permissions` is accepted and IGNORED — no mode is applied, so the directory gets the process umask default.",
        "",
    ),
    (
        "rmdir",
        "Filesystem",
        "rmdir(string $directory): bool",
        "Removes an empty directory. It is never recursive, so a non-empty directory returns `false`.",
        "",
    ),
    (
        "rename",
        "Filesystem",
        "rename(string $from, string $to): bool",
        "Renames a path with same-filesystem semantics. Errors return `false` silently.",
        "",
    ),
    (
        "copy",
        "Filesystem",
        "copy(string $from, string $to): bool",
        "Copies the source over the destination, creating or truncating it and carrying the permission bits. Symlinks are followed.",
        "",
    ),
    (
        "touch",
        "Filesystem",
        "touch(string $filename, ?int $mtime = null): bool",
        "Creates the file if absent — without truncating an existing one — and sets its modification time, defaulting to now. DIVERGENCE: PHP's third `$atime` argument is accepted positionally but never applied, because the underlying file handle exposes only the modification time.",
        "",
    ),
    (
        "scandir",
        "Filesystem",
        "scandir(string $directory, int $sorting_order = SCANDIR_SORT_ASCENDING): array|false",
        "Lists a directory, SYNTHESIZING the `.` and `..` entries rather than reading them, then sorting by Rust byte order (not PHP's locale collation). Only the descending order is recognized; `SCANDIR_SORT_NONE` is not, so the result is always sorted. A read failure returns `false`.",
        "var_dump(in_array(\".\", scandir(\"/tmp\")));   // => bool(true)",
    ),
    (
        "glob",
        "Filesystem",
        "glob(string $pattern, int $flags = 0): array",
        "A hand-rolled matcher, NOT libc `glob(3)`. The pattern splits at its LAST `/`: everything before is a literal directory, so wildcards never expand across directory levels. Supported: `*`, `?`, and `[…]` with `a-z` ranges and `!`/`^` negation. NOT supported: `{a,b}` brace expansion and backslash escaping. `GLOB_ONLYDIR`, `GLOB_MARK`, and `GLOB_NOSORT` are honoured. Dotfiles are skipped unless the name pattern itself starts with `.`. DIVERGENCE: it never returns `false` — an unreadable directory yields an empty array.",
        "file_put_contents(\"/tmp/php_ref_g.txt\", \"\"); echo count(glob(\"/tmp/php_ref_g.*\"));   // => 1",
    ),
    (
        "fnmatch",
        "Filesystem",
        "fnmatch(string $pattern, string $filename, int $flags = 0): bool",
        "Runs the same hand-rolled matcher over the whole string. Only `FNM_CASEFOLD` is honoured, and its folding is ASCII-only. DIVERGENCE: `FNM_PATHNAME` is ignored so `*` and `?` cross `/`, `FNM_PERIOD` is ignored so `*` matches a leading dot, and backslash escaping does not exist.",
        "var_dump(fnmatch(\"*.txt\", \"a.txt\"));   // => bool(true)",
    ),
    (
        "basename",
        "Filesystem",
        "basename(string $path, string $suffix = \"\"): string",
        "A pure string operation with no filesystem access: it strips all trailing `/`, then takes the text after the last remaining one. The suffix is removed only when doing so would not empty the result, so `basename(\"foo.txt\", \"foo.txt\")` returns `foo.txt` unchanged. Windows `\\` separators are not recognized.",
        "echo basename(\"/a/b/c.txt\", \".txt\");   // => c",
    ),
    (
        "dirname",
        "Filesystem",
        "dirname(string $path, int $levels = 1): string",
        "Applies the one-level dirname `$levels` times. DIVERGENCE: a `$levels` of 0 or negative is clamped to 1 rather than raising `ValueError`. An all-slash path yields `/`, and a path with no `/` yields `.`.",
        "echo dirname(\"/a/b/c.txt\"), \"|\", dirname(\"/a/b/c.txt\", 2);   // => /a/b|/a",
    ),
    (
        "pathinfo",
        "Filesystem",
        "pathinfo(string $path, int $flags = PATHINFO_ALL): array|string",
        "Splits the basename at the LAST `.`, matching PHP's own `php_pathinfo`, so `.htaccess` gives extension `htaccess` and an empty filename. With no second argument it returns a map whose `extension` key is OMITTED ENTIRELY when the basename has no dot. With a selector it returns one string, or `\"\"` when that piece is absent. No filesystem access.",
        "echo pathinfo(\"/a/b.txt\", PATHINFO_EXTENSION);   // => txt",
    ),
    (
        "realpath",
        "Filesystem",
        "realpath(string $path): string|false",
        "Canonicalizes the path, resolving symlinks and `.`/`..` to an absolute path. The path must EXIST — a non-existent name under an existing parent returns `false`. Being the OS call, on macOS it returns the `/private`-prefixed form for `/tmp` and `/var`.",
        "var_dump(realpath(\"/no/such/path\"));   // => bool(false)",
    ),
    (
        "getcwd",
        "Filesystem",
        "getcwd(): string|false",
        "The current working directory, or `false` when the syscall fails — for instance after the directory has been removed.",
        "var_dump(strlen(getcwd()) > 0);   // => bool(true)",
    ),
    (
        "sys_get_temp_dir",
        "Filesystem",
        "sys_get_temp_dir(): string",
        "The temporary directory, honouring `TMPDIR` and otherwise `/tmp`, with trailing slashes trimmed. It never returns `false`.",
        "var_dump(strlen(sys_get_temp_dir()) > 0);   // => bool(true)",
    ),
    (
        "tempnam",
        "Filesystem",
        "tempnam(string $directory, string $prefix): string|false",
        "Creates a new empty file and returns its path, falling back to the system temp directory when `$directory` is not one. DIVERGENCE: uniqueness comes from the process id plus a nanosecond timestamp rather than randomness, and although the file is created exclusively it is NOT chmod'ed to 0600 — it gets the default mode masked by the umask, so do not treat it as private.",
        "",
    ),
    (
        "disk_free_space",
        "Filesystem",
        "disk_free_space(string $directory): float|false",
        "A real `statvfs(2)`, reporting the space available to an UNPRIVILEGED process (the available-blocks count, not the free-blocks count). A failed call returns `false`.",
        "var_dump(disk_free_space(\"/\") > 0);   // => bool(true)",
    ),
    (
        "diskfreespace",
        "Filesystem",
        "diskfreespace(string $directory): float|false",
        "The alias of `disk_free_space`, sharing its match arm.",
        "",
    ),
    (
        "disk_total_space",
        "Filesystem",
        "disk_total_space(string $directory): float|false",
        "A real `statvfs(2)` reporting the filesystem's total size in bytes.",
        "var_dump(disk_total_space(\"/\") > 0);   // => bool(true)",
    ),
    // ══ File streams (stdlib::fileres) ══════════════════════════════════════
    // A phplang stream resource is NOT an OS file descriptor. `fopen` reads the
    // WHOLE file into an in-memory buffer and keeps a cursor; no descriptor is
    // retained. Every write updates the buffer and then rewrites the whole file,
    // so writes reach disk eagerly but each one costs O(filesize).
    (
        "fopen",
        "File streams",
        "fopen(string $filename, string $mode): resource|false",
        "Opens a buffered in-memory resource. A trailing `b` or `t` is a no-op. `r` loads the file and is read-only unless `+` is given; `w` and `x` are always writable and truncate or exclusively create on open; `c` preloads without truncating; `a` preloads and parks the cursor at the end but does NOT create the file until the first flush. An unreadable file, an existing path under `x`, or an unrecognized leading character returns `false`.",
        "$f = fopen(\"/tmp/php_ref_s.txt\", \"w\"); var_dump(is_resource($f)); fclose($f);   // => bool(true)",
    ),
    (
        "fread",
        "File streams",
        "fread(resource $stream, int $length): string|false",
        "Copies up to `$length` bytes from the cursor and advances it. At end of file it returns `\"\"`, not `false`; only a non-resource argument gives `false`. DIVERGENCE: a CLOSED resource still reads successfully, and the lossy UTF-8 conversion makes it binary-unsafe.",
        "file_put_contents(\"/tmp/php_ref_s.txt\", \"abcdef\");\n$f = fopen(\"/tmp/php_ref_s.txt\", \"r\"); echo fread($f, 3); fclose($f);   // => abc",
    ),
    (
        "fgets",
        "File streams",
        "fgets(resource $stream, ?int $length = null): string|false",
        "Reads from the cursor through the next `\\n` inclusive. A `$length` caps the read at one byte fewer, as in PHP. At end of file it returns `false`.",
        "file_put_contents(\"/tmp/php_ref_s.txt\", \"a\\nb\");\n$f = fopen(\"/tmp/php_ref_s.txt\", \"r\"); echo trim(fgets($f)); fclose($f);   // => a",
    ),
    (
        "fwrite",
        "File streams",
        "fwrite(resource $stream, string $data, ?int $length = null): int|false",
        "Overwrites or extends the buffer at the cursor, then IMMEDIATELY rewrites the whole file — so data reaches disk without waiting for `fclose`, at O(filesize) per call. `$length` truncates the data. Returns `false` when the resource is not writable, is closed, or is not a resource. Even in append mode the entire buffer is rewritten.",
        "$f = fopen(\"/tmp/php_ref_s.txt\", \"w\"); echo fwrite($f, \"abc\"); fclose($f);   // => 3",
    ),
    (
        "fputs",
        "File streams",
        "fputs(resource $stream, string $data, ?int $length = null): int|false",
        "The alias of `fwrite`, sharing its match arm and its eager whole-file flush.",
        "",
    ),
    (
        "fclose",
        "File streams",
        "fclose(resource $stream): bool",
        "Flushes any dirty buffer and marks the resource closed. A second `fclose` returns `false`. The flush runs BEFORE the closed check, so a dirty already-closed resource is still written out.",
        "$f = fopen(\"/tmp/php_ref_s.txt\", \"w\"); var_dump(fclose($f), fclose($f));   // => bool(true) bool(false)",
    ),
    (
        "fflush",
        "File streams",
        "fflush(resource $stream): bool",
        "Rewrites the whole buffer to disk when it is dirty. DIVERGENCE: it returns true unconditionally — for a non-resource, a closed resource, and even a failed write.",
        "",
    ),
    (
        "feof",
        "File streams",
        "feof(resource $stream): bool",
        "True when the cursor has reached the end of the buffer, and true for anything that is not a resource. It does not consult the closed flag.",
        "file_put_contents(\"/tmp/php_ref_s.txt\", \"a\");\n$f = fopen(\"/tmp/php_ref_s.txt\", \"r\"); fread($f, 1); var_dump(feof($f)); fclose($f);   // => bool(true)",
    ),
    (
        "ftell",
        "File streams",
        "ftell(resource $stream): int|false",
        "The current cursor position. It is the one accessor that DOES check the closed flag, returning `false` for a closed resource as well as a non-resource.",
        "file_put_contents(\"/tmp/php_ref_s.txt\", \"abc\");\n$f = fopen(\"/tmp/php_ref_s.txt\", \"r\"); fread($f, 2); echo ftell($f); fclose($f);   // => 2",
    ),
    (
        "fseek",
        "File streams",
        "fseek(resource $stream, int $offset, int $whence = SEEK_SET): int",
        "Repositions the cursor; whence 1 is from the current position, 2 from the end, anything else from the start. DIVERGENCE: the result is CLAMPED to the buffer, so seeking past the end is impossible and PHP's seek-beyond-EOF-then-write zero fill cannot happen. Returns 0 on success and -1 only for a non-resource.",
        "file_put_contents(\"/tmp/php_ref_s.txt\", \"abcdef\");\n$f = fopen(\"/tmp/php_ref_s.txt\", \"r\"); fseek($f, 3); echo fread($f, 2); fclose($f);   // => de",
    ),
    (
        "rewind",
        "File streams",
        "rewind(resource $stream): bool",
        "Seeks the cursor to 0. It does not flush, and it succeeds even for a closed resource; only a non-resource returns `false`.",
        "file_put_contents(\"/tmp/php_ref_s.txt\", \"abc\");\n$f = fopen(\"/tmp/php_ref_s.txt\", \"r\"); fread($f, 2); rewind($f); echo fread($f, 1); fclose($f);   // => a",
    ),
    (
        "stream_get_contents",
        "File streams",
        "stream_get_contents(resource $stream): string|false",
        "Everything remaining from the cursor to the end of the buffer. DIVERGENCE: `$maxlength` and `$offset` are never read, so neither a length cap nor an offset seek is applied. A closed resource yields `\"\"`; only a non-resource returns `false`.",
        "file_put_contents(\"/tmp/php_ref_s.txt\", \"abc\");\n$f = fopen(\"/tmp/php_ref_s.txt\", \"r\"); echo stream_get_contents($f); fclose($f);   // => abc",
    ),
    (
        "is_resource",
        "File streams",
        "is_resource(mixed $value): bool",
        "True only for an OPEN stream resource — a closed handle reports false, as in PHP.",
        "$f = fopen(\"/tmp/php_ref_s.txt\", \"w\"); fclose($f); var_dump(is_resource($f));   // => bool(false)",
    ),
    (
        "get_resource_type",
        "File streams",
        "get_resource_type(mixed $value): string|false",
        "Always the literal `\"stream\"` for an open resource — there is only one resource kind in this runtime. A non-resource or closed resource returns `false`.",
        "$f = fopen(\"/tmp/php_ref_s.txt\", \"w\"); echo get_resource_type($f); fclose($f);   // => stream",
    ),
    // ══ Misc (stdlib::misc) ═════════════════════════════════════════════════
    (
        "array_find",
        "Misc",
        "array_find(array $array, callable $callback): mixed",
        "The PHP 8.4 search: returns the first VALUE for which `$callback($value, $key)` is truthy — note the value comes first. No match returns null, which is indistinguishable from having matched a null element.",
        "echo array_find([1, 8, 3], fn($v, $k) => $v > 5);   // => 8",
    ),
    (
        "array_find_key",
        "Misc",
        "array_find_key(array $array, callable $callback): mixed",
        "The KEY of the first element for which `$callback($value, $key)` is truthy, or null when none matches. It shares `array_find`'s loop.",
        "echo array_find_key([1, 8, 3], fn($v, $k) => $v > 5);   // => 1",
    ),
    (
        "array_any",
        "Misc",
        "array_any(array $array, callable $callback): bool",
        "True as soon as `$callback($value, $key)` is truthy for some element; false for an empty array.",
        "var_dump(array_any([1, 2], fn($v, $k) => $v > 1));   // => bool(true)",
    ),
    (
        "array_all",
        "Misc",
        "array_all(array $array, callable $callback): bool",
        "True when `$callback($value, $key)` is truthy for every element, and true for an empty array.",
        "var_dump(array_all([2, 4], fn($v, $k) => $v % 2 === 0));   // => bool(true)",
    ),
    (
        "array_udiff",
        "Misc",
        "array_udiff(array $array1, array $array2, ..., callable $value_compare_func): array",
        "Keeps the entries of the first array whose VALUE compares non-zero against every value of every other array, preserving keys. The comparator is the LAST argument and any number of operand arrays may precede it. DIVERGENCE: fewer than three arguments silently returns an empty array instead of raising, and the comparison is the direct O(n·m) form rather than PHP's sort-then-compare.",
        "echo implode(\",\", array_udiff([1, 2, 3], [2], fn($a, $b) => $a <=> $b));   // => 1,3",
    ),
    (
        "array_uintersect",
        "Misc",
        "array_uintersect(array $array1, array $array2, ..., callable $value_compare_func): array",
        "Keeps the entries of the first array whose value compares equal to some value in EVERY other array, preserving keys. Same comparator-last shape and same under-three-arguments behaviour as `array_udiff`.",
        "echo implode(\",\", array_uintersect([1, 2, 3], [2, 3], fn($a, $b) => $a <=> $b));   // => 2,3",
    ),
    (
        "array_diff_ukey",
        "Misc",
        "array_diff_ukey(array $array1, array $array2, ..., callable $key_compare_func): array",
        "The key-comparing counterpart of `array_udiff`: an entry survives when its KEY compares non-zero against every key of every other array.",
        "echo implode(\",\", array_diff_ukey([\"a\" => 1, \"b\" => 2], [\"a\" => 9], fn($x, $y) => strcmp($x, $y)));   // => 2",
    ),
    (
        "array_intersect_ukey",
        "Misc",
        "array_intersect_ukey(array $array1, array $array2, ..., callable $key_compare_func): array",
        "Keeps the entries of the first array whose key compares equal to some key in every other array, using the caller's comparator.",
        "echo implode(\",\", array_intersect_ukey([\"a\" => 1, \"b\" => 2], [\"a\" => 9], fn($x, $y) => strcmp($x, $y)));   // => 1",
    ),
    (
        "array_multisort",
        "Misc",
        "array_multisort(array $array1, mixed ...$rest): bool",
        "Fully variadic: every array argument starts a new column and every scalar applies as a flag to the most recent column. Columns break ties left to right, and every column is reordered by the same permutation, reindexed from 0 with all keys discarded. Only `SORT_ASC`, `SORT_DESC`, `SORT_REGULAR`, `SORT_NUMERIC`, and `SORT_STRING` are recognized — `SORT_NATURAL`, `SORT_FLAG_CASE`, and any OR-combination are silently ignored. It returns `false` rather than raising when there is no array argument or the columns differ in length.",
        "$a = [3, 1, 2]; $b = [\"c\", \"a\", \"b\"]; array_multisort($a, $b);\necho implode(\",\", $a), \"|\", implode(\",\", $b);   // => 1,2,3|a,b,c",
    ),
    (
        "array_walk_recursive",
        "Misc",
        "array_walk_recursive(array $array, callable $callback, mixed $arg = null): bool",
        "Descends nested arrays and invokes `$callback($value, $key[, $arg])` on non-array LEAVES only — a nested array is recursed into but never passed to the callback. The leaf goes in through a reference cell, so a `function (&$v)` callback rewrites it in place, exactly as with `array_walk`.",
        "$a = [1, [2, 3]]; array_walk_recursive($a, function ($v, $k) { echo $v; });   // => 123",
    ),
    (
        "str_word_count",
        "Misc",
        "str_word_count(string $string, int $format = 0, ?string $characters = null): int|array",
        "Format 1 returns the words, format 2 a byte-offset-to-word map, and 0 the count; any other value raises `ValueError: str_word_count(): Argument #2 ($format) must be a valid format value`. A word is a run of ASCII letters plus `'` and `-`, which are ALWAYS word characters; `$characters` only ADDS bytes to that set and can never restrict it. Matching is bytewise, so multibyte text is not recognized as words.",
        "echo str_word_count(\"a b c\");   // => 3",
    ),
    (
        "strnatcmp",
        "Misc",
        "strnatcmp(string $string1, string $string2): int",
        "A byte-for-byte port of PHP's natural-order comparison, returning only the sign. Leading zeros are stripped ONCE at the start of each string rather than per digit run, so `strnatcmp(\"1\", \"01\")` is 0. A digit run compares left-aligned when either side starts with `0`, and by magnitude otherwise.",
        "echo strnatcmp(\"img12\", \"img2\");   // => 1",
    ),
    (
        "strnatcasecmp",
        "Misc",
        "strnatcasecmp(string $string1, string $string2): int",
        "`strnatcmp` with ASCII case folding, returning only the sign. Non-ASCII bytes are compared unfolded.",
        "echo strnatcasecmp(\"IMG2\", \"img2\");   // => 0",
    ),
    (
        "soundex",
        "Misc",
        "soundex(string $string): string",
        "The real Soundex algorithm, ported from PHP's own `soundex.c`: the first letter verbatim, then up to three consonant codes, right-padded with zeros. ASCII-only — a string with no ASCII letters returns `\"0000\"`.",
        "echo soundex(\"Robert\");   // => R163",
    ),
    (
        "metaphone",
        "Misc",
        "metaphone(string $string, int $max_phonemes = 0): string",
        "The real traditional Metaphone, ported from PHP's `metaphone.c` including the special first-phoneme cases and the CH, TH, DG, GH, and TIO/TIA rules — so `TH` encodes as the DIGIT zero and `CH` as `X`, as in PHP. ASCII-only; a letterless input returns the empty string. `$max_phonemes` caps the length, with 0 or negative meaning unlimited.",
        "echo metaphone(\"Thompson\");   // => 0MPSN",
    ),
    (
        "str_getcsv",
        "Misc",
        "str_getcsv(string $string, string $separator = \",\", string $enclosure = \"\\\"\", string $escape = \"\\\\\"): array",
        "Parses ONE line. Doubled enclosures inside a quoted field are literals, and unenclosed fields keep their blanks. DIVERGENCE: the escape character keeps BOTH itself and the following character — it is not stripped; an embedded newline is an ordinary field character, so multi-line records are never reassembled; an empty input returns a one-element array holding null; and an empty `$separator` or `$enclosure` falls back to the DEFAULT rather than disabling it. Omitting `$escape` raises PHP 8.4's deprecation notice.",
        "print_r(str_getcsv(\"a,b\"));   // => Array\\n(\\n    [0] => a\\n    [1] => b\\n)",
    ),
    (
        "uniqid",
        "Misc",
        "uniqid(string $prefix = \"\", bool $more_entropy = false): string",
        "A hex timestamp of the form `%08x%05x` from the wall clock's seconds and microseconds, prefixed by `$prefix`. `$more_entropy` is honoured and appends a fractional suffix of PHP's shape, but with only 1000 distinct values. DIVERGENCE: the clock is the ONLY entropy source — there is no RNG, no counter, and no collision avoidance, so two calls in the same microsecond return IDENTICAL strings. It is not suitable as a unique identifier under load.",
        "var_dump(strlen(uniqid()) === 13);   // => bool(true)",
    ),
    // ══ Output buffering (stdlib::system) ═══════════════════════════════════
    // A REAL nesting buffer stack lives on the host, and `write_out` always
    // targets its top, so nested buffers behave as PHP's do. What is missing is
    // the rewriting callback and chunked auto-flush.
    (
        "ob_start",
        "Output buffering",
        "ob_start(?callable $callback = null, int $chunk_size = 0, int $flags = 0): true",
        "Pushes a new buffer onto the stack, so buffers nest correctly. DIVERGENCE: `$callback`, `$chunk_size`, and `$flags` are NEVER read — the output-rewriting callback does not run at all and there is no chunked auto-flush. Always returns true.",
        "ob_start(); echo \"hidden\"; $s = ob_get_clean(); echo strlen($s);   // => 6",
    ),
    (
        "ob_get_contents",
        "Output buffering",
        "ob_get_contents(): string|false",
        "The top buffer's contents WITHOUT popping it, or `false` when no buffer is active.",
        "ob_start(); echo \"ab\"; $s = ob_get_contents(); ob_end_clean(); echo $s;   // => ab",
    ),
    (
        "ob_get_clean",
        "Output buffering",
        "ob_get_clean(): string|false",
        "Pops the top buffer and returns its contents, discarding them from the output. `false` when no buffer is active.",
        "ob_start(); echo \"x\"; echo ob_get_clean();   // => x",
    ),
    (
        "ob_end_clean",
        "Output buffering",
        "ob_end_clean(): bool",
        "Pops and DISCARDS the top buffer, returning whether one was active.",
        "ob_start(); echo \"gone\"; var_dump(ob_end_clean());   // => bool(true)",
    ),
    (
        "ob_end_flush",
        "Output buffering",
        "ob_end_flush(): bool",
        "Pops the top buffer and writes its contents DOWN ONE LEVEL — into the enclosing buffer if there is one, otherwise to output. Returns whether a buffer was active.",
        "ob_start(); echo \"out\"; ob_end_flush();   // => out",
    ),
    (
        "ob_get_flush",
        "Output buffering",
        "ob_get_flush(): string|false",
        "Reads the top buffer's contents and then performs `ob_end_flush()`, so the text is both returned AND written down one level.",
        "ob_start(); echo \"y\"; $s = ob_get_flush(); echo \"|$s\";   // => y|y",
    ),
    (
        "ob_flush",
        "Output buffering",
        "ob_flush(): null",
        "Writes the top buffer's contents one level down and leaves the level ACTIVE but cleared. The host's success flag is discarded, so calling it with no active buffer fails invisibly.",
        "ob_start(); echo \"a\"; ob_flush(); echo \"b\"; ob_end_clean();   // => a",
    ),
    (
        "ob_get_level",
        "Output buffering",
        "ob_get_level(): int",
        "The genuine nesting depth of the buffer stack.",
        "ob_start(); $n = ob_get_level(); ob_end_clean(); echo $n;   // => 1",
    ),
    (
        "ob_get_length",
        "Output buffering",
        "ob_get_length(): int|false",
        "The top buffer's length in BYTES, not characters. `false` when no buffer is active.",
        "ob_start(); echo \"abc\"; $n = ob_get_length(); ob_end_clean(); echo $n;   // => 3",
    ),
    (
        "flush",
        "Output buffering",
        "flush(): null",
        "DIVERGENCE: a complete no-op. It does not flush stdout and does not touch the buffer stack.",
        "var_dump(flush());   // => NULL",
    ),
    // ══ System and runtime environment (stdlib::system) ═════════════════════
    (
        "getenv",
        "System and runtime environment",
        "getenv(?string $name = null, bool $local_only = false): string|array|false",
        "Reads the REAL process environment. With no argument it returns every variable as an array; with a name, its value or `false`. The `$local_only` argument is accepted and ignored.",
        "putenv(\"PHP_REF_X=1\"); echo getenv(\"PHP_REF_X\");   // => 1",
    ),
    (
        "putenv",
        "System and runtime environment",
        "putenv(string $assignment): true",
        "Mutates the REAL process environment, so the change is visible to `getenv` and to spawned children. `\"K=V\"` sets and a bare name unsets. It always returns true, never false.",
        "putenv(\"PHP_REF_Y=2\"); echo getenv(\"PHP_REF_Y\");   // => 2",
    ),
    (
        "getmypid",
        "System and runtime environment",
        "getmypid(): int",
        "The real process id.",
        "var_dump(getmypid() > 0);   // => bool(true)",
    ),
    (
        "getmyuid",
        "System and runtime environment",
        "getmyuid(): int",
        "DIVERGENCE: a stub that always returns 0. The real user id is not queried.",
        "echo getmyuid();   // => 0",
    ),
    (
        "getmygid",
        "System and runtime environment",
        "getmygid(): int",
        "DIVERGENCE: a stub that always returns 0, sharing the `getmyuid` arm.",
        "echo getmygid();   // => 0",
    ),
    (
        "phpversion",
        "System and runtime environment",
        "phpversion(?string $extension = null): string",
        "DIVERGENCE: always the literal `\"8.3.0\"`. The `$extension` argument is never read, so a per-extension lookup returns the PHP version instead of `false`.",
        "echo phpversion();   // => 8.3.0",
    ),
    (
        "php_sapi_name",
        "System and runtime environment",
        "php_sapi_name(): string",
        "DIVERGENCE: always `\"cli\"`, however the runtime was entered — REPL, language server, or embedded.",
        "echo php_sapi_name();   // => cli",
    ),
    (
        "php_uname",
        "System and runtime environment",
        "php_uname(string $mode = \"a\"): string",
        "Built from the COMPILE-TIME target OS, the architecture, and the `HOSTNAME` environment variable (falling back to `localhost`) — not from a real `uname(2)`. Modes `s`, `n`, `m`, and `a` work; DIVERGENCE: `r` (release) and `v` (version) both return the EMPTY STRING.",
        "var_dump(php_uname(\"r\") === \"\");   // => bool(true)",
    ),
    (
        "memory_get_usage",
        "System and runtime environment",
        "memory_get_usage(bool $real_usage = false): int",
        "DIVERGENCE: a fixed 2097152 (2 MiB). phplang has no PHP-level allocator to report, so this is a stable conventional value rather than a measurement.",
        "echo memory_get_usage();   // => 2097152",
    ),
    (
        "memory_get_peak_usage",
        "System and runtime environment",
        "memory_get_peak_usage(bool $real_usage = false): int",
        "Shares the `memory_get_usage` arm, so peak and current are ALWAYS the same fixed 2097152.",
        "echo memory_get_peak_usage();   // => 2097152",
    ),
    (
        "gc_collect_cycles",
        "System and runtime environment",
        "gc_collect_cycles(): int",
        "DIVERGENCE: a no-op that collects nothing and always returns 0.",
        "echo gc_collect_cycles();   // => 0",
    ),
    (
        "gc_mem_caches",
        "System and runtime environment",
        "gc_mem_caches(): int",
        "DIVERGENCE: a no-op that frees nothing and always returns 0.",
        "echo gc_mem_caches();   // => 0",
    ),
    (
        "gc_enable",
        "System and runtime environment",
        "gc_enable(): bool",
        "DIVERGENCE: there is no collector state to toggle. It returns true, where PHP returns void.",
        "",
    ),
    (
        "gc_disable",
        "System and runtime environment",
        "gc_disable(): bool",
        "DIVERGENCE: a no-op returning true, where PHP returns void.",
        "",
    ),
    (
        "gc_enabled",
        "System and runtime environment",
        "gc_enabled(): bool",
        "DIVERGENCE: always true, unaffected by any preceding `gc_disable()`.",
        "gc_disable(); var_dump(gc_enabled());   // => bool(true)",
    ),
    (
        "extension_loaded",
        "System and runtime environment",
        "extension_loaded(string $extension): bool",
        "Checks a HARDCODED allow-list rather than what the standard library actually implements: `core`, `standard`, `json`, `pcre`, `mbstring`, `ctype`, `filter`, `date`, `hash`, `spl`, `tokenizer`. Everything else — `gmp` and `bcmath` included, though both are implemented — reports false.",
        "var_dump(extension_loaded(\"json\"), extension_loaded(\"gmp\"));   // => bool(true) bool(false)",
    ),
    (
        "sleep",
        "System and runtime environment",
        "sleep(int $seconds): int",
        "DIVERGENCE: it does NOT sleep. The argument is never read and it returns 0 immediately, keeping the runtime responsive and tests deterministic.",
        "echo sleep(3);   // => 0",
    ),
    (
        "usleep",
        "System and runtime environment",
        "usleep(int $microseconds): null",
        "DIVERGENCE: it does NOT sleep, returning null immediately.",
        "var_dump(usleep(1000));   // => NULL",
    ),
    (
        "time_nanosleep",
        "System and runtime environment",
        "time_nanosleep(int $seconds, int $nanoseconds): null",
        "DIVERGENCE: it does NOT sleep, and it shares the `usleep` arm — so it returns null where PHP returns true on success.",
        "var_dump(time_nanosleep(0, 1));   // => NULL",
    ),
    (
        "sys_getloadavg",
        "System and runtime environment",
        "sys_getloadavg(): array",
        "DIVERGENCE: always the fixed list `[0.0, 0.0, 0.0]`. No load average is queried.",
        "echo implode(\",\", sys_getloadavg());   // => 0,0,0",
    ),
    (
        "get_defined_constants",
        "System and runtime environment",
        "get_defined_constants(bool $categorize = false): array",
        "A real snapshot of the host's constant table as a flat name-to-value map, including anything `define()` has added. `$categorize` is never read, so the nested by-extension form is unavailable.",
        "define(\"PHP_REF_K\", 5); echo get_defined_constants()[\"PHP_REF_K\"];   // => 5",
    ),
    (
        "php_ini_loaded_file",
        "System and runtime environment",
        "php_ini_loaded_file(): false",
        "DIVERGENCE: always false — no php.ini is modeled.",
        "var_dump(php_ini_loaded_file());   // => bool(false)",
    ),
    (
        "get_include_path",
        "System and runtime environment",
        "get_include_path(): false",
        "DIVERGENCE: always false. PHP returns a string path list and reserves false for failure, so code doing string operations on the result will break.",
        "var_dump(get_include_path());   // => bool(false)",
    ),
    (
        "set_time_limit",
        "System and runtime environment",
        "set_time_limit(int $seconds): true",
        "DIVERGENCE: accepted and ignored — no execution timer is installed. Always returns true.",
        "var_dump(set_time_limit(30));   // => bool(true)",
    ),
    (
        "ignore_user_abort",
        "System and runtime environment",
        "ignore_user_abort(?bool $enable = null): true",
        "DIVERGENCE: accepted and ignored, storing no state, and returning true rather than PHP's previous-setting integer.",
        "",
    ),
    (
        "error_reporting",
        "System and runtime environment",
        "error_reporting(?int $error_level = null): int",
        "Read the error-reporting mask, or set it and return the PREVIOUS one. A diagnostic is displayed only when its `E_*` bit is set in the mask, so `error_reporting(0)` mutes every warning and notice. A missing argument and an explicit `null` both mean read-only. The mask starts at `E_ALL` unless `php -d error_reporting=…` seeded another. It cannot silence a COMPILE-time notice (`Using ${var} in strings …`), which was already decided when the file was read.",
        "error_reporting(E_ALL & ~E_WARNING); echo $undefined; echo \"quiet\";   // => quiet"
    ),
    (
        "ini_get",
        "System and runtime environment",
        "ini_get(string $option): string|false",
        "The current value of an ini setting, always as a STRING, or false when the engine has no such setting. `error_reporting` reads back what was last written to it — the decimal mask after `error_reporting()` or `-d`, but the RAW string after an `ini_set`, which is why `ini_set(\"error_reporting\", \"12abc\")` leaves `ini_get` reporting `\"12abc\"` while the mask is 12. The settings known here are PHP core plus `date` and `pcre` — the two extensions PHP 8 cannot be built without — carrying the values the reference reports for them with NO php.ini loaded, which is how each was established. DIVERGENCE: a name belonging to an optional extension the reference happened to be built with (`mysqli.default_host`), or one whose default is that build's install prefix (`extension_dir`, `include_path`), reports false rather than a value that would be wrong on another machine.",
        "var_dump(ini_get(\"memory_limit\"), ini_get(\"nosuch\"));   // => string(4) \"128M\" bool(false)",
    ),
    (
        "ini_set",
        "System and runtime environment",
        "ini_set(string $option, mixed $value): string|false",
        "Set an ini setting, returning its previous value as a string — or false, changing nothing, for a name the engine does not know (`ini_set` cannot invent settings) or one that is not runtime-changeable. That second group is PHP's `PHP_INI_PERDIR`/`PHP_INI_SYSTEM` set, which only a php.ini or `-d` may write while `ini_get` still reads it: `post_max_size`, `output_buffering`, `max_input_vars`, `expose_php`, `allow_url_fopen`, `arg_separator.input`, `disable_functions`, `hard_timeout`, `max_input_nesting_level`, `max_input_time`, `max_memory_limit`, `output_handler`, `register_argc_argv`, `zend.multibyte`, `zend.script_encoding`. Writing `error_reporting` also writes the mask, by ordinary string-to-int coercion and NOT the php.ini constant-expression scanner: `ini_set(\"error_reporting\", \"E_ALL & ~E_NOTICE\")` reads as 0 and mutes everything, exactly as in the reference. The symbolic spelling works only on the `php -d error_reporting=…` path. DIVERGENCE: per-setting VALUE validation is not modelled — the reference refuses a value a setting will not take, with a warning and false, but `date.timezone` needs a zone database this build does not carry and `memory_limit`'s refusal quotes the process's live memory usage, which is not a reproducible number. Such a write is accepted here.",
        "var_dump(ini_set(\"error_reporting\", \"0\"), ini_get(\"error_reporting\"));   // => string(5) \"30719\" string(1) \"0\"",
    ),
    (
        "spl_object_id",
        "System and runtime environment",
        "spl_object_id(object $object): int",
        "The raw heap handle. It is STABLE for the process lifetime — the object table is push-only, so an id is never recycled after the value dies. DIVERGENCE: it is not object-only — arrays, closures, generators, and resources all get an id, and a non-heap value returns 0 rather than raising a `TypeError`.",
        "$a = new stdClass; $b = new stdClass; var_dump(spl_object_id($a) !== spl_object_id($b));   // => bool(true)",
    ),
    (
        "spl_object_hash",
        "System and runtime environment",
        "spl_object_hash(object $object): string",
        "The same handle rendered as 32 zero-padded lowercase hex digits. DIVERGENCE: real PHP mixes in a per-process seed; this is trivially reversible to the id, so it must not be treated as opaque.",
        "echo strlen(spl_object_hash(new stdClass));   // => 32",
    ),
    (
        "func_get_args",
        "System and runtime environment",
        "func_get_args(): array",
        "The arguments AS PASSED to the enclosing call, read from a hidden frame variable. Variadic arguments ARE included; parameters filled from their defaults are not, matching PHP. DIVERGENCE: named arguments are appended in CALL order rather than placed at their parameter positions, and at global scope it returns an empty array rather than raising.",
        "function f() { return count(func_get_args()); } echo f(1, 2, 3);   // => 3",
    ),
    (
        "func_num_args",
        "System and runtime environment",
        "func_num_args(): int",
        "How many arguments the enclosing call received. DIVERGENCE: outside a function it silently reports 0 instead of raising PHP's error.",
        "function f() { return func_num_args(); } echo f(1, 2);   // => 2",
    ),
    (
        "func_get_arg",
        "System and runtime environment",
        "func_get_arg(int $position): mixed",
        "One argument of the enclosing call by position. DIVERGENCE: an out-of-range or negative position returns null instead of raising `ArgumentCountError` or `ValueError`.",
        "function f() { return func_get_arg(1); } echo f(\"a\", \"b\");   // => b",
    ),
    (
        "iterator_to_array",
        "System and runtime environment",
        "iterator_to_array(mixed $iterator, bool $preserve_keys = true): array",
        "Materializes an array, an `IteratorAggregate`, an object following the `Iterator` protocol, or a plain object's public properties. DIVERGENCE: a GENERATOR is not accepted — it is a distinct handle kind the iteration path does not recognize, so `iterator_to_array($gen)` silently returns an EMPTY array. A scalar does the same.",
        "echo count(iterator_to_array([1, 2, 3]));   // => 3",
    ),
    (
        "iterator_count",
        "System and runtime environment",
        "iterator_count(mixed $iterator): int",
        "Counts what `iterator_to_array` would produce, and carries the same gap: a generator counts as 0.",
        "echo iterator_count([1, 2]);   // => 2",
    ),
    (
        "iterator_apply",
        "System and runtime environment",
        "iterator_apply(mixed $iterator, callable $callback, ?array $args = null): int",
        "DIVERGENCE: the subject is materialized ONLY to obtain a length, then the callback is invoked that many times with the elements of `$args` — it never receives the current element and the iterator is never advanced. Iteration stops early when the callback returns falsey. A generator yields a length of 0, so the callback never runs.",
        "echo iterator_apply([1, 2, 3], fn() => true);   // => 3",
    ),
    // ══ Reflection (stdlib::reflection) ═════════════════════════════════════
    // The parser compiles `class`, `interface`, `trait`, and `enum` through ONE
    // path into ONE class table, and nothing records which keyword declared a
    // given entry. That single fact explains most of this chapter's divergences:
    // `class_exists` says true for all four, while the three specific predicates
    // are hardcoded `false`.
    (
        "class_exists",
        "Reflection",
        "class_exists(string $class, bool $autoload = true): bool",
        "A case-insensitive lookup in the host class table. DIVERGENCE: because interfaces, traits, and enums share that table, this returns TRUE for all of them — PHP returns false. `$autoload` is never read.",
        "interface I {} var_dump(class_exists(\"I\"));   // => bool(true)",
    ),
    (
        "interface_exists",
        "Reflection",
        "interface_exists(string $interface, bool $autoload = true): bool",
        "DIVERGENCE: hardcoded `false` — no argument is read. It therefore CONTRADICTS `instanceof` and `is_a()`, which do resolve the same interface through the class table's interface list. Test with `class_exists()` instead.",
        "interface I {} class C implements I {} $o = new C;\nvar_dump($o instanceof I, interface_exists(\"I\"));   // => bool(true) bool(false)",
    ),
    (
        "trait_exists",
        "Reflection",
        "trait_exists(string $trait, bool $autoload = true): bool",
        "DIVERGENCE: hardcoded `false`, sharing the `interface_exists` arm, even for a trait that was declared and successfully used by a class.",
        "trait T {} var_dump(trait_exists(\"T\"));   // => bool(false)",
    ),
    (
        "enum_exists",
        "Reflection",
        "enum_exists(string $enum, bool $autoload = true): bool",
        "DIVERGENCE: hardcoded `false`. This one is a choice rather than a missing capability — the class definition does record whether it is an enum, and the runtime consults that flag to synthesize `cases()`.",
        "enum E { case A; } var_dump(enum_exists(\"E\"));   // => bool(false)",
    ),
    (
        "get_class",
        "Reflection",
        "get_class(object $object = null): string",
        "The object's class name in its original DECLARED casing. A non-object is a `TypeError` — returning `false` was PHP 7's answer — and a boolean is named in that message by its VALUE (`true given`), not as `bool`. Called with NO argument it answers the enclosing `__CLASS__` and raises `Deprecated: Calling get_class() without arguments is deprecated`; outside a class that form is an `Error` instead.",
        "class Foo {} echo get_class(new Foo);   // => Foo",
    ),
    (
        "get_parent_class",
        "Reflection",
        "get_parent_class(object|string|null $object_or_class = null): string|false",
        "The parent's name in declared casing, or `false` when there is none. It accepts an object, a class-name string, or nothing.",
        "class A {} class B extends A {} echo get_parent_class(new B);   // => A",
    ),
    (
        "get_object_vars",
        "Reflection",
        "get_object_vars(object $object): array",
        "The properties of the instance the CALLING SCOPE may see, in insertion order — public ones from outside the class, everything from inside a method of it. A non-object is a `TypeError`, including an array.",
        "class C { public $a = 1; } print_r(get_object_vars(new C));   // => Array\\n(\\n    [a] => 1\\n)",
    ),
    (
        "get_class_methods",
        "Reflection",
        "get_class_methods(object|string $object_or_class): array",
        "The method names reachable through the class and its parents. DIVERGENCE: names come back LOWERCASED because the host stores them that way, private and protected methods are included, and an undeclared class yields an empty array rather than a `TypeError`.",
        "class C { function Hello() {} } echo get_class_methods(\"C\")[0];   // => hello",
    ),
    (
        "get_class_vars",
        "Reflection",
        "get_class_vars(string $class): array",
        "DIVERGENCE: a stub — an EMPTY array for any declared class, and `false` for an undeclared one where the reference raises `TypeError: get_class_vars(): Argument #1 ($class) must be a valid class name, <name> given`. Property defaults are stored as compiled chunks with no evaluator reachable from this module, so no names or values are reported.",
        "class C { public $a = 1; } print_r(get_class_vars(\"C\"));   // => Array\\n(\\n)",
    ),
    (
        "get_declared_classes",
        "Reflection",
        "get_declared_classes(): array",
        "Every name in the class table — which always includes the 25 prelude classes, plus any user interfaces, traits, and enums. DIVERGENCE: names are LOWERCASED and the order is the hash map's, not declaration order.",
        "var_dump(in_array(\"exception\", get_declared_classes()));   // => bool(true)",
    ),
    (
        "class_parents",
        "Reflection",
        "class_parents(object|string $object_or_class, bool $autoload = true): array|false",
        "A nearest-first `name => name` map of the ancestor chain in declared casing, or `false` when the subject is neither an object nor a declared class.",
        "class A {} class B extends A {} echo implode(\",\", class_parents(new B));   // => A",
    ),
    (
        "class_implements",
        "Reflection",
        "class_implements(object|string $object_or_class, bool $autoload = true): array|false",
        "DIVERGENCE: a stub returning an EMPTY array for any valid class or object. The interface list it would need IS populated and IS used by `instanceof` — this function simply never reads it.",
        "interface I {} class C implements I {} print_r(class_implements(new C));   // => Array\\n(\\n)",
    ),
    (
        "class_uses",
        "Reflection",
        "class_uses(object|string $object_or_class, bool $autoload = true): array|false",
        "DIVERGENCE: a stub returning an empty array for any valid class or object; nothing trait-related is consulted.",
        "",
    ),
    (
        "method_exists",
        "Reflection",
        "method_exists(object|string $object_or_class, string $method): bool",
        "Resolves the method through the class and its parents, comparing the name case-insensitively as PHP does.",
        "class C { function m() {} } var_dump(method_exists(\"C\", \"M\"));   // => bool(true)",
    ),
    (
        "property_exists",
        "Reflection",
        "property_exists(object|string $object_or_class, string $property): bool",
        "Checks the declared instance properties, walking parents, and — for an OBJECT subject — the live property list too. The name is compared case-SENSITIVELY. DIVERGENCE: static properties are never found, and a promoted constructor property is found on an instance but NOT on the class name, because promotion compiles to an assignment rather than a declaration.",
        "class C { public $a; } var_dump(property_exists(\"C\", \"a\"));   // => bool(true)",
    ),
    (
        "is_a",
        "Reflection",
        "is_a(mixed $object_or_class, string $class, bool $allow_string = false): bool",
        "True when the subject is, extends, or implements the named class, walking parents and interfaces transitively. `Throwable` is special-cased to match the `Exception` and `Error` roots even though no such class is declared. A string subject requires `$allow_string`.",
        "class A {} class B extends A {} var_dump(is_a(new B, \"A\"));   // => bool(true)",
    ),
    (
        "is_subclass_of",
        "Reflection",
        "is_subclass_of(mixed $object_or_class, string $class, bool $allow_string = true): bool",
        "The same ancestry walk as `is_a`, but the subject's own class is excluded first, so only strict ancestors and interfaces count.",
        "class A {} class B extends A {}\nvar_dump(is_subclass_of(new B, \"A\"), is_subclass_of(new A, \"A\"));   // => bool(true) bool(false)",
    ),
    // ══ Runtime and diagnostics (stdlib::runtime) ═══════════════════════════
    // Most of this module is deliberately inert: phplang has no error-handler
    // chain, no shutdown queue, and no autoload chain, so the registration
    // functions accept a callback and discard it. The four that do real work are
    // `assert`, `trigger_error`/`user_error`, `error_log`, and `class_alias`.
    (
        "assert",
        "Runtime and diagnostics",
        "assert(mixed $assertion, mixed $description = null): bool",
        "Evaluates the assertion for truthiness and RETURNS it. DIVERGENCE: this inverts PHP 8's contract — PHP always returns true and throws `AssertionError` on failure, whereas here `assert(false)` simply returns false and throws nothing. `$description` is never read.",
        "var_dump(assert(1 === 1), assert(false));   // => bool(true) bool(false)",
    ),
    (
        "assert_options",
        "Runtime and diagnostics",
        "assert_options(int $option, mixed $value = null): int",
        "DIVERGENCE: a stub that always returns 0 and stores nothing. No argument is read.",
        "echo assert_options(1);   // => 0",
    ),
    (
        "trigger_error",
        "Runtime and diagnostics",
        "trigger_error(string $message, int $error_level = E_USER_NOTICE): bool",
        "Prints `\"<label>: <message>\"` to STDERR and returns true. The label is `Fatal error` for `E_USER_ERROR`, `Warning` for `E_USER_WARNING`, `Deprecated` for `E_USER_DEPRECATED`, and `Notice` for everything else. DIVERGENCE: `E_USER_ERROR` does NOT halt — execution continues with the next statement.",
        "trigger_error(\"careful\", E_USER_WARNING); echo \"still running\";   // => still running",
    ),
    (
        "user_error",
        "Runtime and diagnostics",
        "user_error(string $message, int $error_level = E_USER_NOTICE): bool",
        "The alias of `trigger_error`, sharing its match arm and its non-halting `E_USER_ERROR` behaviour.",
        "",
    ),
    (
        "error_log",
        "Runtime and diagnostics",
        "error_log(string $message, int $message_type = 0, string $destination = \"\"): bool",
        "With `$message_type` 3 AND a destination it really appends the raw message bytes to that file — no timestamp and no trailing newline are added. Every other combination writes the message to stderr and returns true. The email and SAPI-logger message types are not implemented.",
        "error_log(\"note\", 3, \"/tmp/php_ref_log.txt\"); echo file_get_contents(\"/tmp/php_ref_log.txt\");   // => note",
    ),
    (
        "debug_backtrace",
        "Runtime and diagnostics",
        "debug_backtrace(int $options = 0, int $limit = 0): array",
        "DIVERGENCE: a stub that always returns an empty array. No call stack is captured, so neither argument has any effect.",
        "echo count(debug_backtrace());   // => 0",
    ),
    (
        "debug_print_backtrace",
        "Runtime and diagnostics",
        "debug_print_backtrace(int $options = 0, int $limit = 0): null",
        "DIVERGENCE: a stub that prints nothing and returns null.",
        "var_dump(debug_print_backtrace());   // => NULL",
    ),
    (
        "set_error_handler",
        "Runtime and diagnostics",
        "set_error_handler(?callable $callback, int $error_levels = E_ALL): null",
        "DIVERGENCE: accepted and discarded. There is no error-handler chain, so the callback is NEVER invoked; it returns null, which reads as \"no previous handler\".",
        "var_dump(set_error_handler(fn() => true));   // => NULL",
    ),
    (
        "set_exception_handler",
        "Runtime and diagnostics",
        "set_exception_handler(?callable $callback): null",
        "DIVERGENCE: shares the `set_error_handler` arm — the callback is discarded, so an uncaught exception still ends the program with the standard `Fatal error: Uncaught …` block instead of being routed to the handler.",
        "",
    ),
    (
        "restore_error_handler",
        "Runtime and diagnostics",
        "restore_error_handler(): bool",
        "DIVERGENCE: a no-op that always returns true, since no handler was ever stored.",
        "var_dump(restore_error_handler());   // => bool(true)",
    ),
    (
        "restore_exception_handler",
        "Runtime and diagnostics",
        "restore_exception_handler(): bool",
        "DIVERGENCE: a no-op returning true, sharing the `restore_error_handler` arm.",
        "",
    ),
    (
        "register_shutdown_function",
        "Runtime and diagnostics",
        "register_shutdown_function(callable $callback, mixed ...$args): null",
        "DIVERGENCE: the callback is accepted and SILENTLY DROPPED — no shutdown queue exists, so it never runs. Put cleanup in a `finally` block instead.",
        "var_dump(register_shutdown_function(fn() => print(\"never\")));   // => NULL",
    ),
    (
        "spl_autoload_register",
        "Runtime and diagnostics",
        "spl_autoload_register(?callable $callback = null, bool $throw = true, bool $prepend = false): bool",
        "DIVERGENCE: a no-op returning true. There is no autoload chain and no `include`, so every class must be declared in the source that uses it.",
        "var_dump(spl_autoload_register(fn($c) => null));   // => bool(true)",
    ),
    (
        "spl_autoload_unregister",
        "Runtime and diagnostics",
        "spl_autoload_unregister(callable $callback): bool",
        "DIVERGENCE: a no-op returning true.",
        "",
    ),
    (
        "get_defined_vars",
        "Runtime and diagnostics",
        "get_defined_vars(): array",
        "DIVERGENCE: a stub that always returns an empty array — no scope enumerator is exposed to the standard library. Use `compact()` with explicit names instead.",
        "$x = 1; echo count(get_defined_vars());   // => 0",
    ),
    (
        "class_alias",
        "Runtime and diagnostics",
        "class_alias(string $class, string $alias, bool $autoload = true): bool",
        "DIVERGENCE: it reports whether `$class` exists and REGISTERS NOTHING — `$alias` is never read. A true return is therefore misleading: instantiating the alias afterwards still fails.",
        "class C {} var_dump(class_alias(\"C\", \"D\"), class_exists(\"D\"));   // => bool(true) bool(false)",
    ),
    // ══ Callables (stdlib::callable) ════════════════════════════════════════
    (
        "call_user_func",
        "Callables",
        "call_user_func(callable $callback, mixed ...$args): mixed",
        "Invokes any of the five accepted callable forms with the remaining arguments: a `Closure`, a `\"function\"` name, a `\"Class::method\"` string, `[$obj, \"method\"]`, or `[\"Class\", \"method\"]`. Method names resolve case-insensitively.",
        "echo call_user_func(\"strtoupper\", \"hi\");   // => HI",
    ),
    (
        "call_user_func_array",
        "Callables",
        "call_user_func_array(callable $callback, array $args): mixed",
        "Spreads the array's VALUES in order, discarding keys — so named-argument spreading is not modelled. A non-array second argument passes no arguments rather than raising. This is also what first-class callable syntax `f(...)` desugars to.",
        "echo call_user_func_array(\"max\", [1, 5, 3]);   // => 5",
    ),
    (
        "function_exists",
        "Callables",
        "function_exists(string $function): bool",
        "Exact for USER functions, which are looked up in the real function table. DIVERGENCE: builtin coverage is a hand-maintained allow-list of 314 names, so it is wrong in both directions — an implemented function absent from the list (`assert`, `error_log`, `class_alias`, `debug_backtrace`, `filter_has_var`, …) reports false, while `interface_exists`, `trait_exists`, and `enum_exists` report true even though all three are hardcoded stubs.",
        "function myFn() {} var_dump(function_exists(\"myFn\"), function_exists(\"strlen\"));   // => bool(true) bool(true)",
    ),
    // ══ Constants (stdlib::constants) ═══════════════════════════════════════
    (
        "define",
        "Constants",
        "define(string $constant_name, mixed $value, bool $case_insensitive = false): bool",
        "Inserts a constant, returning false when the name already exists — including any of the 156 predefined ones. DIVERGENCE: a failed redefinition prints no warning, the third argument is never read, and an omitted value stores null.",
        "define(\"PHP_REF_C\", 5); echo PHP_REF_C;   // => 5",
    ),
    (
        "defined",
        "Constants",
        "defined(string $constant_name): bool",
        "Whether a constant of that exact name exists. Lookup is case-SENSITIVE, unlike class and function lookup, so `define(\"FOO\", 1)` leaves `defined(\"foo\")` false.",
        "define(\"PHP_REF_D\", 1); var_dump(defined(\"PHP_REF_D\"), defined(\"php_ref_d\"));   // => bool(true) bool(false)",
    ),
    (
        "constant",
        "Constants",
        "constant(string $name): mixed",
        "The value of the named constant. An UNDEFINED name throws `Error: Undefined constant \"<name>\"`, catchable, exactly as a bare reference to the same name does.",
        "echo constant(\"NOPE\");   // => NOPE",
    ),
    // ══ Input filtering (stdlib::filter) ════════════════════════════════════
    (
        "filter_var",
        "Input filtering",
        "filter_var(mixed $value, int $filter = FILTER_DEFAULT, array|int $options = 0): mixed",
        "Applies one filter. `$options` may be a bare flags bitmask or a `['flags' => …, 'options' => …]` map. A failing VALIDATOR returns false, or null when `FILTER_NULL_ON_FAILURE` is set; sanitizers cannot fail. DIVERGENCE: an ARRAY value fails every filter; `FILTER_CALLBACK`, `FILTER_SANITIZE_ENCODED`, and `FILTER_SANITIZE_ADD_SLASHES` are unimplemented and silently return the raw string; and `options['default']` is never consulted.",
        "var_dump(filter_var(\"42\", FILTER_VALIDATE_INT), filter_var(\"x\", FILTER_VALIDATE_INT));   // => int(42) bool(false)",
    ),
    (
        "filter_var_array",
        "Input filtering",
        "filter_var_array(array $array, array|int $options = FILTER_DEFAULT, bool $add_empty = true): array|false",
        "Filters many fields at once. With a definition array the output is keyed by the DEFINITION — data keys it does not mention are dropped, and fields missing from the data become null. With a bare id, that filter applies to every field. A non-array subject returns false. DIVERGENCE: `$add_empty` is never read, so missing fields are always emitted.",
        "print_r(filter_var_array([\"a\" => \"1\"], [\"a\" => FILTER_VALIDATE_INT]));   // => Array\\n(\\n    [a] => 1\\n)",
    ),
    (
        "filter_has_var",
        "Input filtering",
        "filter_has_var(int $input_type, string $var_name): bool",
        "DIVERGENCE: hardcoded `false`, reading neither argument. phplang is a standalone runtime with no request context, so there is no `$_GET` or `$_POST` to consult.",
        "var_dump(filter_has_var(INPUT_GET, \"q\"));   // => bool(false)",
    ),
    // APPEND_HERE
];