Concatenate

What, if anything, is the minimum change (fewest inserted/deleted/modified characters) required to make the output The result is bar:


<?php
class A {
  private $foo = "bar";
  public function __toString() {
    return $this->foo;
  }
}

$myObject = new A();
echo "The result is " . $myObject;
?>

Answer:
echo "The result is " , $myObject;

Comments

2 responses to “Concatenate”

  1. AlexPHP Avatar
    AlexPHP

    Was this specific for a particular PHP version? Because no modifications would already produce the desired output in PHP5

  2. snoyes Avatar

    Must have been PHP 4, and must have had something to do with the way that objects were evaluated for concatenation rather than separately. If I had PHP 4 installed, I’d try it.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.