Jump to content

Catchable fatal error...


android6011

Recommended Posts

This is the code:

 

<?

// Instantiate a new COM client to iTunes
$iTunes = new COM('iTunes.Application');

// What's playing now?
$currentTrack = $iTunes->CurrentTrack;
$trackName = $currentTrack->Name;
$trackNumber = $currentTrack->TrackNumber;
$albumName = $currentTrack->Album;
$artistName = $currentTrack->Artist;

echo $currentTrack;

 

This is what I get:

 

 

Catchable fatal error: Object of class variant could not be converted to string in E:\xampp\htdocs\itunes.php on line 18

 

Link to comment
https://forums.phpfreaks.com/topic/54479-catchable-fatal-error/
Share on other sites

I'm not positive what is causing your error; but I found this on php.net :::::::::::

 

 

 

As of (at least) PHP 5.2, you can no longer convert an object to a string unless it has a __toString method. Converting an object without this method now gives the error:

 

PHP Catchable fatal error:  Object of class <classname> could not be converted to string in <file> on line <line>

 

Try this code to get the same results as before:

 

<?php

 

if (!is_object($value) || method_exists($value, '__toString')) {

    $string = (string)$value;

} else {

    $string = 'Object';

}

 

?>

 

 

---------

 

Hope that helps.

Link to comment
https://forums.phpfreaks.com/topic/54479-catchable-fatal-error/#findComment-269463
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.