Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1360,11 +1360,6 @@ services:
tags:
- phpstan.broker.dynamicFunctionReturnTypeExtension

-
class: PHPStan\Type\Php\CurlInitReturnTypeExtension
tags:
- phpstan.broker.dynamicFunctionReturnTypeExtension
Comment on lines -1363 to -1366
Copy link
Contributor Author

@tscni tscni Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we no longer ignore curl_init() memory allocation & initialization issues, this extension becomes mostly useless.
It would really only handle the following

  • If the input contains \0 it will always return false / never
  • If the input is really huge it will likely return false
  • If the input is an invalid URL or uses the file:// scheme it might return false on PHP 7

These are all very unlikely edge-cases, thus it seemed more reasonable to move the return type definition to the function map.

In short: curl_init() will now always return (resource|false) or (CurlHandle|false).


-
class: PHPStan\Type\Php\DateFunctionReturnTypeHelper

Expand Down
2 changes: 1 addition & 1 deletion resources/functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@
'curl_exec' => ['bool|string', 'ch'=>'resource'],
'curl_file_create' => ['CURLFile', 'filename'=>'string', 'mimetype='=>'string', 'postfilename='=>'string'],
'curl_getinfo' => ['mixed', 'ch'=>'resource', 'option='=>'int'],
'curl_init' => ['resource|false', 'url='=>'string'],
'curl_init' => ['__benevolent<resource|false>', 'url='=>'string'],
'curl_multi_add_handle' => ['int', 'mh'=>'resource', 'ch'=>'resource'],
'curl_multi_close' => ['void', 'mh'=>'resource'],
'curl_multi_errno' => ['int', 'mh'=>'resource'],
Expand Down
2 changes: 2 additions & 0 deletions resources/functionMap_php80delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'ceil' => ['float', 'number'=>'float'],
'com_load_typelib' => ['bool', 'typelib_name'=>'string', 'case_insensitive='=>'true'],
'count_chars' => ['array<int,int>|string', 'input'=>'string', 'mode='=>'int'],
'curl_init' => ['__benevolent<CurlHandle|false>', 'url='=>'string'],
'date_add' => ['DateTime', 'object'=>'DateTime', 'interval'=>'DateInterval'],
'date_date_set' => ['DateTime', 'object'=>'DateTime', 'year'=>'int', 'month'=>'int', 'day'=>'int'],
'date_diff' => ['DateInterval', 'obj1'=>'DateTimeInterface', 'obj2'=>'DateTimeInterface', 'absolute='=>'bool'],
Expand Down Expand Up @@ -169,6 +170,7 @@
'convert_cyr_string' => ['string', 'str'=>'string', 'from'=>'string', 'to'=>'string'],
'com_load_typelib' => ['bool', 'typelib_name'=>'string', 'case_insensitive='=>'bool'],
'count_chars' => ['array<int,int>|false|string', 'input'=>'string', 'mode='=>'int'],
'curl_init' => ['__benevolent<resource|false>', 'url='=>'string'],
'date_add' => ['DateTime|false', 'object'=>'DateTime', 'interval'=>'DateInterval'],
'date_date_set' => ['DateTime|false', 'object'=>'DateTime', 'year'=>'int', 'month'=>'int', 'day'=>'int'],
'date_diff' => ['DateInterval|false', 'obj1'=>'DateTimeInterface', 'obj2'=>'DateTimeInterface', 'absolute='=>'bool'],
Expand Down
102 changes: 0 additions & 102 deletions src/Type/Php/CurlInitReturnTypeExtension.php

This file was deleted.

6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,12 @@ public function testBug11511(): void
$this->assertSame('Access to an undefined property object::$bar.', $errors[0]->getMessage());
}

public function testBug11640(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-11640.php');
$this->assertNoErrors($errors);
}

/**
* @param string[]|null $allAnalysedFiles
* @return Error[]
Expand Down
9 changes: 9 additions & 0 deletions tests/PHPStan/Analyser/data/bug-11640.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php declare(strict_types = 1);

namespace Bug11640;

$ch = curl_init('https://example.com');

if (!$ch) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PHPStan\Reflection\PassedByReference;
use PHPStan\Testing\PHPStanTestCase;
use PHPStan\Type\ArrayType;
use PHPStan\Type\BenevolentUnionType;
use PHPStan\Type\BooleanType;
use PHPStan\Type\CallableType;
use PHPStan\Type\ClassStringType;
Expand Down Expand Up @@ -59,7 +60,7 @@ public function dataFunctions(): array
'variadic' => false,
],
],
new UnionType([
new BenevolentUnionType([
new ObjectType('CurlHandle'),
new ConstantBooleanType(false),
]),
Expand Down
32 changes: 0 additions & 32 deletions tests/PHPStan/Type/Php/CurlInitReturnTypeExtensionTest.php

This file was deleted.

65 changes: 0 additions & 65 deletions tests/PHPStan/Type/Php/data/curl-init-php-7.php

This file was deleted.

69 changes: 0 additions & 69 deletions tests/PHPStan/Type/Php/data/curl-init-php-8.php

This file was deleted.

Loading