News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Paul Jones' Blog:
When Possible, Use File *Resources* Instead Of File *Names*
July 04, 2012 @ 14:10:49

In this new post to his blog Paul Jones makes a suggestion when you're working with files or external connections in your PHP applications - pass the resource, not the file/path name for more flexibility.

In testing the Aura.Http package, I have realized that it's much more flexible, testing wise, to pass around file resources (a.k.a. handles, pointers, or streams) than it is to pass around file names. When you do that, you can use a php://memory stream instead of attempting to touch the file system.

He shows how using this method can make it easier to test with a simple bit of refactoring by passing in the "php://memory" stream rather than the actual file reference. The comment (from Chris Hartjes) also suggests an alternative tool for working with tests that need the file system, vfsStream.

0 comments voice your opinion now!
file resource filename opinion unittest phpmemory stream


blog comments powered by Disqus

Similar Posts

Nay Pryce's Blog: "Dependency Injection" Considered Harmful

Debuggable Blog: Code Coverage Analysis soon in CakePHP - Test How Well You Test

NetTuts.com: Hands-On Unit Testing With PHPUnit (Screencast)

DevShed: Using the Xdebug Extension's xdebug_call_function() Function

Chris Jones: Using the PHP CLI Webserver to Identify and Test Memory Issues in PHP


Community Events

Don't see your event here?
Let us know!


library series release symfony2 framework podcast extension community interview laravel php7 example opinion application performance conference voicesoftheelephpant version api introduction

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework