Skip to content

[Filesystem] Support resources and deprecate using arrays in dumpFile() and appendToFile() #29661

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

Merged
merged 1 commit into from
Mar 3, 2019

Conversation

thewilkybarkid
Copy link
Contributor

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets
License MIT
Doc PR

Running PHPStan on my project picked up that passing a resource to Filesystem::dumpFile() didn't match the documented type.

I found this has been discussed in #20980 and #28019, without a clear result. But, my reading is that only strings should be supported. While I think that not supporting streams makes this a lot less useful (and I'm going to switch away from it), this does need to be resolved. So, I've deprecated using arrays and resources.

@thewilkybarkid thewilkybarkid changed the title Deprecate using arrays and resources in Filesystem's dumpFile() and appendToFile() [Filesystem] Deprecate using arrays and resources in dumpFile() and appendToFile() Dec 21, 2018
@nicolas-grekas nicolas-grekas added this to the next milestone Dec 24, 2018
Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

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

UPGADE-4.3.md needs to be updated

@thewilkybarkid
Copy link
Contributor Author

Would need a separate PR, but would you accept a new method that takes a resource?

@fabpot
Copy link
Member

fabpot commented Dec 28, 2018

What about reusing the same method?

@thewilkybarkid
Copy link
Contributor Author

That would be my preference, but this PR was following #20980 and #28019.

@fabpot
Copy link
Member

fabpot commented Feb 21, 2019

I would be in favor of supporting resources and strings in the existing method.

@thewilkybarkid thewilkybarkid changed the title [Filesystem] Deprecate using arrays and resources in dumpFile() and appendToFile() [Filesystem] Support resources and deprecate using arrays in dumpFile() and appendToFile() Feb 22, 2019
@thewilkybarkid
Copy link
Contributor Author

@fabpot Updated to match.

@fabpot
Copy link
Member

fabpot commented Mar 3, 2019

Thank you @thewilkybarkid.

@fabpot fabpot merged commit 0eaf9d2 into symfony:master Mar 3, 2019
fabpot added a commit that referenced this pull request Mar 3, 2019
…ays in dumpFile() and appendToFile() (thewilkybarkid)

This PR was squashed before being merged into the 4.3-dev branch (closes #29661).

Discussion
----------

[Filesystem] Support resources and deprecate using arrays in dumpFile() and appendToFile()

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Running PHPStan on my project picked up that passing a resource to `Filesystem::dumpFile()` didn't match the documented type.

I found this has been discussed in #20980 and #28019, without a clear result. But, my reading is that only strings should be supported. While I think that not supporting streams makes this a lot less useful (and I'm going to switch away from it), this does need to be resolved. So, I've deprecated using arrays and resources.

Commits
-------

0eaf9d2 [Filesystem] Support resources and deprecate using arrays in dumpFile() and appendToFile()
@thewilkybarkid thewilkybarkid deleted the dump-file-type branch March 4, 2019 06:05
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 2019
@fabpot fabpot mentioned this pull request May 9, 2019
@tvdijen
Copy link

tvdijen commented Mar 1, 2022

The current type-hints that were added in 5.x for these methods prevent us from passing resources because the file is type-hinted as string.
I'm trying to use appendToFile with file php://stderr which breaks on the mkdir() in the method and passing fopen('php://stderr', 'w') as a file break because of the typehint.. Is this a bug, or shouldn't I be doing this at all @fabpot ?

Update: this only breaks on Windows for some reason... this is my workaround to deal with php:// files on windows right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants