Solved

Fatal error: Call to undefined function

Posted on 2004-09-02
8
626 Views
Last Modified: 2008-01-09
I get this error in my PHP code on a Windows NT server:
Fatal error: Call to undefined function: getmxrrwindows() in ...\formprocessor.php on line 219

On my linux machine, the code works.

I am working around the fact the PHP windows does not have a getmxrr() function.
So I have a version for windows, called getmxrrWindows().
The function declaration and call have a 'W' while the function specified in the error has a 'w',
which is mysterious.  What is the problem?

code snippets:

function validateEmail($email)
{
  // Create the syntactical validation regular expression
  $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";

  $valid = false; // assume it is not valid

  // if syntax is valid then
  if (eregi($regexp, $email))
  {

    list($username,$domaintld) = split("@",$email);  // get domain
    $os = strtoupper(substr(PHP_OS, 3));
    echo $os;  // 'NT' for NT machine, 'UX' for linux
    echo "<br>";
   
    // check if domain is valid using getmxrr()
    // getmxrr() is not available on windows platforms, so use home-grown version
    // if server is windows NT then
    if(substr_count(strtoupper(PHP_OS), 'NT'))
    {
      if (getmxrrWindows ($domaintld,$mxrecords) ) // ERROR HERE *****************************
      {
        $valid = true;
      }
    }
    else // server OS is not NT
    {
      if (getmxrr ($domaintld,$mxrecords) )
      {
        $valid = true;
      }
    }
  }

  return $valid;
}


function getmxrrWindows($hostname, &$mxhosts)
{
   $mxhosts = array();
   exec('nslookup -type=mx '.$hostname, $result_arr);
   foreach($result_arr as $line)
   {
     if (preg_match("/.*mail exchanger = (.*)/", $line, $matches))
         $mxhosts[] = $matches[1];
   }
   return( count($mxhosts) > 0 );
}  

0
Comment
Question by:allelopath
  • 3
  • 3
  • 2
8 Comments
 
LVL 27

Expert Comment

by:Diablo84
ID: 11963547
I seem to remember on Windows you must define the function before you call it so try moving the getmxrrWindows above the validateEmail function, you said the above is just code snippets so this may already be the case, if not i'd like you to try it.
0
 
LVL 1

Author Comment

by:allelopath
ID: 11963949
good idea.  getmxrrWindows() was indeed after validateEmail(), but I moved it and the error still occurs.
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 11964162
hmm, i cannot recreate the error on my XP box, still thinking...
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 9

Expert Comment

by:_GeG_
ID: 11964278
hmm, is it possibe that you declare the function in the wrong context?
like
class xx{
function getmxrrWindows($hostname, &$mxhosts)
{...}
}

or function xxx{
...
function getmxrrWindows($hostname, &$mxhosts)
{...}
}

check your }s ;)
0
 
LVL 1

Author Comment

by:allelopath
ID: 11964602
GeG,
I understand why your 2nd example would be a problem and no, i''m not doing that.
I think my structure is like your 1st example, but i don't see why that's a problem.

I have:

<?php
...
// instantiate it here
$formProcessor = new FormProcessor();
...
class FormProcessor
{
...
function getmxrrWindows($hostname, &$mxhosts)
{
...
}
function validateEmail($email)
{
... // call to getmxrrWindows();
}
...
} // end class
?>
0
 
LVL 9

Accepted Solution

by:
_GeG_ earned 125 total points
ID: 11965121
then you will have to use $this->getmxrrWindows();
0
 
LVL 1

Author Comment

by:allelopath
ID: 11966663
Thanks, i was so focused on the "W" vs "w" thing, that i overlooked the real issue.
I guess Apache outputs messages in all lowercase.
In addition to referring to the function name in all lowercase, it did so with the path and filename, e.g. the filename is FormProcessor.php but it referred to as formprocessor.php in the error message.

Thanks, Diablo 84, for you input as well.
0
 
LVL 9

Expert Comment

by:_GeG_
ID: 11968827
no, it's not apache, I think it's a windows issue. I was also wondering when I saw my variables and paths in lowercase on command line php under windows, but I always thought wtf, so I still don't know why.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question