...

View Full Version : PHP Class function - cannot find...



BWiz
01-01-2008, 05:18 PM
Hi, I'm creating my mod_rewrite engine right now, and I'm having some problems with referencing a function within the class.

heres the code:


class query {
private $query_string;
private $raw_query;
private $fixed_query;

function get() {
$raw_query = $_SERVER['REQUEST_URI'];
process_query();
}

function process_query() {

}
}
I'm trying to get the query string through this:


$q = new Query();
print $q->get();
As you can see, in the get() function, which is the only function that I should have access to (and the function which eventually returns the processed query string), I reference a function process_query(), however, in doing so I receive this error:
Fatal error: Call to undefined function process_query()

I've tried using property declarations, however that doesn't work either. Any help to this matter would be greatly appreciated.

GJay
01-01-2008, 06:48 PM
when you're accessing a property or method of the object from within it, you need to use the 'special' $this variable:


class query {

function get() {
$raw_query = $_SERVER['REQUEST_URI'];
$this->process_query();
}

function process_query() {

}
}

Fou-Lu
01-02-2008, 03:32 AM
Yes oh this drives me INSANE!
PHP's required usage of $this is absolutly the only reason why I use 'this' in any other programming language (unless its the scope based stuff). Drives me nuts.
Oh and by the way, you can actually access the process_query() method from the object, the default scope of php is public, unlike other languages (protected in java, internal in c#, etc), so if you don't give it a scope it assumes to be public.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum