From 96da3e78bbed4c781309bdac8545af4a22f53a01 Mon Sep 17 00:00:00 2001 From: Dave Liddament Date: Mon, 15 Feb 2021 11:03:34 +0000 Subject: [PATCH 1/2] Fix fputcsv fields parameter (should be string[]) The `fields` parameter for `fputcsv` should be an array of strings. See [PHP manual](https://www.php.net/manual/en/function.fputcsv.php). This should fix [this snippet](https://phpstan.org/r/65420d60-d1fd-4eef-9ba3-e057672082ee) by correctly reporting an error on line `22`. Running the code in the snippet on PHP 8.0 (`PHP 8.0.0 (cli) (built: Dec 6 2020 06:56:11) ( NTS )`) results in this error: ``` PHP Fatal error: Uncaught Error: Object of class Person could not be converted to string in /home/vagrant/example/csv.php:24 Stack trace: #0 /home/vagrant/example/csv.php(24): fputcsv() #1 {main} thrown in /home/vagrant/example/csv.php on line 24 ``` NOTE: I've seen a similar error with PHP 7.3 too. --- resources/functionMap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/functionMap.php b/resources/functionMap.php index faaa3f4323..b3c725c84b 100644 --- a/resources/functionMap.php +++ b/resources/functionMap.php @@ -3004,7 +3004,7 @@ 'fpassthru' => ['int|false', 'fp'=>'resource'], 'fpm_get_status' => ['array|false'], 'fprintf' => ['int', 'stream'=>'resource', 'format'=>'string', '...values='=>'string|int|float'], -'fputcsv' => ['int|false', 'fp'=>'resource', 'fields'=>'array', 'delimiter='=>'string', 'enclosure='=>'string', 'escape_char='=>'string'], +'fputcsv' => ['int|false', 'fp'=>'resource', 'fields'=>'string[]', 'delimiter='=>'string', 'enclosure='=>'string', 'escape_char='=>'string'], 'fputs' => ['int|false', 'fp'=>'resource', 'str'=>'string', 'length='=>'int'], 'fread' => ['string|false', 'fp'=>'resource', 'length'=>'int'], 'frenchtojd' => ['int', 'month'=>'int', 'day'=>'int', 'year'=>'int'], From 7521c3dfed617868d5cf7cfc3ebfec277b533a04 Mon Sep 17 00:00:00 2001 From: Dave Liddament Date: Mon, 15 Feb 2021 14:41:50 +0000 Subject: [PATCH 2/2] Update functionMap.php --- resources/functionMap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/functionMap.php b/resources/functionMap.php index b3c725c84b..02966e5ad6 100644 --- a/resources/functionMap.php +++ b/resources/functionMap.php @@ -3004,7 +3004,7 @@ 'fpassthru' => ['int|false', 'fp'=>'resource'], 'fpm_get_status' => ['array|false'], 'fprintf' => ['int', 'stream'=>'resource', 'format'=>'string', '...values='=>'string|int|float'], -'fputcsv' => ['int|false', 'fp'=>'resource', 'fields'=>'string[]', 'delimiter='=>'string', 'enclosure='=>'string', 'escape_char='=>'string'], +'fputcsv' => ['int|false', 'fp'=>'resource', 'fields'=>'array', 'delimiter='=>'string', 'enclosure='=>'string', 'escape_char='=>'string'], 'fputs' => ['int|false', 'fp'=>'resource', 'str'=>'string', 'length='=>'int'], 'fread' => ['string|false', 'fp'=>'resource', 'length'=>'int'], 'frenchtojd' => ['int', 'month'=>'int', 'day'=>'int', 'year'=>'int'],