views:

48

answers:

1

Hi,

I am trying to build a byte array in PHP using Variants. However, I can't seem to make it work. Here's a sample code:

$ie = new COM("InternetExplorer.Application");

$ie->Visible = true;
$ie->Height    = 500 ;
$ie->Width     = 700 ;

$post = array (ord('p'),ord('='),ord('1')) ;
$v = new VARIANT($post, VT_ARRAY|VT_UI1); 

$ie->Navigate2("http://host/web/echo_request.php",0,'',$v) ;

The code produces an error:

Fatal error: Uncaught exception 'com_exception' with message 'Variant type conversion failed: Type mismatch.type conversion failed: Type mismatch.

I have tried with all sorts of combinations for the variant type from http://fi2.php.net/manual/en/com.constants.php

Any help is greatly appreciated!

+1  A: 

(with PHP 5.3.2)
Wouldn't it be just VT_ARRAY? (or empty type)

$post = array (ord('p'),ord('='),ord('1'));
$v = new VARIANT($post, VT_ARRAY);
print variant_get_type($v);

(NOTE: so does leaving VT_ARRAY out of it i.e)

$v = new VARIANT($post);

Prints out 8024. 8024 - 8192 = 12. 12 = VT_VARIANT

Or am I missing something here?

If you want to use VT_UI1 you'll have to create the variants individually i.e

$v = new VARIANT(ord('p'), VT_UI1);

But I'm assuming you're wanting the first way.

This is from PHP source code (PHP 5.3.3) (might help, I could be way off)

/* Only perform conversion if variant not already of type passed */
if ((ZEND_NUM_ARGS() >= 2) && (vt != V_VT(&obj->v))) {

   /* If already an array and VT_ARRAY is passed then:  
       - if only VT_ARRAY passed then do not perform a conversion  
       - if VT_ARRAY plus other type passed then perform conversion  
         but will probably fail (origional behavior)
   */
Viper_Sb
Thanks for the answer. However, I still can't make it to work. This produces an error "Parameter is incorrect", which I think comes from the actual .NET function and not PHP. The code snippets I tried: `$variant = new VARIANT(array());` and `$variant = new VARIANT(array(new VARIANT(ord('p'), VT_UI1)));`. Any ideas?
rFactor
The code $variant = new VARIANT(array()); would error because array is empty, if you want an empty variant you'd just do it without the array(). $variant = new VARIANT(); Which segment is giving you the error?
Viper_Sb