Browse Source

Implement __toString() magic in Zend/Http/Response.php

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16023 44c647ce-9c0f-0410-b52a-842ac1e357ba
doctorrock83 16 years ago
parent
commit
902f081816

+ 3 - 1
documentation/manual/en/module_specs/Zend_Http_Response.xml

@@ -161,7 +161,9 @@ if ($response->isError()) {
                 <listitem>
                     <para>
                         <code>string asString($br = "\n")</code>: Get the entire response message as a string.
-                        Lines are broken with the $br parameter (Can be, for example, "&lt;br /&gt;")
+                        Lines are broken with the $br parameter (Can be, for example, "&lt;br /&gt;").
+						You can also use the magic method __toString() when casting the object as a string. It will
+						then proxy to asString()
                     </para>
                 </listitem>
             </itemizedlist>

+ 10 - 0
library/Zend/Http/Response.php

@@ -398,6 +398,16 @@ class Zend_Http_Response
     }
 
     /**
+     * Implements magic __toString()
+     *
+     * @return string
+     */
+    public function __toString()
+    {
+        return $this->asString();
+    }
+
+    /**
      * A convenience function that returns a text representation of
      * HTTP response codes. Returns 'Unknown' for unknown codes.
      * Returns array of all codes, if $code is not specified.

+ 1 - 0
tests/Zend/Http/ResponseTest.php

@@ -161,6 +161,7 @@ class Zend_Http_ResponseTest extends PHPUnit_Framework_TestCase
 		$response = Zend_Http_Response::fromString($response_str);
 		
 		$this->assertEquals(strtolower($response_str), strtolower($response->asString()), 'Response convertion to string does not match original string');
+		$this->assertEquals(strtolower($response_str), strtolower((string)$response), 'Response convertion to string does not match original string');
 	}
 	
 	public function testGetHeaders()