Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

jamesjones21
jamesjones21
9,260 Points

Recoverable fatal error: Object of class could not be converted to string

HI Guys,

I have a class which has two static functions:

class Render
{
    public static function listCustomerOrder($order)
    {

        $output2 = "";
        $output2 .= $order->getCustomerName();
        $output2 .= $order->GetItemQuantity();
        return $output2;


    }

    public static function displayCustomerOrder ($shoppingCart) //
    {
        $output ="";
        $output .= self::listCustomerOrder($shoppingCart->getCustomerName());
        return $output;
    }
}

when calling the function render like so:

echo new Render();

It provides me with object of class could not be converted to string.

any ideas?

cheers,

James

Nedim Becirovic
Nedim Becirovic
9,394 Points

You can echo only string values. If you want to see any other value use var_dump().

1 Answer

jamesjones21
jamesjones21
9,260 Points

thanks for the input, I resolved the issue, I had to have a __construct and a __toString method added :) OOP is hard enough to grasp but getting there slightly.

regards,

James