You are here:  » MagicParser_parse and function myRecordHandler() inside of a class


MagicParser_parse and function myRecordHandler() inside of a class

Submitted by hmaurich on Tue, 2007-07-03 22:44 in

Hi, I worked with MagicParser well until I wanted to use it from inside a class like this:

<?php
class ClassWithMagicParser
{
   public    
$error;
   ...
 function 
__construct ()
 {
  
$format_string = ...;
  ...
 }
 function 
MethodWithMagicParser ()
 {
  ...
  
$data = ...;
  ...
  function 
myRecordHandler($item)
  {
   
// return a non-zero value to stop reading any more records
   
return 1;
  }
  ...
  if(
MagicParser_parse("string://".$data,"myRecordHandler",$this->format_string))
  {
   
$this->error MagicParser_getErrorMessage();
  }
  ...
 }
?>

I got no ErrorMessage and no result. The script simply stops.
Instead of "myRecordHandler" in MagicParser_parse(...) I tryed also $this->myRecordHandler - no success.

May I use MagicParser from inside of a class?

Thanks, Hans-Martin

Submitted by support on Wed, 2007-07-04 03:28

Hello Hans-Martin,

Because Magic Parser uses a variable-function name callback and also makes use of its own global variables i'm afraid you won't be able to use it within a class. Apologies for any inconvenience.

Regards,
David.

Submitted by hmaurich on Wed, 2007-07-04 07:41

Thanks for fast answering!

I'll use SimpleXML instead of MagicParser in my class.

Hans-Martin Aurich
Internetservice
www.WebConsultant.de