Call to undefined function? Bollocks.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jawaiah
Forum Newbie
Posts: 4
Joined: Tue Jul 21, 2009 2:56 pm

Call to undefined function? Bollocks.

Post 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);
    }
}
?> 
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Call to undefined function? Bollocks.

Post 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?
jawaiah
Forum Newbie
Posts: 4
Joined: Tue Jul 21, 2009 2:56 pm

Re: Call to undefined function? Bollocks.

Post 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.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Call to undefined function? Bollocks.

Post by Darhazer »

if recursiveFindPath is in a class, then you should call it using $this->recursiveFindPath() syntax
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Call to undefined function? Bollocks.

Post 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
(#10850)
jawaiah
Forum Newbie
Posts: 4
Joined: Tue Jul 21, 2009 2:56 pm

Re: Call to undefined function? Bollocks.

Post 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.
Post Reply