Skip to content

Commit

Permalink
Only assign values properties to properties when they exist
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Feb 25, 2018
1 parent b057013 commit c280e48
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace WyriHaximus;

use Exception;
use ReflectionClass;
use ReflectionProperty;
use Throwable;

Expand Down Expand Up @@ -58,6 +59,10 @@ function throwable_decode($json)

$throwable = new $json['class']();
foreach ($properties as $key) {
if (!(new ReflectionClass($json['class']))->hasProperty($key)) {
continue;
}

$property = new ReflectionProperty($json['class'], $key);
$property->setAccessible(true);
$property->setValue($throwable, $json[$key]);
Expand Down

0 comments on commit c280e48

Please sign in to comment.