Skip to content

Commit 256f405

Browse files
bug #39794 Dont allow unserializing classes with a destructor - 4.4 (jderusse)
This PR was merged into the 4.4 branch. Discussion ---------- Dont allow unserializing classes with a destructor - 4.4 | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Prevent destructors with side-effects from being unserialized Commits ------- 955395c999 Dont allow unserializing classes with a destructor - 4.4
2 parents 11019fc + d0fdb72 commit 256f405

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

Chunk/ErrorChunk.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ public function didThrow(): bool
115115
return $this->didThrow;
116116
}
117117

118+
public function __sleep()
119+
{
120+
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
121+
}
122+
123+
public function __wakeup()
124+
{
125+
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
126+
}
127+
118128
public function __destruct()
119129
{
120130
if (!$this->didThrow) {

CurlHttpClient.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,16 @@ public function reset()
362362
}
363363
}
364364

365+
public function __sleep()
366+
{
367+
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
368+
}
369+
370+
public function __wakeup()
371+
{
372+
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
373+
}
374+
365375
public function __destruct()
366376
{
367377
$this->reset();

HttplugClient.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,16 @@ public function createUri($uri): UriInterface
218218
throw new \LogicException(sprintf('You cannot use "%s()" as the "nyholm/psr7" package is not installed. Try running "composer require nyholm/psr7".', __METHOD__));
219219
}
220220

221+
public function __sleep()
222+
{
223+
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
224+
}
225+
226+
public function __wakeup()
227+
{
228+
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
229+
}
230+
221231
public function __destruct()
222232
{
223233
$this->wait();

Response/ResponseTrait.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ public function toStream(bool $throw = true)
199199
return $stream;
200200
}
201201

202+
public function __sleep()
203+
{
204+
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
205+
}
206+
207+
public function __wakeup()
208+
{
209+
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
210+
}
211+
202212
/**
203213
* Closes the response and all its network handles.
204214
*/

0 commit comments

Comments
 (0)