"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

LVL 14
hujiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Avinash ZalaWeb ExpertCommented:
GetRandom function is not exist in your class  COM.


Hope this helps.
Addy
vidularandunuCommented:
the GetRandom method probably isn't implemented in the COM class... verify by looking inside com.php
hernst42Commented:
Fatal errors are fatal and will stop php execution. Those can't be catched (as e.g. compile errors)
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

hujiAuthor Commented:
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?
Adoryc666Commented:
There must be a fatal error in your com.php class. The $util varible never gets an instanc e of the COM class.
hujiAuthor Commented:
That is all of the code? Should I add something, or is there something wrong with my PHP installation?
Adoryc666Commented:
It looks like your CAPICOM isnt registered correcly with windows. You can try to reinstall it.
hujiAuthor Commented:
How can I do that?
vidularandunuCommented:
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.
hujiAuthor Commented:
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.
hujiAuthor Commented:
Didn't help :(
vidularandunuCommented:
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

hujiAuthor Commented:
I still get the same fatal error.

For some reason, I can't have PHP access that COM object correctly. Any idea?
hujiAuthor Commented:
Found the solution myself in the "comments" section of http://bugs.php.net/bug.php?id=48498

I had CAPICOM installed but I had to register the DLL by hand:
regsvr32 capicom.dll

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.