php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25759 COM Instantiation causes Script to fail silently
Submitted: 2003-10-06 09:26 UTC Modified: 2003-11-28 09:18 UTC
From: david dot nicholls at camden dot gov dot uk Assigned: wez (profile)
Status: Closed Package: COM related
PHP Version: 5CVS-2003-10-06 (dev) OS: Windows 2000
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: david dot nicholls at camden dot gov dot uk
New email:
PHP Version: OS:

 

 [2003-10-06 09:26 UTC] david dot nicholls at camden dot gov dot uk
Description:
------------
Following on from bug 25732 I am trying PHP5-dev from CVS

Code that worked previously under 4.3.3 now fails silently

error_reporting = E_ALL is set

Reproduce code:
---------------
$acctDomain = "Camden";
echo "Making COM connection using ADSI\n\r";
$acctStr = "WinNT://".$acctDomain;
echo "$acctStr\n\r";
$comUsers = new COM($acctStr);
echo "new COM Sucessful";

Expected result:
----------------
'new COM Sucessful' to be printed at console or an error code

Actual result:
--------------
Nothing, just brings back command promt


C:\Inetpub\wwwroot\ntadmin>php comtest.php
Content-type: text/html
X-Powered-By: PHP/5.0.0b2-dev

Making COM connection using ADSI
WinNT://Camden

C:\Inetpub\wwwroot\ntadmin>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-06 09:43 UTC] wez@php.net
Try it with exception handlers: 

try {
  $comUsers = new COM($acctStr);
}
catch (exception $e) {
  print_r($e);
}
 [2003-10-06 09:59 UTC] david dot nicholls at camden dot gov dot uk
Looks like PHP is messing up valid syntax


exception Object
(
    [message:protected] => Unknown exception
    [string:private] =>
    [code:protected] => 0
    [file:protected] => C:\Inetpub\wwwroot\ntadmin\comtest.php
    [line:protected] => 15
    [trace:private] => Array
        (
        )

    [message] => Failed to create COM object `WinNT://Camden': Invalid syntax

    [file] => C:\Inetpub\wwwroot\ntadmin\comtest.php
    [line] => 15
)
 [2003-10-06 11:09 UTC] wez@php.net
I've comitted a quick little "fix" for this; you can
pick it up in the next development snapshot in around
3 hours time.
Please let me know if it works for you.
 [2003-10-07 07:40 UTC] david dot nicholls at camden dot gov dot uk
The bug fix worked thanks and I can now do the instatitaion. However there are issues at the next stage :(

This works under 4 and not 5 

I suspect "while($obj = $comUsers->Next())" (dont know how to put in the exception handling code there)


<?php
$acctDomain = "Camden";
echo "Making COM connection using ADSI\n\r";
$acctStr = "WinNT://".$acctDomain;
echo "$acctStr\n\r";

$comUsers = new COM($acctStr);
echo "Bound";

while($obj = $comUsers->Next()) {
	$uClass = $obj->Class;
	$uName = $obj->Name;
  	echo "$uName \t $uClass \n\r";
}
?>
 [2003-10-07 07:42 UTC] david dot nicholls at camden dot gov dot uk
Should add fails silently after echoing 'Bound' to console
 [2003-10-07 08:45 UTC] wez@php.net
Put the try { } catch () stuff around the whole of your script and lets see what's going wrong.
(Yes, PHP should at least tell you about the uncaught
exception; that appears to be another bug)
 [2003-10-07 08:52 UTC] david dot nicholls at camden dot gov dot uk
Its one of the usefule errors :)

C:\Inetpub\wwwroot\ntadmin>php comtest.php
Content-type: text/html
X-Powered-By: PHP/5.0.0b2-dev

Making COM connection using ADSI
WinNT://Camden
Boundexception Object
(
    [message:protected] => Unknown exception
    [string:private] =>
    [code:protected] => 0
    [file:protected] => C:\Inetpub\wwwroot\ntadmin\comtest.php
    [line:protected] => 12
    [trace:private] => Array
        (
        )

    [message] => <b>Source:</b> Active Directory<br/><b>Description:</b> Unspecified error

    [file] => C:\Inetpub\wwwroot\ntadmin\comtest.php
    [line] => 12
)

C:\Inetpub\wwwroot\ntadmin>


Line 12 is the 'while' line
 [2003-10-07 09:21 UTC] wez@php.net
One of the differences between PHP 4 COM and PHP 5 COM is that PHP doesn't do magic for IEnumXXX interfaces, and that
is what I suspect the problem is here.

That means that the magical $obj->next() stuff won't
work, and should never have worked in the first place,
because they aren't really methods of the com object,
but of an iterator interface. (The PHP 4 COM stuff had
quite a few of these hacks).

The plan for PHP 5 is to allow this:

foreach ($comUsers as $user) {
    $uClass = $obj->Class;
    $uName = $obj->Name;
    echo "$uName \t $uClass \n\r";
}

but to implement that, I'm waiting for some
engine magic, so I'll prod the relevant
people about it.

 [2003-10-07 09:23 UTC] wez@php.net
of course, I meant this:

foreach ($comUsers as $user) {
    $uClass = $user->Class;
    $uName = $user->Name;
    echo "$uName \t $uClass \n\r";
}

I'll look into the API docs for ADSI later
to sanity check my other comments also.
 [2003-10-07 09:44 UTC] david at replicant dot org dot uk
Many thanks for your time.

The foreach contruct use appeals to my sensibilites much more than the while one.

Hope the proding gets the results :) 

- i'm stuck at the momement as PHP4 wont be changed to fix to a show stopping bug and 5 wont work yet.
 [2003-11-28 09:18 UTC] wez@php.net
Fixed some time ago.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 20:01:28 2024 UTC