在回显get_browser()的结果时,“类stdClass的对象无法转换为字符串”进行故障排除

<?
/*current browser*/
$string = get_browser("name");
echo("$string");
?>

is giving me the error:

Catchable fatal error: Object of class stdClass could not be converted to string in C:\xampp\htdocs\endlessdescription\header.php on line 106

line 106 is echo("$string"). I have a similar bit of code that displays the last modified date/time above and it works fine.

I pulled this from a book so I don't see why it wouldn't work, is "name" not a valid argument of get_browser? Any help greatly appreciated.

As you can read here, from the official documentation, the function get_browser return an array, not just a string. So you have to choose the info you need and print it accordingly. Maybe the best info that fits your need is to echo the value of browser.

As the dude above said, it returns in array, a way to print this out is using foreach(); This prints out the array.

foreach($string as $string => $sub)
{
    echo $string.'<br />'.$sub.'<br />';
}

try something like:

<?
$browser = get_browser(null, true);
echo($browser['browser']);
?>

From the get_browser documentation on php.net:

In order for this to work, your browscap configuration setting in php.ini must point to the correct location of the browscap.ini file on your system. browscap.ini is not bundled with PHP, but you may find an up-to-date php_browscap.ini file here.