Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Fatal error: Call to undefined function

Posted on 2004-09-02
8
629 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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 count occurrences of each item in an array.

856 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