Skip to content

Commit

Permalink
Fix extract signature
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored Nov 13, 2024
1 parent 5a110c4 commit ceac309
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 13 deletions.
4 changes: 2 additions & 2 deletions resources/functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
'array_map' => ['array', 'callback'=>'?callable', 'array'=>'array', '...args='=>'array'],
'array_merge' => ['array', 'arr1'=>'array', '...args='=>'array'],
'array_merge_recursive' => ['array', 'arr1'=>'array', '...args='=>'array'],
'array_multisort' => ['bool', '&rw_array1'=>'array', 'array1_sort_order='=>'array|int', 'array1_sort_flags='=>'array|int', '...args='=>'array|int'],
'array_multisort' => ['bool', 'array1'=>'array', 'array1_sort_order='=>'array|int', 'array1_sort_flags='=>'array|int', '...args='=>'array|int'],
'array_pad' => ['array', 'input'=>'array', 'pad_size'=>'int', 'pad_value'=>'mixed'],
'array_pop' => ['mixed', '&rw_stack'=>'array'],
'array_product' => ['int|float', 'input'=>'array'],
Expand Down Expand Up @@ -2637,7 +2637,7 @@
'explode' => ['list<string>|false', 'separator'=>'string', 'str'=>'string', 'limit='=>'int'],
'expm1' => ['float', 'number'=>'float'],
'extension_loaded' => ['bool', 'extension_name'=>'string'],
'extract' => ['0|positive-int', '&rw_var_array'=>'array', 'extract_type='=>'int', 'prefix='=>'string|null'],
'extract' => ['0|positive-int', 'array'=>'array', 'flags='=>'int', 'prefix='=>'string|null'],
'ezmlm_hash' => ['int', 'addr'=>'string'],
'fam_cancel_monitor' => ['bool', 'fam'=>'resource', 'fam_monitor'=>'resource'],
'fam_close' => ['void', 'fam'=>'resource'],
Expand Down
2 changes: 1 addition & 1 deletion resources/functionMap_bleedingEdge.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
'scandir' => ['list<string>|false', 'dir'=>'string', 'sorting_order='=>'SCANDIR_SORT_ASCENDING|SCANDIR_SORT_DESCENDING| SCANDIR_SORT_NONE', 'context='=>'resource'],
'stream_socket_client' => ['resource|false', 'remoteaddress'=>'string', '&w_errcode='=>'int', '&w_errstring='=>'string', 'timeout='=>'float', 'flags='=>'int-mask<STREAM_CLIENT_CONNECT|STREAM_CLIENT_ASYNC_CONNECT|STREAM_CLIENT_PERSISTENT>', 'context='=>'resource'],
'stream_socket_enable_crypto' => ['0|bool', 'stream'=>'resource', 'enable'=>'bool', 'crypto_method='=>'STREAM_CRYPTO_METHOD_SSLv2_CLIENT|STREAM_CRYPTO_METHOD_SSLv3_CLIENT|STREAM_CRYPTO_METHOD_SSLv23_CLIENT|STREAM_CRYPTO_METHOD_ANY_CLIENT|STREAM_CRYPTO_METHOD_TLS_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT|STREAM_CRYPTO_METHOD_SSLv2_SERVER|STREAM_CRYPTO_METHOD_SSLv3_SERVER|STREAM_CRYPTO_METHOD_SSLv23_SERVER|STREAM_CRYPTO_METHOD_ANY_SERVER|STREAM_CRYPTO_METHOD_TLS_SERVER|STREAM_CRYPTO_METHOD_TLSv1_0_SERVER|STREAM_CRYPTO_METHOD_TLSv1_1_SERVER|STREAM_CRYPTO_METHOD_TLSv1_2_SERVER|STREAM_CRYPTO_METHOD_TLSv1_3_SERVER', 'session_stream='=>'resource'],
'extract' => ['0|positive-int', '&rw_var_array'=>'array', 'extract_type='=>'EXTR_OVERWRITE|EXTR_SKIP|EXTR_PREFIX_SAME|EXTR_PREFIX_ALL|EXTR_PREFIX_INVALID|EXTR_IF_EXISTS|EXTR_PREFIX_IF_EXISTS|EXTR_REFS', 'prefix='=>'string|null'],
'extract' => ['0|positive-int', 'array'=>'array', 'flags='=>'EXTR_OVERWRITE|EXTR_SKIP|EXTR_PREFIX_SAME|EXTR_PREFIX_ALL|EXTR_PREFIX_INVALID|EXTR_IF_EXISTS|EXTR_PREFIX_IF_EXISTS|EXTR_REFS', 'prefix='=>'string|null'],
'RecursiveIteratorIterator::__construct' => ['void', 'iterator'=>'RecursiveIterator|IteratorAggregate', 'mode='=>'RecursiveIteratorIterator::LEAVES_ONLY|RecursiveIteratorIterator::SELF_FIRST|RecursiveIteratorIterator::CHILD_FIRST', 'flags='=>'0|RecursiveIteratorIterator::CATCH_GET_CHILD'],
'Locale::composeLocale' => ['string|false', 'subtags'=>'array{language:string, script?:string, region?:string, variant?:array<array-key,string>, private?:array<array-key,string>, extlang?:array<array-key,string>, variant0?:string, variant1?:string, variant2?:string, variant3?:string, variant4?:string, variant5?:string, variant6?:string, variant7?:string, variant8?:string, variant9?:string, variant10?:string, variant11?:string, variant12?:string, variant13?:string, variant14?:string, private0?:string, private1?:string, private2?:string, private3?:string, private4?:string, private5?:string, private6?:string, private7?:string, private8?:string, private9?:string, private10?:string, private11?:string, private12?:string, private13?:string, private14?:string, extlang0?:string, extlang1?:string, extlang2?:string}'],
'locale_compose' => ['string|false', 'subtags'=>'array{language:string, script?:string, region?:string, variant?:array<array-key,string>, private?:array<array-key,string>, extlang?:array<array-key,string>, variant0?:string, variant1?:string, variant2?:string, variant3?:string, variant4?:string, variant5?:string, variant6?:string, variant7?:string, variant8?:string, variant9?:string, variant10?:string, variant11?:string, variant12?:string, variant13?:string, variant14?:string, private0?:string, private1?:string, private2?:string, private3?:string, private4?:string, private5?:string, private6?:string, private7?:string, private8?:string, private9?:string, private10?:string, private11?:string, private12?:string, private13?:string, private14?:string, extlang0?:string, extlang1?:string, extlang2?:string}'],
Expand Down
20 changes: 10 additions & 10 deletions resources/functionMap_php74delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@
*/
return [
'new' => [
'FFI::addr' => ['FFI\CData', '&ptr'=>'FFI\CData'],
'FFI::alignof' => ['int', '&ptr'=>'mixed'],
'FFI::addr' => ['FFI\CData', 'ptr'=>'FFI\CData'],
'FFI::alignof' => ['int', 'ptr'=>'mixed'],
'FFI::arrayType' => ['FFI\CType', 'type'=>'string|FFI\CType', 'dims'=>'array<int,int>'],
'FFI::cast' => ['FFI\CData', 'type'=>'string|FFI\CType', '&ptr'=>''],
'FFI::cast' => ['FFI\CData', 'type'=>'string|FFI\CType', 'ptr'=>''],
'FFI::cdef' => ['FFI', 'code='=>'string', 'lib='=>'?string'],
'FFI::free' => ['void', '&ptr'=>'FFI\CData'],
'FFI::free' => ['void', 'ptr'=>'FFI\CData'],
'FFI::load' => ['FFI', 'filename'=>'string'],
'FFI::memcmp' => ['int', '&ptr1'=>'FFI\CData|string', '&ptr2'=>'FFI\CData|string', 'size'=>'int'],
'FFI::memcpy' => ['void', '&dst'=>'FFI\CData', '&src'=>'string|FFI\CData', 'size'=>'int'],
'FFI::memset' => ['void', '&ptr'=>'FFI\CData', 'ch'=>'int', 'size'=>'int'],
'FFI::memcmp' => ['int', 'ptr1'=>'FFI\CData|string', 'ptr2'=>'FFI\CData|string', 'size'=>'int'],
'FFI::memcpy' => ['void', 'dst'=>'FFI\CData', 'src'=>'string|FFI\CData', 'size'=>'int'],
'FFI::memset' => ['void', 'ptr'=>'FFI\CData', 'ch'=>'int', 'size'=>'int'],
'FFI::new' => ['FFI\CData', 'type'=>'string|FFI\CType', 'owned='=>'bool', 'persistent='=>'bool'],
'FFI::scope' => ['FFI', 'scope_name'=>'string'],
'FFI::sizeof' => ['int', '&ptr'=>'FFI\CData|FFI\CType'],
'FFI::string' => ['string', '&ptr'=>'FFI\CData', 'size='=>'int'],
'FFI::typeof' => ['FFI\CType', '&ptr'=>'FFI\CData'],
'FFI::sizeof' => ['int', 'ptr'=>'FFI\CData|FFI\CType'],
'FFI::string' => ['string', 'ptr'=>'FFI\CData', 'size='=>'int'],
'FFI::typeof' => ['FFI\CType', 'ptr'=>'FFI\CData'],
'FFI::type' => ['FFI\CType', 'type'=>'string'],
'fread' => ['string|false', 'fp'=>'resource', 'length'=>'positive-int'],
'get_mangled_object_vars' => ['array', 'obj'=>'object'],
Expand Down
18 changes: 18 additions & 0 deletions tests/PHPStan/Analyser/nsrt/extract.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,21 @@ function doTyped3(array $vars): void

assertVariableCertainty(TrinaryLogic::createNo(), $none);
}

function doTyped4(): void
{
extract(['foo' => 42]);

assertVariableCertainty(TrinaryLogic::createYes(), $foo);
assertType('42', $foo);
}


function doTyped5(): void
{
$foo = ['foo' => 42];
extract($foo);

assertVariableCertainty(TrinaryLogic::createYes(), $foo);
assertType('42', $foo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1898,4 +1898,9 @@ public function testBug9224(): void
$this->analyse([__DIR__ . '/data/bug-9224.php'], []);
}

public function testBug11759(): void
{
$this->analyse([__DIR__ . '/data/bug-11759.php'], []);
}

}
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-11759.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace Bug11759;

extract(['answer' => 42 ]);

0 comments on commit ceac309

Please sign in to comment.