xref: /PHP-8.2/ext/standard/tests/array/bug45312.phpt (revision f8d79582)
1--TEST--
2Bug #45312 (Segmentation fault on second request for array functions)
3--FILE--
4<?php
5class cr {
6    private $priv_member;
7    function __construct($val) {
8        $this->priv_member = $val;
9    }
10    static function comp_func_cr($a, $b) {
11        if ($a->priv_member === $b->priv_member) return 0;
12        return ($a->priv_member > $b->priv_member) ? 1 : -1;
13    }
14    static function comp_func_cr2($a, $b) {
15        echo ".";
16        if ($a->priv_member === $b->priv_member) return 0;
17        return ($a->priv_member < $b->priv_member) ? 1 : -1;
18    }
19    function dump() {
20        echo $this->priv_member . "\n";
21    }
22}
23$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),);
24$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),);
25$result = array_udiff_assoc($a, $b, array("cr", "comp_func_cr"));
26foreach($result as $val) {
27    $val->dump();
28}
29$result = array_udiff_assoc($a, $b, array("cr", "comp_func_cr2"));
30foreach($result as $val) {
31    $val->dump();
32}
33?>
34--EXPECT--
359
3612
3723
38....9
3912
4023
41