ID:               34094
 Updated by:       [EMAIL PROTECTED]
 Reported By:      csaba at alum dot mit dot edu
-Status:           Open
+Status:           Feedback
 Bug Type:         Feature/Change Request
 Operating System: Windows
 PHP Version:      5CVS-2005-08-12 (dev)
 New Comment:

Can you clarify your sample script?
I've been staring at it for 5 minutes and can't figure it out.  I
understand that you're trying to call into PHP objects from the
browser, but can't tell quite what you're doing and what you expect it
should be doing instead.




Previous Comments:
------------------------------------------------------------------------

[2005-08-12 11:49:07] csaba at alum dot mit dot edu

Description:
------------
This report seems related to http://bugs.php.net/bug.php?id=33386 but
as far as I can tell a distinct phenomenon is occurring.  In this
report, there is also only external access to the last function, (but
in the VB analogue, that is OK here as opposed to there) but the access
here is through a var of the class (as opposed to the class itself or a
function of the class) and that seems wrong.

Let me summarize the VB analagous situation, the acutal situation, and
then the distinction between the report above and this one.  

1.  Summary of the VB situation: In VB, documentation says and testing
confirms that if you connect a DOM event handler directly to a class
built with VB in an .OCX, then if you have marked one of the functions
as default within the class (using Tools / Procedure Attributes /
Advanced ... note that this means one event handler per class), that is
the one that will be executed when the event occurs (note that this
differs from the ScriptControl approach in the prior report where we
expect access to all the class functions).  An example connection is
made by: IE.Document.getElementById('elemId').onclick=classInstance
Note also that there is no facility for passing an argument to the
class.


2.  Summary of actual situation:  With PHP in this report, we have to
set a variable in the DOM to the class instance (OK to here) and then
to access the class (here comes the bug:), ===> we must name a var in
the class <=== (as opposed to the class instance itself or the function
we want to access or for that matter (as in the earlier report) any
function).  At least we are able to pass arguments.


3.  Comparison with prior report:  In both reports, we are only able to
access (from an external COM object) the last function in the class, but
in the earlier report that was not expected (in comparison to VB)
whereas it is conceivable here.  In the earlier report, to access that
last function any function of the class had to be named whereas here
(and the reason for this report), a var (and not a function) of the
class needs to be named.  Frankly, I would expect that other functions
are accessible since some external agent (PHP? COM? javascript?) is
discriminating based on what has been named.


Thanks for considering this,
Csaba Gabor from Vienna


Reproduce code:
---------------
The code below (watch for possible line wrap) manages to successfully
hook a PHP class to event handlers within the IE DOM (as opposed to
event handlers of the IE COM object).  See following section for
issues.

<?
function popup ($text, $title="PHP popup",
                $timeout=4, $style=131120) {
  $oWSH = new COM("WScript.Shell");
  $oWSH->Popup($text, $timeout, $title, $style); }
function hookHandler ($wnd, $elemId, $hndlrName) {
  $wnd->ExecScript(
    "document.getElementById('$elemId')." .
       "onclick=function(){window.evtHandler." .
         "dummyVar('$hndlrName')}"); }

class evtHandler {
  function clickOK()    { popup ("OK was clicked"); }
  function clickBtn2()  { popup ("Test click"); }
  function keyPress($window) {
    if ($window->event->keyCode==27)  // ESC
      $window->doneP=true; }
  var $dummyVar;
  function __destruct() { popup ("destruction"); }
  function __construct() {
    if (func_num_args(0)) {
      popup("in event handler __construct: ");
      $argsRest = array_slice(func_get_args(),1);
      call_user_func_array (array(&$this,
                       "".func_get_arg(0)), $argsRest);
    } else popup("initialization __construct");
  }
}

$ie = new COM("InternetExplorer.Application");
$ie->visible = true;
$ie->Navigate2("about:blank");
$body ="<button id=btnOK " .
       "accesskey=O><u>O</u>K</button>&nbsp;" .
       "<button id=btn2 " .
       "accesskey=T><u>T</u>est me</button>&nbsp;" .
       "<button accesskey=c " .
       "onclick='window.doneP=true'>" .
       "<u>C</u>ancel</button>";
$ie->Document->body->innerHTML .= $body;

$window = $ie->Document->parentWindow;
$window->ExecScript ("window.doneP=false");
$window->ExecScript ("window.evtHandler=false");

$window->evtHandler = new evtHandler();
hookHandler ($window, 'btnOK', 'clickOK');
hookHandler ($window, 'btn2', 'clickBtn2');
$window->ExecScript("document.onkeypress=function(){" .
     "window.evtHandler.dummyVar('keyPress',window)}");

try { while (!$window->doneP) {
        com_message_pump(600);
        print "\n" . $ie->hwnd; }
      $ie->Quit(); }
catch (Exception $e) { popup ("IE has gone away"); }
popup("Done with php program");
?>

Expected result:
----------------
I expect to name the (non private) function within the class that I'd
like to call for a DOM event handler, and have that function be
executed.  If it turns out (because of COM restrictions et al) that an
arbitrary function can't be called, then I would expect to have to name
exactly the function that will be called and not an arbitrary variable
(dummyVar) within the class.


Actual result:
--------------
1.  I need to refer to dummyVar on lines 10, 50
2.  All calls (attempt to) go to the final function defined, even if
it's marked private (in this latter case, the call would fail)

I REALLY like being able to pass arguments to PHP event handlers (e.g.
pressing the Escape key in this example), thanks for building it in.  I
hope that is here to stay.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=34094&edit=1

Reply via email to