Skip to content

Commit bc37d50

Browse files
mrclaysebastianbergmann
authored andcommitted
Allow serializing stdClass objects
Fixes sebastianbergmann#5
1 parent 23af31f commit bc37d50

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

src/Snapshot.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@ private function canBeSerialized($variable)
406406
return !is_resource($variable);
407407
}
408408

409+
if ($variable instanceof \stdClass) {
410+
return true;
411+
}
412+
409413
$class = new ReflectionClass($variable);
410414

411415
do {

tests/SnapshotTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function testStaticAttributes()
3131
$expected = array('SebastianBergmann\GlobalState\TestFixture\SnapshotClass' => array(
3232
'string' => 'snapshot',
3333
'arrayObject' => new ArrayObject(array(1, 2, 3)),
34+
'stdClass' => new \stdClass(),
3435
));
3536

3637
$this->assertEquals($expected, $snapshot->staticAttributes());

tests/_fixture/SnapshotClass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class SnapshotClass
2323
private static $arrayObject;
2424
private static $snapshotDomDocument;
2525
private static $resource;
26+
private static $stdClass;
2627

2728
public static function init()
2829
{
@@ -31,5 +32,6 @@ public static function init()
3132
self::$arrayObject = new ArrayObject(array(1, 2, 3));
3233
self::$snapshotDomDocument = new SnapshotDomDocument();
3334
self::$resource = fopen('php://memory', 'r');
35+
self::$stdClass = new \stdClass();
3436
}
3537
}

0 commit comments

Comments
 (0)