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

Add method to get underlying file resource #2328

Closed
wants to merge 2 commits into from

Conversation

4 participants
@Danack
Copy link
Contributor

Danack commented Jan 22, 2017

An implementation for https://bugs.php.net/bug.php?id=44392

This appears to be a useful thing, and I can't see a reason why the file resource shouldn't be retrievable......but maybe I missed something.

@krakjoe krakjoe added the Enhancement label Jan 22, 2017

@krakjoe

This comment has been minimized.

Copy link
Member

krakjoe commented Jan 22, 2017

This should target master.

@nikic

This comment has been minimized.

Copy link
Member

nikic commented Jan 22, 2017

See #1280. This does not appear safe, at least not in this basic form.

@krakjoe

This comment has been minimized.

Copy link
Member

krakjoe commented Jan 22, 2017

I was sure I had seen something like this before ... thanks nikita ...

@Danack

This comment has been minimized.

Copy link
Contributor Author

Danack commented Jan 22, 2017

In that case - this might not be possible without a re-write of the streams library. So I'll close this.

@Danack Danack closed this Jan 22, 2017

@nyamsprod

This comment has been minimized.

Copy link
Contributor

nyamsprod commented Jun 21, 2017

@Danack @nikic since adding a method to access the underlying resource is a no go can the other way around this be tried then ? Allow php stream function like stream_filter_append to accept a stream resource or a SplFileObject. This way the internal file pointer is not expose to user land and we get to use stream filter on SplFileObject without using some limited hack like this

Instead of doing this:

$path = 'path/to/my/file.txt';
$file = new SplFileObject('php://filter/read=string.rot13|string.toupper/resource='.$path, 'r');
$file->fgets();  //the output text is ROT13 and then uppercased

We could do this

$path = 'path/to/my/file.txt';
$file = new SplFileObject($path, 'r');
$filter_one = stream_filter_append($file, 'string.toupper');
$filter_two = stream_filter_prepend($file, 'string.rot13');
$file->fgets();  //the output text is ROT13 and then uppercased

Unless this would also leave the SplFileObject in an unstable state ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.