在PHP中使用变体构建字节数组? [英] Building a byte array in PHP with variants?

查看:116
本文介绍了在PHP中使用变体构建字节数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Variants 在PHP中构建字节数组>。但是,我似乎无法使其正常运行。以下是示例代码:

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) ;

代码产生错误:


致命错误:未捕获的异常
'com_exception',消息为'Variant
类型转换失败:类型不匹配。类型转换失败:类型不匹配。

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

我尝试了来自 http:/的各种类型的组合/fi2.php.net/manual/zh-cn/com.constants.php

任何帮助都将不胜感激!

Any help is greatly appreciated!

推荐答案

(使用PHP 5.3.2)

不仅是VT_ARRAY吗? (或空类型)

(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);

(注意:将VT_ARRAY排除在外也是如此)

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

$v = new VARIANT($post);

打印出8024。8024-8192 =12。12 = VT_VARIANT

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

还是我在这里缺少什么?

Or am I missing something here?

如果要使用VT_UI1,则必须分别创建变体,即

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.

这是来自PHP源代码(PHP 5.3.3)(可能有帮助,我可能相距较远)

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


/ *仅在尚未传递类型的变体时执行转换* /

if((ZEND_NUM_ARGS()> = 2)&&(vt!= V_VT(& obj-> v)) ){

/* 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)
   */


这篇关于在PHP中使用变体构建字节数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆