Skip to content

Instantly share code, notes, and snippets.

@vikbert
Last active April 6, 2019 07:12
Show Gist options
  • Select an option

  • Save vikbert/b374aa84221dd72f16eb98ba8c50abfa to your computer and use it in GitHub Desktop.

Select an option

Save vikbert/b374aa84221dd72f16eb98ba8c50abfa to your computer and use it in GitHub Desktop.
[PHP God Bad] PHP snippets #php, #snippet

convert object toArray

public function toArray(): array
{
  $properties = get_object_vars($this);
  $output = [];
  foreach ($properties as $name => $value) {
    $output[ucfirst($name)] = $value;
  }

  return $output;
}

PHP7.1

$greet = $foo['bar'] ?? 'hello world';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment