mirror of
https://github.com/danog/math.git
synced 2024-11-27 04:14:40 +01:00
unserialize() now throws an exception when called directly
This guarantees that immutability cannot be broken.
This commit is contained in:
parent
53a61b46a7
commit
908e73e8e4
@ -670,6 +670,10 @@ class BigDecimal implements \Serializable
|
||||
*/
|
||||
public function unserialize($value)
|
||||
{
|
||||
if ($this->value !== null || $this->scale !== null) {
|
||||
throw new \LogicException('unserialize() is an internal function, it must not be called directly.');
|
||||
}
|
||||
|
||||
list ($value, $scale) = explode(':', $value);
|
||||
|
||||
$this->value = $value;
|
||||
|
@ -562,16 +562,20 @@ class BigInteger implements \Serializable
|
||||
/**
|
||||
* This method is required by interface Serializable and MUST NOT be accessed directly.
|
||||
*
|
||||
* Accessing this method directly would bypass consistency checks and break immutability.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function unserialize($value)
|
||||
{
|
||||
if ($this->value !== null) {
|
||||
throw new \LogicException('unserialize() is an internal function, it must not be called directly.');
|
||||
}
|
||||
|
||||
$this->value = $value;
|
||||
}
|
||||
}
|
||||
|
@ -1956,4 +1956,12 @@ class BigDecimalTest extends AbstractTestCase
|
||||
|
||||
$this->assertBigDecimalEquals($value, $scale, unserialize(serialize($number)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
public function testDirectCallToUnserialize()
|
||||
{
|
||||
BigDecimal::zero()->unserialize('123:0');
|
||||
}
|
||||
}
|
||||
|
@ -1577,4 +1577,12 @@ class BigIntegerTest extends AbstractTestCase
|
||||
|
||||
$this->assertBigIntegerEquals($value, unserialize(serialize($number)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
public function testDirectCallToUnserialize()
|
||||
{
|
||||
BigInteger::zero()->unserialize('123');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user