1--TEST-- 2pg_copy_from with an iterable 3--EXTENSIONS-- 4pgsql 5--SKIPIF-- 6<?php include("inc/skipif.inc"); ?> 7--FILE-- 8<?php 9 10include('inc/config.inc'); 11$table_name = "table_copy_iter"; 12 13$db = pg_connect($conn_str); 14pg_query($db, "CREATE TABLE {$table_name} (num int)"); 15 16$iter = new class implements Iterator { 17 var $count = 0; 18 var $values = Array(1,2,3); 19 20 public function next(): void { 21 ++$this->count; 22 } 23 24 public function rewind(): void { 25 $this->count = 0; 26 } 27 28 public function current(): int { 29 return $this->values[$this->count]; 30 } 31 32 public function key(): int { 33 return $this->count; 34 } 35 36 public function valid(): bool { 37 return $this->count < count($this->values); 38 } 39}; 40 41try { 42 pg_copy_from($db, $table_name, new stdClass()); 43} catch (\TypeError $e) { 44 echo $e->getMessage() . PHP_EOL; 45} 46var_dump(pg_copy_from($db, $table_name, $iter)); 47$res = pg_query($db, "SELECT FROM {$table_name}"); 48var_dump(count(pg_fetch_all($res)) == 3); 49 50?> 51--CLEAN-- 52<?php 53include('inc/config.inc'); 54$table_name = "table_copy_iter"; 55 56$db = pg_connect($conn_str); 57pg_query($db, "DROP TABLE IF EXISTS {$table_name}"); 58?> 59--EXPECT-- 60pg_copy_from(): Argument #3 ($rows) must be of type Traversable|array, stdClass given 61bool(true) 62bool(true) 63