php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56694 GetIDsOfNames returns DISPID of zero
Submitted: 2005-12-04 02:46 UTC Modified: 2006-02-27 07:36 UTC
From: nick at gammon dot com dot au Assigned:
Status: No Feedback Package: PHPScript (PECL)
PHP Version: 5_1 CVS-2005-12-04 OS: Windows NT
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2005-12-04 02:46 UTC] nick at gammon dot com dot au
Description:
------------
Package: pecl-5.1.1-Win32.zip

I am a developer of a MUD client program which supports various script language (VBscript, Jscript, Perlscript etc.) and have been trying to get PHPscript to work with it.

All is working fine now, except for one thing. When I call GetIDsOfNames to retrieve a DISPID for a function declared inside the script which has been parsed, the DISPID of the first function requested is zero.

Your relevant code is this:

char *m_names[1024];
int m_lens[1024];
int m_ids;  // initially zero

Every time GetIDsOfNames is called it calls create_id which (if the ID has not already been created) adds the function name to the table, and returns the index of the table, thus the first returned index is zero.

Now my problem is that I was using a DISPID of zero as a flag for "no such routine" - a technique that has worked for every other script engine so far. The question is, is it valid to return a DISPID of zero?

According to the Windows include file OAIDL.H:

/* DISPID reserved for the "value" property */
#define	DISPID_VALUE	( 0 )

Thus, the first DISPID returned by GetIDsOfNames is really DISPID_VALUE, a special "reserved" value.

According to the help for DISPID, DISPID_VALUE is :

"The default member for the object. This property or method is invoked when an ActiveX client specifies the object name without a property or method."

Other help topics for DISPID_VALUE state:

* An object is coerced to a value by invoking the object's Value property (DISPID_VALUE).

* The Value property defines the default behavior of an object when no property or method is specified. It is typically used for the property that users associate most closely with the object. 

-----

To be honest, I don't think that "the first function I happened to want the DISPID for" qualifies for this special treatment. I suggest starting the returned DISPIDs at 1, not 0.

As a work-around, I am now using DISPID_UNKNOWN (-1) as my "no such function" flag, however I think it would be cleaner, and possibly save other script users problems in the future, to fix it.

Thanks for your time. :)

Reproduce code:
---------------
Not relevant.

Expected result:
----------------
The first DISPID returned to be 1, not 0.

You could simply do this by changing one line in TPHPScriptingEngine::TPHPScriptingEngine() from:

	m_ids = 0;

to
	m_ids = 1;

Effectively this will waste one entry in both arrays (8 bytes). There would be more complicated fixes, but the extra code involved would almost certainly involve more than 8 bytes of code.

Actual result:
--------------
See above.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-04 10:50 UTC] wez@php.net
I patched this in CVS; keep your eye on:
http://pecl4win.php.net/ext.php/php5activescript.dll
the next build dated after you get this message should have the fix.
 [2006-02-27 07:36 UTC] mike@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed May 22 02:01:26 2019 UTC