Solved

Fatal error: Call to undefined function

Posted on 2004-09-02
8
619 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 dynamically set the form action using jQuery.

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now