Skip to content

Commit 9430bc8

Browse files
Adrian Föderdbu
authored andcommitted
[BUGFIX] Prevent null-check on get_class occurrence
Since PHP's get_class() has the unlucky ability to pass null (resp. nothing) as argument and considers the calling class in this case which leads to side effects; and PHP 7.2 doesn't allow null values at all anymore; this change fixes a case where this might happen as of the interface since a null object can be passed.
1 parent 10e49f6 commit 9430bc8

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

PublishWorkflow/Voter/PublishableVoter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function supportsClass($class)
4949
*/
5050
public function vote(TokenInterface $token, $object, array $attributes)
5151
{
52-
if (!$this->supportsClass(get_class($object))) {
52+
if ($object === null || !$this->supportsClass(get_class($object))) {
5353
return self::ACCESS_ABSTAIN;
5454
}
5555

Tests/Unit/PublishWorkflow/Voter/PublishableVoterTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,14 @@ public function testUnsupportedClass()
100100
);
101101
$this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $result);
102102
}
103+
104+
public function testNullObject()
105+
{
106+
$result = $this->voter->vote(
107+
$this->token,
108+
null,
109+
array()
110+
);
111+
$this->assertEquals(VoterInterface::ACCESS_ABSTAIN, $result);
112+
}
103113
}

0 commit comments

Comments
 (0)