Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 654
  • Last Modified:

Fatal error: Call to undefined function

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
allelopath
Asked:
allelopath
  • 3
  • 3
  • 2
1 Solution
 
Diablo84Commented:
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
 
allelopathAuthor Commented:
good idea.  getmxrrWindows() was indeed after validateEmail(), but I moved it and the error still occurs.
0
 
Diablo84Commented:
hmm, i cannot recreate the error on my XP box, still thinking...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
_GeG_Commented:
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
 
allelopathAuthor Commented:
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
 
_GeG_Commented:
then you will have to use $this->getmxrrWindows();
0
 
allelopathAuthor Commented:
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
 
_GeG_Commented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now