Page 1 of 1

Call to undefined function? Bollocks.

Posted: Tue Jul 21, 2009 3:30 pm
by jawaiah
If anyone could help me debug this I would much appreciate it.
PHP is not my native tongue so I'm pretty sure my syntax might be muddled with C or FORTRAN or ADA or something.

When my script is interpreted I get this error:

Fatal error: Call to undefined function recursiveFindPath() in /net/koaserver/koadata2/*****/database.v1.inc on line 99

I've been staring at the code for about...oh, 13 hours straight now. I took out a few little syntactical ambiguities (my background is with C++ so I thought this would solve it) but to no avail. It would be nice if it was an obvious problem, don't be afraid to call me a f*ing idiot for missing it.


Here is the function call and the function in question.
The line that generates an error is in the call in findPath().
I've included the few lines that lead up to the end of the class as well:

***edit : I took out the comments for readability ***

Code: Select all

function findPath($start, $goalfield)    
    {                                              
        $visited[$start] = TRUE;
                   //ERROR HERE
        return recursiveFindPath($start, $nulllink, $visited, $goalfield); 
                   //OMGHAXCWTF
    }
    
function recursiveFindPath($current, $linkfield, $visited, $goalfield) 
    {
        if(in_array($current, $this->links[$goalfield]))           
            return array($current, $linkfield);             
            
       else                                          
       {
          foreach($this->adjacency[$current] as $next => $nextlink)
             if(!$visited[$next] && $nextlink != $linkfield)  
                {                                      
                    $visited[$next] = TRUE;
                    $path = recursiveFindPath($next, $nextlink, $visited, $goalfield);
                                     
                    if($path) return array_unshift($path, array($current, $linkfield));
                }        
                
            return FALSE;
        }
    }
    
    function doQuery($query)                    
    {
        return mysql_query($query, $this->db);
    }
    
    function dbClose()                          
    {
        mysql_close($this->db);
    }
}
?> 

Re: Call to undefined function? Bollocks.

Posted: Tue Jul 21, 2009 3:38 pm
by requinix
jawaiah wrote:***edit : I took out the comments for readability ***
Wow. Never thought I'd see that happen.


That lone } at the bottom (line 38): what's it closing?

Re: Call to undefined function? Bollocks.

Posted: Tue Jul 21, 2009 3:42 pm
by jawaiah
tasairis wrote:
jawaiah wrote:***edit : I took out the comments for readability ***
Wow. Never thought I'd see that happen.
LOL yeah they were wrapping and interrupting the flow of code. I figure it's syntax i need help with, not theory or code semantics, so better to see raw code.
tasairis wrote:That lone } at the bottom (line 38): what's it closing?
It's closing the database class.

Just for clarification, recursiveFindPath is a depth-first-search through my database map array, which I've stored as an adjacency list and matrix.

Re: Call to undefined function? Bollocks.

Posted: Tue Jul 21, 2009 4:00 pm
by Darhazer
if recursiveFindPath is in a class, then you should call it using $this->recursiveFindPath() syntax

Re: Call to undefined function? Bollocks.

Posted: Tue Jul 21, 2009 4:03 pm
by Christopher
jawaiah wrote:Just for clarification, recursiveFindPath is a depth-first-search through my database map array, which I've stored as an adjacency list and matrix.
To call methods from within a class you need to do:

Code: Select all

                    $path = $this->recursiveFindPath($next, $nextlink, $visited, $goalfield);
Or public methods from outside:

Code: Select all

                    $path = $foo->recursiveFindPath($next, $nextlink, $visited, $goalfield);
Or statically from outside:

Code: Select all

                    $path = Foo::recursiveFindPath($next, $nextlink, $visited, $goalfield);
You might want to read the excellent sections in the PHP manual on objects/classes (instead of "staring at the code for about...oh, 13 hours straight now" ;))

http://www.php.net/manual/en/langref.php

Re: Call to undefined function? Bollocks.

Posted: Tue Jul 21, 2009 4:04 pm
by jawaiah
Darhazer wrote:if recursiveFindPath is in a class, then you should call it using $this->recursiveFindPath() syntax
That would be the problem indeed.
I knew it was c++/php confusion... I was aware of the $this-> syntax.
It just looked so right. I won't forget that syntax construct again!

I guess it just took a pair of fresh eyes.
Thank you very much Darhazer.