diff --git a/DataMapper/DataMapper.php b/DataMapper/DataMapper.php index 591860d..8f2c5b1 100644 --- a/DataMapper/DataMapper.php +++ b/DataMapper/DataMapper.php @@ -148,9 +148,13 @@ public function asClass(?string $class = null): self /** * @inheritDoc */ - public function asObject(): self + public function asObject(?object $obj = null): self { - $this->getStatement()->setFetchMode(PDO::FETCH_OBJ); + if (null !== $obj) { + $this->getStatement()->setFetchMode(PDO::FETCH_INTO, $obj); + } else { + $this->getStatement()->setFetchMode(PDO::FETCH_OBJ); + } return $this; } diff --git a/DataMapper/Interfaces/DataMapperInterface.php b/DataMapper/Interfaces/DataMapperInterface.php index 3bb1189..1571c88 100644 --- a/DataMapper/Interfaces/DataMapperInterface.php +++ b/DataMapper/Interfaces/DataMapperInterface.php @@ -82,10 +82,11 @@ public function numRows(): int; public function asClass(?string $class = null): self; /** + * @param null|object $obj * @return self * @throws DataMapperException */ - public function asObject(): self; + public function asObject(?object $obj = null): self; /** * @return self