Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help - Call to a member function on a non-object

Status
Not open for further replies.

sd0t1

IS-IT--Management
Mar 14, 2007
131
US
I am getting a fatal error "Fatal error: Call to a member function setStopTime() on a non-object in C:\wamp\ on line 39"

Line 39 is $m->setStopTime ( $attributes->time );
Line 40 is $m->setStartTime ( $startTime );

Can anyone help me understand this. The start and stop times are not objects but string values that I am assigning to setStartTime and setStopTime.
Am I trying to convert it to an object in order to get past the fatal error (if so, how) or am I violating some coding rule?


Code:
<?php
class FindXML extends ReadXML{
	
	public $path;
	public $rootFolder;
	public $files = array ();
	
	public function __construct(){
		include_once('ReadXML.php');
	}
	
	public function setRootDirectory($dirPath){
		$this->rootFolder = $dirPath;
	}
	
	public function loadXMLtoDatabase() {
		
	(array)	$arrDirList = ReadXML::scanFilesFolders($this->rootFolder);		
		$a = new ArrayObject ($arrDirList , ArrayObject::STD_PROP_LIST );
		foreach ( $a as $path ) {
			if (is_file ( $path )) {
				if (strpos ( "$path", "xml" )) {
					echo $path . "<br />";
					try {
						// code here
						$s = simplexml_load_file ((string) $path, 'SimpleXMLElement', LIBXML_NOCDATA );
						echo '<pre>';
					} catch ( Exception $e ) {
						echo $e->getMessage ();
					}
					foreach ( $s->header as $header ) :
						foreach ( $s->event as $key => $event ) :
							$attributes = $event->attributes ();
							if ($attributes->type == 'system') :
								if (strpos ( $event->text, 'Start Cap' ) !== false) :
									$startTime = $attributes->time;
									$asfFileName = $event->text;
								 elseif (strpos ( $event->text, 'Stop Cap' ) !== false) :
									$m->setStopTime ( $attributes->time );
									$m->setStartTime ( $startTime );
									$startTime = null;
									$m->save ();
								endif;
							 elseif ($attributes->type == 'case') :
								$m = new ReadXML();
								$m->load ( $m->merge ( $event->case, $header ) );
							endif;
						endforeach
						;
						echo print_r ( $m->merge ( $event->case, $header ) );
					endforeach
					;
				}
			
			}
		}
	}
}
 
it means that you have not correctly instantiated $m.
and in the loadXMLtoDatabase method I do not see any assignment to 4m or any import of a global $m variable.
 
In other words $m is not a valid object so it can't have a member function to be called.

Instantiate $m and assuming the class from which $m is instantiated has those functions, they'll then be available to $m.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top