|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-09-03 19:08 UTC] tetikr at spytech dot cz
Description:
------------
Comparing COM object variable with NULL throws an exception
Reproduce code:
---------------
$a = new COM(.....);
if (!$a)
{
......
}
else
{
.....
}
Expected result:
----------------
If $a is non null, I expect the ELSE block to be performed.
Actual result:
--------------
PHP throws an exception when trying to evaluate !$a. I think it tries to access the default COM object's property.
If this is a valid behavior, how should I test for null?
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 18:00:01 2025 UTC |
Some objects work and some not. The following code creates an object that works not. It throws a COM exception "Member not found". Test it for yourself, I hope it will fail :-) --------------------------------- $o = new COM("WScript.Shell"); if (!$o) /* dummy */ ; else echo $o->CurrentDirectory; ---------------------------------in this case you should be doing: try { $a = new COM(...); // use it here } catch (exception $e) { // failed to create it } in other cases, where you have been passed the object, use is_object() to check if it is valid. I'll see if I can fix the shorthand "if (!$a)" syntax someone in the next month.