Still looking for a cleaner way to do this than a stack backtrace, - TopicsExpress



          

Still looking for a cleaner way to do this than a stack backtrace, but this is pretty cool: public function populateThisLayer($data) { if(is_object($data)) { $data = (array) $data; } $bt = debug_backtrace(); $calledFrom = $bt[1][class]; $reflect = new \ReflectionClass($calledFrom); $props = $reflect->getProperties(); foreach($props as $_p) { $_k = $_p->name; if(($_p->class == $calledFrom) && isset($data[$_k])) { $this->$_k = (is_numeric($data[$_k])) ? floatval($data[$_k]) : $data[$_k]; } } }
Posted on: Wed, 23 Jul 2014 20:10:45 +0000

Trending Topics



Recently Viewed Topics




© 2015