Fixed circular to string method in simplexml #39

Closed
wants to merge 1 commit into
from

2 participants

@jswift

utilities/simplexml was changed in 1.5.7 to extend simplexmlelement::_toString(), but the implemented to_string() method had an implied call _toString.

This fix prevents the never-ending loop.

@jswift

The original method (casting to string in a __toString() call) seems to work fine in PHP 5.3.10, but breaks in PHP 5.4.7 (segfault or xdebug stack depth exception). The following test passes in 5.3.10, but fails to complete in 5.4.7. The above change fixes it for 5.4.7:

    /**
     * Simple test that causes segfault error in PHP 5.4.7
     *
     * If xdebug is enabled, will cause maximum function nesting level error.
     * @author jarrodswift
     */
    class SimpleAwsTests extends PHPUnit_Framework_TestCase {
        /**
         * @var AmazonSDB $sdb
         */
        protected $sdb;

        public function setUp() {
            $this->sdb = new AmazonSDB();
        }

        public function testToStringBug() {
            $response = $this->sdb->list_domains();
            $this->assertTrue( $response->isOK(), "Failed to list domains" );

            $domains = $response->body->ListDomainsResult->DomainName;
            foreach($domains as $domain ) {
                // This is the line that causes the issue
                $this->assertNotEquals('domain that doesnt exist', (string)$domain);
            }
        }
    }
@jswift

Pretty sure this is related to Bug #62328 __toString() not being called on SimpleXMLElement. In PHP 5.4.6 and before, the __toString() method of utilities/simplexml is never called.

@jeremeamia

Thanks for pull request and details. We'll try to get it integrated soon.

@jeremeamia

I've made the changes in my local copy and have added you to the CONTRIBUTORS doc. We do not accept pull requests directly for logistical reasons, but your changes will appear in the next version of the SDK. Thanks again!

@jeremeamia jeremeamia closed this Sep 20, 2012
@jeremeamia

That __toString()/SimpleXmlElement is an annoying bug, btw. I fixed the circular reference, but I think you are going to have to call __toString() on the element directly, or better, the to_string() method, which is a prettier alias. I updated the DynamoDB Session Handler to do the stringification correctly (see the other pull request).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment