mirror of
https://github.com/php/php-src.git
synced 2025-01-10 21:14:37 +08:00
Fix clone + add tests
This commit is contained in:
parent
ac1204b7eb
commit
1c23174d9d
@ -397,7 +397,13 @@ static zend_object_value spl_heap_object_new_ex(zend_class_entry *class_type, sp
|
||||
intern->ce_get_iterator = other->ce_get_iterator;
|
||||
|
||||
if (clone_orig) {
|
||||
int i;
|
||||
intern->heap = spl_ptr_heap_clone(other->heap TSRMLS_CC);
|
||||
for (i = 0; i < intern->heap->count; ++i) {
|
||||
if (intern->heap->elements[i]) {
|
||||
Z_ADDREF_P((zval *)intern->heap->elements[i]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
intern->heap = other->heap;
|
||||
}
|
||||
|
@ -32,7 +32,9 @@ $b = 4;
|
||||
$h->insert($b);
|
||||
$b = 5;
|
||||
|
||||
$h2 = clone $h;
|
||||
echo $h->extract()."\n";
|
||||
echo $h2->extract()."\n";
|
||||
?>
|
||||
===DONE===
|
||||
<?php exit(0); ?>
|
||||
@ -47,4 +49,5 @@ Exception: Can't extract from an empty heap
|
||||
0
|
||||
--
|
||||
4
|
||||
4
|
||||
===DONE===
|
||||
|
31
ext/spl/tests/heap_011.phpt
Normal file
31
ext/spl/tests/heap_011.phpt
Normal file
@ -0,0 +1,31 @@
|
||||
--TEST--
|
||||
SPL: SplHeap with overriden compare()
|
||||
--FILE--
|
||||
<?php
|
||||
class SplMinHeap2 extends SplMinHeap {
|
||||
public function compare($a, $b) {
|
||||
return -parent::compare($a,$b);
|
||||
}
|
||||
}
|
||||
$h = new SplMinHeap2();
|
||||
$h->insert(1);
|
||||
$h->insert(6);
|
||||
$h->insert(5);
|
||||
$h->insert(2);
|
||||
var_dump($h->top());
|
||||
|
||||
class SplMaxHeap2 extends SplMaxHeap {
|
||||
public function compare($a, $b) {
|
||||
return -parent::compare($a,$b);
|
||||
}
|
||||
}
|
||||
$h = new SplMaxHeap2();
|
||||
$h->insert(1);
|
||||
$h->insert(6);
|
||||
$h->insert(5);
|
||||
$h->insert(2);
|
||||
var_dump($h->top());
|
||||
?>
|
||||
--EXPECT--
|
||||
int(6)
|
||||
int(1)
|
Loading…
Reference in New Issue
Block a user