The temporary string created to hold the file contents will be destroyed. Without delving into the sources to confirm, here's a couple of ways you can test that a temporary value created as a function parameter gets destroyed:
Method 1: a class which reports its destruction
This demonstrates lifetime by using a class which reports on its own demise:
class lifetime
{
public function __construct()
{
echo "construct\n";
}
public function __destruct()
{
echo "destruct\n";
}
}
function getTestObject()
{
return new lifetime();
}
function foo($obj)
{
echo "inside foo\n";
}
echo "Calling foo\n";
foo(getTestObject());
echo "foo complete\n";
This outputs
Calling foo
construct
inside foo
destruct
foo complete
Which indicates that the implied temporary variable is destroyed right after the foo function call.
Method 2: measure memory usage
Here's another method which offers further confirmation using memory_get_usage to measure how much we've consumed.
function foo($str)
{
$length=strlen($str);
echo "in foo: data is $length, memory usage=".memory_get_usage()."\n";
}
echo "start: ".memory_get_usage()."\n";
foo(file_get_contents('/tmp/three_megabyte_file'));
echo "end: ".memory_get_usage()."\n";
This outputs
start: 50672
in foo: data is 2999384, memory usage=3050884
end: 51544