huji
asked on
"Call to undifined method" error for existing function
Using the attached code snippet, I get the following fatal error:
PHP Fatal error: Call to undefined method com::GetRandom() in C:\\Inetpub\\apacheroot\\c om.php on line 7
I'm running PHP 5.2.6 on Apache on Windows XP.
My questions are: (1) Why can't I access the GetRandom function? (2) Why doesn't this fatal error get handled by the try..catch?
PHP Fatal error: Call to undefined method com::GetRandom() in C:\\Inetpub\\apacheroot\\c
I'm running PHP 5.2.6 on Apache on Windows XP.
My questions are: (1) Why can't I access the GetRandom function? (2) Why doesn't this fatal error get handled by the try..catch?
if(class_exists('COM'))
{
$util = new COM('CAPICOM.Utilities.1');
try {
$output = base64_decode($util->GetRandom($count, 0));
}
catch(Exception $ex) { }
}
the GetRandom method probably isn't implemented in the COM class... verify by looking inside com.php
Fatal errors are fatal and will stop php execution. Those can't be catched (as e.g. compile errors)
ASKER
Excuse me but I'm confused. GetRandom is a member function of the COM object I'm creating:
http://msdn.microsoft.com/en-us/library/aa388182%28VS.85%29.aspx
Why can't I call it?
http://msdn.microsoft.com/en-us/library/aa388182%28VS.85%29.aspx
Why can't I call it?
There must be a fatal error in your com.php class. The $util varible never gets an instanc e of the COM class.
ASKER
That is all of the code? Should I add something, or is there something wrong with my PHP installation?
It looks like your CAPICOM isnt registered correcly with windows. You can try to reinstall it.
have you installed capicom????
http://www.microsoft.com/downloads/details.aspx?FamilyId=860EE43A-A843-462F-ABB5-FF88EA5896F6&displaylang=en
http://www.microsoft.com/downloads/details.aspx?FamilyId=860EE43A-A843-462F-ABB5-FF88EA5896F6&displaylang=en
ASKER
How can I do that?
through the link you posted i understood that 'capicom.dll' is associated with this COM and did a search in my machine (XP SP3)..couldn't find it so it probably isn't installed by default. so click on that link i posted before, download the package, install it...reboot the pc and try again and see.
ASKER
The point is that I have the DLL and I can find it in my registry too, so I think it is installed (I wonder why you don't have it since it comes on Windows XP by default). Anyways, I'm going to give your solution a try.
ASKER
Didn't help :(
my god...okay here's the solution...and i have absolutely NO idea why your code doesn't work...but try it this way...i just checked it and got it to work... i found the solution in the php bug repots...apparently it's not a bug at all.
$count = 10;
try{
$util = new COM('CAPICOM.Utilities.1');
}
catch(Exception $ex)
{
echo $ex->getMessage();
}
$output = base64_decode($util->GetRandom($count,0));
ASKER
I still get the same fatal error.
For some reason, I can't have PHP access that COM object correctly. Any idea?
For some reason, I can't have PHP access that COM object correctly. Any idea?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hope this helps.
Addy