src/Entity/Entity.php
public function copy($save = false)
    {
        $object_class = get_class($this);

        /** @var EntityInterface $copy */
        $copy = new $object_class($this->connection, $this->pool, $this->log);

        foreach ($this->getFields() as $field) {
            if ($this->isPrimaryKey($field)) {
                continue;
            }

            $copy->setFieldValue($field, $this->getFieldValue($field));
        }

        if ($save) {
            $copy->save();
        }

        return $copy;
    }
public function copy($save = false)
    {
        $object_class = get_class($this);

        /** @var EntityInterface $copy */
        $copy = new $object_class($this->connection, $this->pool, $this->log);

        foreach ($this->getFields() as $field) {
            if ($this->isPrimaryKey($field)) {
                continue;
            }

            $copy->setFieldValue($field, $this->getFieldValue($field));
        }

        if ($save) {
            $copy->save();
        }

        return $copy;
    }
Create a copy of this object and optionally save it.

@param  bool   $save
@return object