Passing arrays from c# to phalanger dll

Discussion about the open-source Phalanger [?] project.

Passing arrays from c# to phalanger dll

Postby strfrank » June 20th, 2012, 9:16 am

Hi,
I'm working on a pure php dll that I need to call from c# apps.
The php code is an actual library and I cannot modify it, it has many functions that require array arguments.
Actually I use the PhpArray class to pass these arrays correctly from c# to the dll functions and it works perfectly, I was wondering if there is some method to automatically convert c# arrays or collections to php arrays to shorten the code.

Many thanks
strfrank
 
Posts: 20
Joined: May 30th, 2012, 5:05 pm

Re: Passing arrays from c# to phalanger dll

Postby Jakub Misek » June 20th, 2012, 12:12 pm

Hi,
I agree PhpArray is not always easy to create, as it has many additional array features.

For you the easiest ways would be to wrap System.Array or ICollection into PhpArray:
Code: Select all
new PhpArray(collection)


You can make an extension method to ICollection or IDictionary, that would create PhpArray from it:
Code: Select all
public static PhpArray ToPhpArray(this IDictionary dict){ ... }


Or write an explicit cast operator.

Also in most cases (tested for [] operator), Phalanger handles objects derived from IList and IDictionary directly, so you don't have to create PhpArray at all.
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2092
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: Passing arrays from c# to phalanger dll

Postby strfrank » June 21st, 2012, 9:29 am

Hi,
Thanks for the answer, I'll rely on phparray, maybe I can write an adapter that accepts standard collections and converts them to PhpArray.

The problem with passing .net collections or arrays is that when the php code tries to add elements to the collections I get an exception.

Thanks
strfrank
 
Posts: 20
Joined: May 30th, 2012, 5:05 pm


Return to Phalanger project

Who is online

Users browsing this forum: No registered users and 39 guests

cron

User Control Panel

Login

Who is online

In total there are 39 users online :: 0 registered, 0 hidden and 39 guests (based on users active over the past 5 minutes)
Most users ever online was 431 on April 25th, 2024, 1:28 am

Users browsing this forum: No registered users and 39 guests