Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually implement stream_context_set_options in a php8.1-compatible way #495

Closed
wants to merge 1 commit into from
Closed
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
27 changes: 0 additions & 27 deletions generated/stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,6 @@

use Safe\Exceptions\StreamException;

/**
* Sets options on the specified context.
*
* @param resource $context The stream or context resource to apply the options to.
* @param array $options The options to set for context.
*
* options must be an associative
* array of associative arrays in the format
* $array['wrapper']['option'] = $value.
*
* Refer to context options and parameters
* for a listing of stream options.
* @return true Returns TRUE on success.
* @throws StreamException
*
*/
function stream_context_set_options($context, array $options): true
{
error_clear_last();
$safeResult = \stream_context_set_options($context, $options);
if ($safeResult === false) {
throw StreamException::createFromPhpError();
}
return $safeResult;
}


/**
* Sets parameters on the specified context.
*
Expand Down
6 changes: 5 additions & 1 deletion generator/config/specialCasesFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@
'simplexml_import_dom',
'simplexml_load_file',
'simplexml_load_string',
'fgetcsv', // This function need to return false when iterating on an end of file.
// returns literal "true", which php8.1 doesn't support, so we implement
// this one manually and return "bool"
'stream_context_set_options',
// This function need to return false when iterating on an end of file.
Comment on lines +18 to +21
Copy link
Collaborator

@staabm staabm Dec 3, 2024

Choose a reason for hiding this comment

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

maybe we can rewrite a :true or :false return type in the generator to bool instead of this hardcoded 1 function fix? other functions might have the same problem?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems sensible, #497 does it that way instead

'fgetcsv',
];
27 changes: 27 additions & 0 deletions lib/special_cases.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Safe\Exceptions\OpensslException;
use Safe\Exceptions\PcreException;
use Safe\Exceptions\SimplexmlException;
use Safe\Exceptions\StreamException;
use Safe\Exceptions\FilesystemException;

use const PREG_NO_ERROR;
Expand Down Expand Up @@ -442,3 +443,29 @@
}
return $safeResult;
}

/**
* Sets options on the specified context.
*
* @param resource $context The stream or context resource to apply the options to.
* @param array $options The options to set for context.
*
* options must be an associative
* array of associative arrays in the format
* $array['wrapper']['option'] = $value.
*
* Refer to context options and parameters
* for a listing of stream options.
* @return true Returns TRUE on success.
* @throws StreamException
*
*/
function stream_context_set_options($context, array $options): bool

Check failure on line 463 in lib/special_cases.php

View workflow job for this annotation

GitHub Actions / Generated Tests (8.1)

Function Safe\stream_context_set_options() has parameter $options with no value type specified in iterable type array.

Check failure on line 463 in lib/special_cases.php

View workflow job for this annotation

GitHub Actions / Generated Tests (8.2)

Function Safe\stream_context_set_options() has parameter $options with no value type specified in iterable type array.

Check failure on line 463 in lib/special_cases.php

View workflow job for this annotation

GitHub Actions / Generated Tests (8.3)

Function Safe\stream_context_set_options() has parameter $options with no value type specified in iterable type array.

Check failure on line 463 in lib/special_cases.php

View workflow job for this annotation

GitHub Actions / Generated Tests (8.1)

Function Safe\stream_context_set_options() has parameter $options with no value type specified in iterable type array.

Check failure on line 463 in lib/special_cases.php

View workflow job for this annotation

GitHub Actions / Generated Tests (8.2)

Function Safe\stream_context_set_options() has parameter $options with no value type specified in iterable type array.

Check failure on line 463 in lib/special_cases.php

View workflow job for this annotation

GitHub Actions / Generated Tests (8.4)

Function Safe\stream_context_set_options() has parameter $options with no value type specified in iterable type array.

Check failure on line 463 in lib/special_cases.php

View workflow job for this annotation

GitHub Actions / Generated Tests (8.3)

Function Safe\stream_context_set_options() has parameter $options with no value type specified in iterable type array.

Check failure on line 463 in lib/special_cases.php

View workflow job for this annotation

GitHub Actions / Generated Tests (8.4)

Function Safe\stream_context_set_options() has parameter $options with no value type specified in iterable type array.
{
error_clear_last();
$safeResult = \stream_context_set_options($context, $options);

Check failure on line 466 in lib/special_cases.php

View workflow job for this annotation

GitHub Actions / Generated Tests (8.1)

Function stream_context_set_options not found.

Check failure on line 466 in lib/special_cases.php

View workflow job for this annotation

GitHub Actions / Generated Tests (8.2)

Function stream_context_set_options not found.

Check failure on line 466 in lib/special_cases.php

View workflow job for this annotation

GitHub Actions / Generated Tests (8.1)

Function stream_context_set_options not found.

Check failure on line 466 in lib/special_cases.php

View workflow job for this annotation

GitHub Actions / Generated Tests (8.2)

Function stream_context_set_options not found.
if ($safeResult === false) {

Check failure on line 467 in lib/special_cases.php

View workflow job for this annotation

GitHub Actions / Generated Tests (8.4)

Strict comparison using === between true and false will always evaluate to false.

Check failure on line 467 in lib/special_cases.php

View workflow job for this annotation

GitHub Actions / Generated Tests (8.4)

Strict comparison using === between true and false will always evaluate to false.
throw StreamException::createFromPhpError();
}
return $safeResult;
}
Loading