Skip to content

Commit bf205bb

Browse files
committed
Wrong parameters for Exception([string $message [, long $code [, Throwable $previous = NULL]]]).
1 parent dea93aa commit bf205bb

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/FormattedException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static function formattedConstruct($args): array
7979
{
8080
$code = 0;
8181
$previous = null;
82-
$format = array_shift($args);
82+
$format = array_shift($args) ?? '';
8383

8484
if (is_array($format))
8585
{

test/FormattedExceptionTestBase.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,42 @@ public function testFormattingMissingArgs1(): void
104104
}
105105
}
106106

107+
//--------------------------------------------------------------------------------------------------------------------
108+
/**
109+
* Test formatting null string.
110+
*/
111+
public function testFormattingNull1(): void
112+
{
113+
try
114+
{
115+
$format = null;
116+
117+
throw new self::$class($format);
118+
}
119+
catch (Exception $e)
120+
{
121+
self::assertSame('', $e->getMessage());
122+
}
123+
}
124+
125+
//--------------------------------------------------------------------------------------------------------------------
126+
/**
127+
* Test formatting null string and bogus arguments.
128+
*/
129+
public function testFormattingNull2(): void
130+
{
131+
try
132+
{
133+
$format = null;
134+
135+
throw new self::$class($format, 'bogus', 123);
136+
}
137+
catch (Exception $e)
138+
{
139+
self::assertSame('', $e->getMessage());
140+
}
141+
}
142+
107143
//--------------------------------------------------------------------------------------------------------------------
108144
/**
109145
* Test formatting string with missing arguments.

0 commit comments

Comments
 (0)