From fca0e244104090681902397daec66899183580b7 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Wed, 15 Nov 2006 00:20:40 +0000 Subject: [PATCH] Added missing object support to file_put_contents(). --- NEWS | 1 + ext/standard/file.c | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 0547e635f14..e09b5254c36 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2007, PHP 5.2.1 +- Added missing object support to file_put_contents(). (Ilia) - Updated bundled libcURL to version 7.16.0 in the Windows distro. (Edin) - cgi.* and fastcgi.* directives are moved to INI subsystem. The new directive cgi.check_shebang_line can be used to ommiting checnk diff --git a/ext/standard/file.c b/ext/standard/file.c index 6456dcac4d4..248318a1383 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -653,11 +653,23 @@ PHP_FUNCTION(file_put_contents) } break; + case IS_OBJECT: + if (Z_OBJ_HT_P(data) != NULL) { + zval out; + + if (zend_std_cast_object_tostring(data, &out, IS_STRING TSRMLS_CC) == SUCCESS) { + numbytes = php_stream_write(stream, Z_STRVAL(out), Z_STRLEN(out)); + if (numbytes != Z_STRLEN(out)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only %d of %d bytes written, possibly out of free disk space", numbytes, Z_STRLEN(out)); + numbytes = -1; + } + zval_dtor(&out); + break; + } + } default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The 2nd parameter should be either a string or an array"); - numbytes = -1; + numbytes = -1; break; - } php_stream_close(stream);