Building an object to array hydrator

This recipe is the converse of the Creating an array to object hydrator recipe. In this case, we need to pull values from object properties and return an associative array where the key will be the column name.

How to do it...

  1. For this illustration we will build upon the Application\Generic\Hydrator\GetSet class defined in the previous recipe:
    namespace Application\Generic\Hydrator;
    class GetSet
    {
      // code
    }
  2. After the hydrate() method defined in the previous recipe, we define an extract() method, which takes an object as an argument. The logic is similar to that used with hydrate(), except this time we're searching for getXXX() methods. Again, preg_match() is used to match the method prefix and its suffix, which ...

Get PHP 7 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.