android6011 Posted June 6, 2007 Share Posted June 6, 2007 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 More sharing options...
jscix Posted June 6, 2007 Share Posted June 6, 2007 which line is. # 18? Link to comment https://forums.phpfreaks.com/topic/54479-catchable-fatal-error/#findComment-269462 Share on other sites More sharing options...
jscix Posted June 6, 2007 Share Posted June 6, 2007 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 More sharing options...
android6011 Posted June 6, 2007 Author Share Posted June 6, 2007 how do i apply that to my current code though? Link to comment https://forums.phpfreaks.com/topic/54479-catchable-fatal-error/#findComment-269470 Share on other sites More sharing options...
jscix Posted June 6, 2007 Share Posted June 6, 2007 To be honest, I haven't coded anything like that,(OOP) yet. But I can help you figure it out. Which line is #18? Link to comment https://forums.phpfreaks.com/topic/54479-catchable-fatal-error/#findComment-269477 Share on other sites More sharing options...
android6011 Posted June 6, 2007 Author Share Posted June 6, 2007 line 18 is echo $currentTrack; Link to comment https://forums.phpfreaks.com/topic/54479-catchable-fatal-error/#findComment-269479 Share on other sites More sharing options...
jscix Posted June 6, 2007 Share Posted June 6, 2007 What happens when you run this; print ($iTunes->CurrentTrack); Link to comment https://forums.phpfreaks.com/topic/54479-catchable-fatal-error/#findComment-269483 Share on other sites More sharing options...
android6011 Posted June 6, 2007 Author Share Posted June 6, 2007 i know why. i dont need to convert it. the variables below it work fine when i print them. thanks for the help Link to comment https://forums.phpfreaks.com/topic/54479-catchable-fatal-error/#findComment-269484 Share on other sites More sharing options...
jscix Posted June 6, 2007 Share Posted June 6, 2007 ah ok. no problem, glad ya got it. I'm curious why you couldn't print $iTunes->CurrentTrack Though.. It seems to just be an array. /shrug I'll look it up. Link to comment https://forums.phpfreaks.com/topic/54479-catchable-fatal-error/#findComment-269490 Share on other sites More sharing options...
per1os Posted June 6, 2007 Share Posted June 6, 2007 var_dump($iTunes->CurrentTrack); Try that? Link to comment https://forums.phpfreaks.com/topic/54479-catchable-fatal-error/#findComment-269495 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.