Link to home
Start Free TrialLog in
Avatar of huji
hujiFlag for United States of America

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\\com.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?
if(class_exists('COM'))
{
	$util = new COM('CAPICOM.Utilities.1');
	try {
		$output = base64_decode($util->GetRandom($count, 0));
	}
	catch(Exception $ex) { }
}

Open in new window

Avatar of Avinash Zala
Avinash Zala
Flag of India image

GetRandom function is not exist in your class  COM.


Hope this helps.
Addy
Avatar of vidularandunu
vidularandunu

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)
Avatar of huji

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?
There must be a fatal error in your com.php class. The $util varible never gets an instanc e of the COM class.
Avatar of huji

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.
Avatar of huji

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.
Avatar of huji

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.
Avatar of huji

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));

Open in new window

Avatar of huji

ASKER

I still get the same fatal error.

For some reason, I can't have PHP access that COM object correctly. Any idea?
ASKER CERTIFIED SOLUTION
Avatar of huji
huji
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial