Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix GH-8750: Can not create VT_ERROR variant type
We add support for creating `VT_ERROR` variants via `__construct()`, and allow casting to int via `variant_cast()` and `variant_set_type()`. We do not, however, allow type conversion by other means, to avoid otherwise easily introduced type confusion. VB(A) also only allows explicit type conversion. We also introduce `DISP_E_PARAMNOTFOUND` which might be the most important `scode` for this purpose, since this allows to skip optional parameters in method calls. Closes GH-8886.
- Loading branch information
Showing
8 changed files
with
120 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--TEST-- | ||
Bug GH-8750 (Can not create VT_ERROR variant type) | ||
--EXTENSIONS-- | ||
com_dotnet | ||
--SKIPIF-- | ||
<?php | ||
$provider = "Microsoft.ACE.OLEDB.12.0"; | ||
$filename = __DIR__ . "\\gh8750.mdb"; | ||
$catalog = new com("ADOX.Catalog"); | ||
try { | ||
$catalog->Create("Provider=$provider;Data Source=$filename"); | ||
} catch (com_exception) { | ||
die("skip $provider provider not available"); | ||
} | ||
$catalog = null; | ||
@unlink($filename); | ||
?> | ||
--FILE-- | ||
<?php | ||
$filename = __DIR__ . "\\gh8750.mdb"; | ||
|
||
$catalog = new com("ADOX.Catalog"); | ||
$catalog->Create("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$filename"); | ||
$catalog = null; | ||
|
||
$db = new com("ADODB.Connection"); | ||
$db->ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$filename"; | ||
$db->Mode = 1; // adModeRead | ||
$db->Open(); | ||
// adSchemaProviderSpecific, *missing*, JET_SCHEMA_USERROSTER | ||
$rs = $db->OpenSchema(-1, new variant(DISP_E_PARAMNOTFOUND, VT_ERROR), "{947bb102-5d43-11d1-bdbf-00c04fb92675}"); | ||
// manual counting since rs.RecordCount is -1 (not supported) | ||
$i = 0; | ||
while (!$rs->EOF) { | ||
$rs->MoveNext(); | ||
$i++; | ||
} | ||
$rs->Close(); | ||
$db->Close(); | ||
var_dump($i); | ||
?> | ||
--EXPECT-- | ||
int(1) | ||
--CLEAN-- | ||
<?php | ||
unlink(__DIR__ . "/gh8750.mdb"); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--TEST-- | ||
Bug GH-8750 (Can not create VT_ERROR variant type) - cast and conversion | ||
--EXTENSIONS-- | ||
com_dotnet | ||
--FILE-- | ||
<?php | ||
$error = new variant(DISP_E_PARAMNOTFOUND, VT_ERROR); | ||
|
||
// explicit variant_cast() to int is supported if in range | ||
echo variant_cast($error, VT_I4), PHP_EOL; | ||
|
||
// however, explicit (int) casts are not supported | ||
echo (int) $error, PHP_EOL; | ||
|
||
// nor are implicit conversions | ||
try { | ||
echo 1 + $error, PHP_EOL; | ||
} catch (TypeError $err) { | ||
echo $err->getMessage(), PHP_EOL; | ||
} | ||
|
||
// we can retrieve the type | ||
echo variant_get_type($error), PHP_EOL; | ||
|
||
// and change it via variant_set_type() | ||
variant_set_type($error, VT_I4); | ||
echo variant_get_type($error), PHP_EOL; | ||
?> | ||
--EXPECTF-- | ||
-2147352572 | ||
|
||
Warning: Object of class variant could not be converted to int in %s on line %d | ||
1 | ||
Unsupported operand types: int + variant | ||
10 | ||
3 |