Why is a fatal error being generated when invoking a new class instance in Joomla?

93 views Asked by At

One of our company web application's functions recently stopped working properly. The application was built with Joomla. The error log is generating this fatal error:

PHP Fatal error:  Class 'getXML' not found in /var/www/mycompanysite.com/html/display/listener.php on line 5

The code block in question here looks like this ($insert_sql is a dummy query for testing only, same fatal error without this query present):

<?php
include("config.php");// $myVar = 4 in this file, test #1
include("message.class.php"); //$myVar = 5 in this file, separate test #2
$xml = $_REQUEST['messagelist'];
$insert_sql = mysql_query("insert into messages (message, pid) values ('".$myVar."','999999');");
$retrieverobj = new getXML($xml);

    // etc.   

The files config.php and message.class.php are both in the same folder as listener.php (I have changed both includes to reference the file's absolute path but same result), so the path should not be an issue. I have done two tests. In the first test (config.php), the value 4 appears in the messages table (in the message column) after the script runs, so the first include works for config.php it appears. In the second test, the value 5 does NOT appear after the script runs, (a null appears to be inserted), so the second include seems to be failing.

I am new to Joomla, so I thought it might have some class naming convention (since the class name is getXML and the file name is message.class.php). So I retried with this line in my second include statement:

include("getXML.class.php"); //also tried as include("getXML.php"); 

but the same fatal error resulted (and I also tried as require instead of include).

Here is the class in question (I should add that when I even delete the entire function, so that only class getXML{} is present as an empty class, the fatal error is still present):

class getXML{

function getXML($incomingMessage){

    global $keyword, $phonenumber, $carriercode, $messagebody;

    $messagelist_xml = simplexml_load_string(stripslashes($incomingMessage));

    $from = urldecode($messagelist_xml->{'message-list'}->message->from);

    $messagebody = urldecode($messagelist_xml->{'message-list'}->message->body);

    $keywordarray=explode(" ",$messagebody);

    $keyword = $keywordarray[0];

    if($_GET['keyword'] != ''){

        $keyword = $_GET['keyword'];

    }

    $phonenumber= substr($from,-10);

    $carriercode= strstr($from, '=');
    $carriercode= substr($carriercode,1,5);

    }
}

Any ideas on what is happening here? Why is the second include failing on this Joomla site?

1

There are 1 answers

4
meda On

Im not sure if you are allowed to use the same class name and function name:

class getXML{

function getXML($incomingMessage){

The bigger problem is you don't have a constructor that takes an argument

So try to change it to :

public function __construct($incomingMessage)
{

And also pick better names for a class.