ID: 31040
User updated by: jeanpierre dot vincent at gmail dot com
Reported By: jeanpierre dot vincent at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: COM related
Operating System: W2K WinXP
PHP Version: 5.0.2
New Comment:
this bug exists for all objects events sink.
Problem is in the function disp_invokeex() in file com_wrapper.c
the var zarg declared in the for loop to catch parameters is overwriten
every time, so all parameters have the value of the last one.
The reason why it happened on some functions and not another depends of
the compilation. We had here a random bug !!
the solution is to replace this code (in disp_invokeex() in file
com_wrapper.c)
///////////////////////////bugged code/////////////////////
params = (zval ***)safe_emalloc(sizeof(zval **), pdp->cArgs, 0);
for (i = 0; i < pdp->cArgs; i++) {
VARIANT *arg;
zval *zarg;
arg = &pdp->rgvarg[ pdp->cArgs - 1 - i];
trace("alloc zval for arg %d VT=%08x\n", i,
V_VT(arg));
ALLOC_INIT_ZVAL(zarg[i]);
php_com_wrap_variant(zarg, arg, COMG(code_page)
TSRMLS_CC);
params[i] = &zarg;
}
///////////////////////////////////////////////////////
by this one :
////////////////////correct code/////////////////////
params = (zval ***)safe_emalloc(sizeof(zval **), pdp->cArgs, 0);
for (i = 0; i < pdp->cArgs; i++) {
VARIANT *arg;
zval **zarg= NULL;
zarg=(zval **)safe_emalloc(sizeof(zval *),
pdp->cArgs, 0);
arg = &pdp->rgvarg[ pdp->cArgs - 1 - i];
trace("alloc zval for arg %d VT=%08x\n", i,
V_VT(arg));
ALLOC_INIT_ZVAL(zarg[i]);
php_com_wrap_variant(zarg[i], arg,
COMG(code_page) TSRMLS_CC);
params[i] = &zarg[i];
}
/////////////////////////////////////////////////////////
Hope you'll correct for the next version !
Previous Comments:
------------------------------------------------------------------------
[2004-12-09 18:24:39] jeanpierre dot vincent at gmail dot com
Description:
------------
For some events of the IE browser, parameters given take value 0 and
are of boolean type.
For example : BeforeNavigate2, BeforeNavigate and CommandStateChange,
whereas events like DocumentComplete work fine.
Here is the example code from http://www.php.net/com-event-sink, which
I simply added BeforeNavigate2. Launch it from a browser or CLI.
Reproduce code:
---------------
class IEEventSinker {
var $terminated = false;
// just after Browser understands he has to navigate
function BeforeNavigate2(&$pDisp, &$url, &$Flags, &$TargetFrameName,
&$PostData, &$Headers, &$Cancel) {
foreach(func_get_args() as $id => $valeur) {
// if the problem occurs ...
if($valeur == 0)
print $id.' = '.$valeur.' of type
'.variant_get_type($valeur)."\n";
}
// if the problem doesnt, $url is filled
if($url != 0)
echo "you'll navigate on $url\n";
}
// when all objects of page are loaded
function DocumentComplete(&$dom, $url) {
echo "Document $url complete\n";
}
// when closing browser
function OnQuit() {
echo "Quit!\n";
$this->terminated = true;
}
}
$ie = new COM("InternetExplorer.Application");
// note that you don't need the & for PHP 5!
$sink = new IEEventSinker();
com_event_sink($ie, $sink, "DWebBrowserEvents2");
$ie->Visible = true;
$ie->Navigate("http://www.php.net");
while(!$sink->terminated) {
com_message_pump(4000);
}
$ie = null;
Expected result:
----------------
you'll navigate on http://www.php.net/
Document http://www.php.net/ complete
Quit!
Actual result:
--------------
0 = 0 of type 11
1 = 0 of type 11
2 = 0 of type 11
3 = 0 of type 11
4 = 0 of type 11
5 = 0 of type 11
6 = 0 of type 11
Document http://www.php.net/ complete
Quit!
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=31040&edit=1