Change data inside file object?

I still try to merge the two objects together but still no luck. What is wrong?

class Foo {
    function test() {
      return 'whatever';
    }
}

$foo = new Foo;

$new_object = (object) array_merge((array) $foo, (array) $page);

echo $new_object->title();

The error message is

Fatal error: Call to undefined method stdClass::title()