ars_moriendi Posted July 20, 2007 Share Posted July 20, 2007 Thanks everyone for all the help you've been. Now, I'm having a problem in that, when I turn my code into a class, it fails to instantiate. I've looked at the documentation for how PHP treats objects--fairly simple--and I'm stumped. I know I'm missing something obvious. Any ideas? <?php class eventList { $stack = array(); $tagname=""; function create($filename) { if (! ($xmlparser = xml_parser_create()) ) { die ("Cannot create parser"); } function start_tag($parser, $name, $attribs) { global $tagname; $tagname = $name; } function end_tag($parser, $name) { } function tag_contents($parser, $data) { global $tagname; global $stack; $stack[$tagname]=$data; } xml_set_element_handler($xmlparser, "start_tag", "end_tag"); xml_set_character_data_handler($xmlparser, "tag_contents"); if (!($fp = fopen($filename, "r"))) { die("cannot open ".$filename); } while ($data = fread($fp, 4096)) { $data=eregi_replace(">"."[[:space:]]+"."<","><",$data); if (!xml_parse($xmlparser, $data, feof($fp))) { $reason = xml_error_string(xml_get_error_code($xmlparser)); $reason .= xml_get_current_line_number($xmlparser); die($reason); } } xml_parser_free($xmlparser); } } $event1=new eventList(); $event1->create("http://www.example.com/rss.xml"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/61003-solved-converting-object-to-class/ Share on other sites More sharing options...
per1os Posted July 20, 2007 Share Posted July 20, 2007 class eventList { var $stack = array(); var $tagname=""; function create($filename) { if (! ($xmlparser = xml_parser_create()) ) { die ("Cannot create parser"); } function start_tag($parser, $name, $attribs) { global $tagname; $tagname = $name; } function end_tag($parser, $name) { } function tag_contents($parser, $data) { global $tagname; global $stack; $stack[$tagname]=$data; } xml_set_element_handler($xmlparser, "start_tag", "end_tag"); xml_set_character_data_handler($xmlparser, "tag_contents"); if (!($fp = fopen($filename, "r"))) { die("cannot open ".$filename); } while ($data = fread($fp, 4096)) { $data=eregi_replace(">"."[[:space:]]+"."<","><",$data); if (!xml_parse($xmlparser, $data, feof($fp))) { $reason = xml_error_string(xml_get_error_code($xmlparser)); $reason .= xml_get_current_line_number($xmlparser); die($reason); } } xml_parser_free($xmlparser); } } $event1=new eventList(); $event1->create("http://www.example.com/rss.xml"); ?> Parse error for one, turn on display_errors and error_reporting to E_ALL and report any more errors. Quote Link to comment https://forums.phpfreaks.com/topic/61003-solved-converting-object-to-class/#findComment-303555 Share on other sites More sharing options...
ars_moriendi Posted July 20, 2007 Author Share Posted July 20, 2007 Sorry, I wanted to change my post, but I missed the time limit. The PHP install on my laptop has consistently failed time and again. Not sure why. Never had the time to figure it out. So, I have to upload my code to a shared hosting server to test. Is the error tracking something I can still do on shared hosting? Quote Link to comment https://forums.phpfreaks.com/topic/61003-solved-converting-object-to-class/#findComment-303559 Share on other sites More sharing options...
per1os Posted July 20, 2007 Share Posted July 20, 2007 Sorry, I wanted to change my post, but I missed the time limit. The PHP install on my laptop has consistently failed time and again. Not sure why. Never had the time to figure it out. So, I have to upload my code to a shared hosting server to test. Is the error tracking something I can still do on shared hosting? Should be www.php.net/display_errors www.php.net/error_reporting It is good to be disabled in production enviroments, but for testing you want them to show all errors. Quote Link to comment https://forums.phpfreaks.com/topic/61003-solved-converting-object-to-class/#findComment-303567 Share on other sites More sharing options...
ars_moriendi Posted July 20, 2007 Author Share Posted July 20, 2007 Sorry, I wanted to change my post, but I missed the time limit. The PHP install on my laptop has consistently failed time and again. Not sure why. Never had the time to figure it out. So, I have to upload my code to a shared hosting server to test. Is the error tracking something I can still do on shared hosting? Should be www.php.net/display_errors www.php.net/error_reporting It is good to be disabled in production enviroments, but for testing you want them to show all errors. Okay, I added error_reporting(E_ALL); error_reporting(E_PARSE); to the top of my script. No screen output. I checked my logs with the hosting company: nothing yet. On the other hand, the logs they (Globat) supply me look like they came out of a chron job so I may not get any error information until tomorrow. Quote Link to comment https://forums.phpfreaks.com/topic/61003-solved-converting-object-to-class/#findComment-303591 Share on other sites More sharing options...
per1os Posted July 20, 2007 Share Posted July 20, 2007 www.php.net/ini_set ini_set("display_errors", "on"); error_reporting(E_ALL); Try putting those at the top and see if it reports the error. Quote Link to comment https://forums.phpfreaks.com/topic/61003-solved-converting-object-to-class/#findComment-303596 Share on other sites More sharing options...
ars_moriendi Posted July 20, 2007 Author Share Posted July 20, 2007 Okay, I put the following code at the top of my script, including the parse error line separately because evidently E_ALL doesn't pick those up: ini_set("display_errors", "on"); error_reporting(E_ALL); error_reporting(E_PARSE); $p = getcwd(); error_log("ERRORS!", 3, $p."/my-errors.log"); I was hoping to redirect the error log to my working directory, but I'm still coming up with bupkiss. Quote Link to comment https://forums.phpfreaks.com/topic/61003-solved-converting-object-to-class/#findComment-303612 Share on other sites More sharing options...
ars_moriendi Posted July 20, 2007 Author Share Posted July 20, 2007 Okay, I put the following code at the top of my script, including the parse error line separately because evidently E_ALL doesn't pick those up: ini_set("display_errors", "on"); error_reporting(E_ALL); error_reporting(E_PARSE); $p = getcwd(); error_log("ERRORS!", 3, $p."/my-errors.log"); Before you say it--yes, I know that error log on line 5 was pointless. I tried both ini_set('display_errors','1'); and ini_set("display_errors", "on"); Any idea why these won't display to the page? Quote Link to comment https://forums.phpfreaks.com/topic/61003-solved-converting-object-to-class/#findComment-303638 Share on other sites More sharing options...
ars_moriendi Posted July 20, 2007 Author Share Posted July 20, 2007 Solution: Class variables not preceeded by var keyword: Example: class someclass { $tagname=""; // WRONG var $tagname=""; // RIGHT } Quote Link to comment https://forums.phpfreaks.com/topic/61003-solved-converting-object-to-class/#findComment-303666 Share on other sites More sharing options...
Barand Posted July 20, 2007 Share Posted July 20, 2007 Have a look at the first reply to your topic by frost110 and note the "var" kewords Quote Link to comment https://forums.phpfreaks.com/topic/61003-solved-converting-object-to-class/#findComment-303697 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.