Skip to content

Instantly share code, notes, and snippets.

@primitive-type
Last active December 15, 2015 06:19
Show Gist options
  • Save primitive-type/5215709 to your computer and use it in GitHub Desktop.
Save primitive-type/5215709 to your computer and use it in GitHub Desktop.
Generic exchangeArray() method in a parent class
<?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