PHP?

Posted by Poromenos on Fri 26 Nov 2004 05:16 AM — 3 posts, 18,334 views.

Greece #0
Is it easy to implement PHP support for MC?
From PHP's install.txt:
Quote:

ActiveScript is a windows only SAPI that enables you to use PHP script
in any ActiveScript compliant host, like Windows Script Host,
ASP/ASP.NET, Windows Script Components or Microsoft Scriptlet control.

As of PHP 5.0.1, ActiveScript has been moved to the PECL repository.
You may download this PECL extensions DLL from the PHP Downloads page
or at http://snaps.php.net/.

After installing PHP, you should download the ActiveScript DLL
(php5activescript.dll) and place it in the main PHP folder (e.g.
C:\php).


I hope this makes it as easy as a few code changes.
Australia Forum Administrator #1
Well, I've tried. I downloaded PHP and the activescript dll as you suggested. A few changes to MUSHclient to recognise PHP as a script engine, register the DLL and we are away, sort of.

The problem is:

a) I don't seem to be able to test without raising syntax errors in PHP; and

b) As soon as I get an error, I see the usual script error dialog box, but when I close that MUSHclient silently terminates (ie. with no error message, however without offering to save changed documents etc.)

I tried testing with:


/world.Note "Hi"


This usually works, however first I see this in the error dialog:


syntax error, unexpected T_CONSTANT_ENCAPSED_STRING


Then this is what I get in the debug window:


T=0000015e 01dcc6d0: GetScriptState(current=SCRIPTSTATE_CONNECTED)
T=0000015e ParseScriptText
T=0000015e pstrCode=001423E4 pstrItemName=00000000 
punkContext=00000000 pstrDelimiter=00000000 pvarResult=00000000 pexcepinfo=0012F990
T=0000015e [MARSHAL]  prepping for function code 0 ParseScriptText, 9 args, marshal defs at 01EDA01C
T=0000015e [MARSHAL] marshalling ... 
T=0000015e [MARSHAL]    arg=2 IUnknown(NULL) - skip
T=0000015e [MARSHAL]  -- skipping (this param is not needed in this direction)
T=00000141 [MARSHAL]  unmarshalling...
T=00000141 [MARSHAL]    unmarshal arg=2 IUnknown(NULL) - skip
T=00000141 ParseScriptText
T=00000141 pstrCode=001423E4 pstrItemName=00000000 punkContext=00000000 pstrDelimiter=00000000 
pvarResult=00000000 pexcepinfo=0012F990
T=00000141 01dcc6d0: ParseScriptText:
 state=SCRIPTSTATE_CONNECTED
code=world.Note "Hi"
 item=<NULL>
 delim=<NULL>
 line=0
T=00000141 0014ee58: COMPILED FRAG
T=00000141 code to compile is:
code_offs=0  func=(null)
world.Note "Hi"
T=00000141 01dcc6d0: PHP Error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING
T=00000141 raising error object!
T=00000141 Calling [marshall] m_pass->OnScriptError
T=00000141 Release: errobj refcount=1
CActiveScriptSite: OnScriptError
T=00000141 Release: errobj refcount=2
T=00000141 Release: errobj refcount=1
T=00000141 Release: errobj refcount=0
T=00000141 024f3b40: cleaning up error object
T=00000141 --- done calling m_pass->OnScriptError
The thread 0x15E has exited with code -1 (0xFFFFFFFF).
The thread 0x122 has exited with code -1 (0xFFFFFFFF).
The thread 0x125 has exited with code -1 (0xFFFFFFFF).
The thread 0x13C has exited with code -1 (0xFFFFFFFF).
The thread 0x153 has exited with code -1 (0xFFFFFFFF).
The thread 0x147 has exited with code -1 (0xFFFFFFFF).
The thread 0x167 has exited with code -1 (0xFFFFFFFF).
The thread 0x141 has exited with code -1 (0xFFFFFFFF).
The program 'G:\source\mushclient\WinDebug\MUSHclient.exe' has exited with code -1 (0xFFFFFFFF).


The final line is the important one, MUSHclient.exe has exited.

Now if I try slightly different syntax:


/world.Note ("hi");


I get these errors:


Use of undefined constant world - assumed 'world'
Call to undefined function Note()


However, MUSHclient does not exit and continues normally.

So I have two major problems - the first is that, although I am familiar with PHP, I don't seem to be able to get it to recognise the "world" object (using $world doesn't help much either).

The second is, that for certain sorts of errors the MUSHclient session goes away.

It seems that for parsing (syntax) errors like "syntax error, unexpected T_CONSTANT_ENCAPSED_STRING", it decides to terminate the application altogether, however for semantic errors (doesn't recognise the word "world") it doesn't. Sounds like a bug in the script engine to me.
Amended on Fri 26 Nov 2004 08:09 PM by Nick Gammon
United Kingdom #2
Just thought I'd let everyone know, I've just got prefix-style php scripting working.

Example:
/$world->tell("Test!\n");

For me it was a case of:
Copying the php5activescript.dll from http://snaps.php.net/ to the mush install directory.

Getting a very strage error about entry points when trying to register the dll.

Realising that I was running a version of php 1 minor out of date (5.0.2 instead of 5.0.3).

Installing that..

Searching around for all outdates copies of php5ts.dll (windir, windir\system, windir\system32, apache\bin.. etc.), delteing them, and replacing them with the new version.

And now, the register dll button worked! Hurray!

The I just had to hang MUSH a few times while trying to guess the syntax.


Just a note, taken (although I can't find the page again, so roughly remembered) from a FAQ somewhere:

. (periods) are not valid characters in variable names.
. (period) is the string concatenation operator.
Any unrecognised token becomes a string.

ie:

return a.b("sample argument");
-> return 'a'.'b'("sample argument");
-> return 'ab'("sample argument");
(not valid (arrays are [] delimited in php))

ie#2:

(assuming $a isn't null (=="somethingsomething")).

return $a.b("sample argument");
-> $a.='b'; return $a("sample argument");
~> return 'somethingsomethingb'("sample argument");


Hope this helps anyone else wanting to play, and I'll have a look at the actual script file soon.

Faux.