首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

SplTempFileObject::__construct

(PHP 5 >= 5.1.2, PHP 7)

SplTempFileObject::__construct — Construct a new temporary file object

Description

代码语言:javascript
复制
public SplTempFileObject::__construct ([ int $max_memory ] )

Construct a new temporary file object.

Parameters

max_memory

The maximum amount of memory (in bytes, default is 2 MB) for the temporary file to use. If the temporary file exceeds this size, it will be moved to a file in the system's temp directory.

If max_memory is negative, only memory will be used. If max_memory is zero, no memory will be used.

Return Values

No value is returned.

Errors/Exceptions

Throws a RuntimeException if an error occurs.

Examples

Example #1 SplTempFileObject() example

This example writes a temporary file in memory which can be written to and read from.

代码语言:javascript
复制
<?php
$temp?=?new?SplTempFileObject();
$temp->fwrite("This?is?the?first?line\n");
$temp->fwrite("And?this?is?the?second.\n");
echo?"Written?"?.?$temp->ftell()?.?"?bytes?to?temporary?file.\n\n";

//?Rewind?and?read?what?was?written
$temp->rewind();
foreach?($temp?as?$line)?{
????echo?$line;
}
?>

The above example will output something similar to:

代码语言:javascript
复制
Written 47 bytes to temporary file.

This is the first line
And this is the second.

See Also

  • SplFileObject

← SplTempFileObject

代码语言:txt
复制
 ? 1997–2017 The PHP Documentation Group

Licensed under the Creative Commons Attribution License v3.0 or later.

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com