Skip to content

Commit

Permalink
base64_decode returns false only in strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-tekiela committed Jun 6, 2023
1 parent 3fc3bff commit cee6672
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion resources/functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@
'BadMethodCallException::getPrevious' => ['(?Throwable)|(?BadMethodCallException)'],
'BadMethodCallException::getTrace' => ['array{function:string,line?:int,file?:string,class?:class-string,type?:\'::\'|\'->\',args?:mixed[],object?:object}'],
'BadMethodCallException::getTraceAsString' => ['string'],
'base64_decode' => ['string|false', 'str'=>'string', 'strict='=>'bool'],
'base64_decode' => ['string', 'str'=>'string', 'strict='=>'false'],
'base64_decode\'1' => ['string|false', 'str'=>'string', 'strict='=>'true'],
'base64_encode' => ['string', 'str'=>'string'],
'base_convert' => ['string', 'number'=>'string', 'frombase'=>'int', 'tobase'=>'int'],
'basename' => ['string', 'path'=>'string', 'suffix='=>'string'],
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-9274.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/extract.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/image-size.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/base64_decode.php');
}

/**
Expand Down
21 changes: 21 additions & 0 deletions tests/PHPStan/Analyser/data/base64_decode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php declare(strict_types = 1);

namespace Base64Decode;

use function PHPStan\Testing\assertType;

class Foo
{

public function nonStrictMode(string $string): void
{
assertType('string', base64_decode($string));
assertType('string', base64_decode($string, false));
}

public function strictMode(string $string): void
{
assertType('string|false', base64_decode($string, true));
}

}

0 comments on commit cee6672

Please sign in to comment.