title: Accessing object properties in PHP
body: <p>I am trying to access properties of a custom object in PHP:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Classes;
  
  use Illuminate\Database\Eloquent\Model;
  
  class AED extends Model {
  
      protected $table = 'aeds';
      protected $fillable = ['owner', 'street', 'postal_code', 'locality', 'latitude', 'longitude', 'annotation_type'];
      public $timestamps = true;
  
      public $id;
      public $owner;
      public $object;
      public $street;
      public $postalCode;
      public $locality;
      public $latitude;
      public $longitude;
      public $annotation_type;
      public $distance;
  
      public function set($data) {
          foreach ($data as $key =&gt; $value) {
              if(property_exists($this, $key)) {
                  $this-&gt;$key = $value;
              }
          }
      }
  }
  </code></pre>
  
  <p>The code to access these properties:</p>
  
  <pre><code>&lt;?php
  namespace App\Transformer;
  
  use App\Classes\AED;
  use League\Fractal\TransformerAbstract;
  
  
  class AEDTransformer extends TransformerAbstract {
      public function transform(AED $aed) {
          return [
              'data' =&gt; $aed-&gt;owner
          ];
      }
  }
  </code></pre>
  
  <p>When I call the function, I get this as a response:</p>
  
  <pre><code>{
  data: [
  {
  data: null
  }
  ],
  meta: "TestMeta"
  }
  </code></pre>
  
  <p>The strange thing is, when I just var_dump the object I get the full info:</p>
  
  <pre><code>...
   protected 'original' =&gt; 
      array (size=11)
        'id' =&gt; int 1
        'owner' =&gt; string 'Owner 1' (length=7)
        'object' =&gt; string 'Object 1' (length=8)
        'street' =&gt; string 'Street 1' (length=8)
        'postal_code' =&gt; string '11111' (length=5)
        'locality' =&gt; string 'Locality 1' (length=10)
        'latitude' =&gt; float 100
        'longitude' =&gt; float 100
        'annotation_type' =&gt; string '1' (length=1)
        'created_at' =&gt; string '0000-00-00 00:00:00' (length=19)
        'updated_at' =&gt; string '0000-00-00 00:00:00' (length=19)
  ...
  </code></pre>
  
  <p>So the data can be taken from the database as expected and is being received as well. Why does the accessing not work then and I receive a "null".</p>
  
  <p>I use the "set" method inside the custom function here:</p>
  
  <pre><code>class AEDHelper {
      static public function searchAED($position) {
          $var1 = $position['latitude'];
          $var2 = $position['longitude'];
          $var3 = $position['latitude'];
  
          $queryResults = DB::select(DB::raw("SQLCODE"));
          $results = [];
  
          foreach ($queryResults as $results) {
              $aed = new AED();
              $aed-&gt;set($results);
              $results[] = $aed;
          }
  
          return $results;
  
      }
  </code></pre>
  
  <p>Here I create a new AED() instance. So I would guess I need to define the object properties therefore as now not Eloquent will be used but a custom AED class needs to be instantiated for displaying SQL results.</p>
  
  <p>Best</p>