I have written a php class with 2 functions in but when i call the functions inside of a different script it only allows 1 of the 2 functions to run.
this is the script with the functions.
<?php
define('RDFAPI_INCLUDE_DIR', 'rdfapi-php/api/');
require_once('SimpleRdfParser.php');
class retrieve{
public $p;
public $uri;
public $rdf;
function retrieve(){
$this->p = new SimpleRdfParser();
$this->uri = 'rdfs/crime.owl';
$this->rdf = @file($this->uri);
}
function getName(){
return "heyyy";
}
public function getL1Comment($type){
/*
this function gets the comments that are to do with the main type of crime i.e. Sexual Offences
*/
if (is_array($this->rdf)) {
$this->rdf = join('', $this->rdf);
if (is_array($data = $this->p->string2triples($this->rdf, $this->uri))) {
$val = $data["http://localhost/".$type][2][1][0];
return $val;
exit;
}
}
}
public function getChildComment($crime){
/*
this function gets the comments from the child node of the main type of crime i.e. Rape of a Female aged 16 and over,
this is a child node of Sexual Offences
*/
if (is_array($this->rdf)) {
$this->rdf = join('', $this->rdf);
if (is_array($data = $this->p->string2triples($this->rdf, $this->uri))) {
$val = $data["http://localhost/".$crime][2][1][0];
return $val;
exit;
}
}
}
}
and this is the script calling it:
<?php
require('retrieve.php');
$type = $_POST["type"];
$crime = $_POST["crime"];
$q = new retrieve();
echo $q->getL1Comment($type)."<br />";
//print($q->getL1Comment($type)."<br />");
print($q->getName());
//print($q->getName());
echo $q->getChildComment($crime);
?>
does anybody have any idea as to why this is happening?
thank you in advance
This is why:
They both do this
$this->rdf = join('', $this->rdf);and they both are conditional on this:
So the first is causing the array to no longer be an array. Thus, the second method’s conditional will fail.
Try something like this:
that way you’re not redefining $this->rdf in the methods, since as I see it there is no reason to do this.