Last active
December 15, 2015 06:19
-
-
Save primitive-type/5215709 to your computer and use it in GitHub Desktop.
Generic exchangeArray() method in a parent class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class GenericSerializable | |
{ | |
public $id = null; | |
public $name = 'genericThing'; | |
public $someProperties = array(); | |
public function exchangeArray($data) | |
{ | |
// Includes all public variables of children classes | |
$classVars = get_class_vars(get_class($this)); | |
foreach ($classVars as $key => $value) { | |
$this->{$key} = (isset($data[$key])) ? $data[$key] : null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment