Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7582839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:32:05+00:00 2026-05-30T18:32:05+00:00

I have written a php class with 2 functions in but when i call

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:32:06+00:00Added an answer on May 30, 2026 at 6:32 pm

    This is why:

    They both do this $this->rdf = join('', $this->rdf);

    and they both are conditional on this:

    if (is_array($this->rdf))
    

    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:

    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($data = $this->p->string2triples(join('',  $this->rdf), $this->uri))) {
         $val = $data["http://localhost/".$type][2][1][0];
    
         return $val;
      }
    }
    

    that way you’re not redefining $this->rdf in the methods, since as I see it there is no reason to do this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this database class in PHP and I only have 1 function
I have this piece of code written in jQuery and PHP: <script type=text/javascript> $(document).ready(function(){
For our online game, we have written tons of PHP classes and functions grouped
I have written a webservice using the PHP SOAP classes. It has functions to
I have a class with several functions that can render images. // render.php class
I have written the following db interface class: <?php // dbinterface.php class db {
I have a PHP script which works fine in PHP 5, but not in
I have written file form.php in application/classes/form.php <?php defined('SYSPATH') or die('No direct script access.');
I have a class written in php that is supposed to find the labels
in my php script at the top i have require_once('../registration/include/membersite_config.php'); wich is a class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.