A Little Noise

November 11, 2005

Concatenate

Filed under: PHP Gotchas — snoyes @ 4:00 am

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;
?>

Show Answer ▼

2 Comments »

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

    Comment by AlexPHP — July 22, 2010 @ 12:49 pm

  2. 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.

    Comment by snoyes — July 22, 2010 @ 1:52 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress