A
A
Anykin2016-07-03 17:55:22
Zend Framework
Anykin, 2016-07-03 17:55:22

Do I need to delete temporary variables in the hydrator?

If you need to hydrate many objects, do you need to delete variables?

public function hydrate(array $data, $object)
    {
        if (!$object instanceof PostInterface) {
            return $object;
        }
        
        $tagString = $data['tagsString'];
        if (empty($tagString)) {
            return $object;
        }
        
        $tags = explode(",", $tagString);
        $itemList = $object->getTags();
        $item = $itemList->offsetGet(0);

        for($i=0, $countTags = count($tags); $i < $countTags; $i++)
        {
            parent::hydrate(array('title' => $tags[$i]), $tagClone = clone $item);
            $itemList->offsetSet($i, $tagClone);
        }
        unset($itemList);
        unset($tagClone);
        unset($item);
        unset($countTags);
        unset($tags);
        unset($tagString);
        
        return $object;
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question