Req #29973 [Asn->Opn]: Comparing COM object variable with NULL throws an exception

From: Date: Fri, 13 Dec 2013 07:44:07 +0000
Subject: Req #29973 [Asn->Opn]: Comparing COM object variable with NULL throws an exception
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183292@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=29973&edit=1 ID: 29973 Updated by: wez@php.net Reported by: tetikr at spytech dot cz Summary: Comparing COM object variable with NULL throws an exception -Status: Assigned +Status: Open Type: Feature/Change Request Package: COM related Operating System: Win2003 PHP Version: 5.* -Assigned To: wez +Assigned To: Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2005-03-25 09:28:06] tetikr at spytech dot cz The problem is still there. Testing a COM object created by the new operator or return by a COM property/method on NULL throws an exception "Member not found.". Using the is_object() function helps, but it is inconvenient and ugly. Let's make PHP better :-) ------------------------------------------------------------------------ [2004-09-09 21:25:51] wez@php.net 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. ------------------------------------------------------------------------ [2004-09-06 14:27:03] tetikr at spytech dot cz 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; --------------------------------- ------------------------------------------------------------------------ [2004-09-06 08:06:19] derick@php.net What is the full error message? ------------------------------------------------------------------------ [2004-09-03 19:08:58] 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? ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=29973&edit=1

« previous php.bugs (#183292) next »