php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38985 Can't cast COM objects to boolean
Submitted: 2006-09-28 19:55 UTC Modified: 2006-10-07 19:58 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: larry dot menard at rogers dot com Assigned: ilia (profile)
Status: Closed Package: COM related
PHP Version: 5.2.0RC4 OS: Windows XP, SP2
Private report: No CVE-ID: None
 [2006-09-28 19:55 UTC] larry dot menard at rogers dot com
Description:
------------
First of all, I'm usng RC5, not RC4 (RC5 is not in the list above).

Can't cast an object of type COM to boolean.

Reproduce code:
---------------
$dbc = new COM('WinNT://Domain'); var_dump((bool)$dbc);

Expected result:
----------------
bool(true)

Actual result:
--------------
Catchable fatal error:  Object of class com could not be converted to boolean

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-06 01:17 UTC] wez@php.net
batting back to you Tony; between moving offices this last week and a dead laptop I don't have a win32 build environment and won't have one in time to get this fixed for 5.2.

As per our email discussion, I think the fix for this issue is to not return failure from the COM object cast handler in the case that we can't convert to variant bool, but to use regular PHP boolean cast at that point (after trying variant bool conversion) and returning success.

 [2006-10-06 06:48 UTC] tony2001@php.net
No idea why it was assigned to me.
I've never had win32 build env.
 [2006-10-06 12:05 UTC] wez@php.net
I think this one liner will do the job, but haven't been able to verify it:

Index: com_handlers.c
===================================================================
RCS file: /repository/php-src/ext/com_dotnet/com_handlers.c,v
retrieving revision 1.37
diff -u -p -r1.37 com_handlers.c
--- com_handlers.c      29 Apr 2006 18:45:29 -0000      1.37
+++ com_handlers.c      6 Oct 2006 12:03:31 -0000
@@ -539,7 +539,7 @@ static int com_object_cast(zval *readobj
                return SUCCESS;
        }
 
-       return FAILURE;
+       return zend_std_cast_object_tostring(readobj, writeobj, type TSRMLS_CC);
 }
 
 static int com_object_count(zval *object, long *count TSRMLS_DC)
cvs diff: Diffing tests


 [2006-10-06 12:25 UTC] edink@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2006-10-07 19:58 UTC] larry dot menard at rogers dot com
Confirmed, it now works.  Thanks!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 19:01:28 2024 UTC