Overriding php methods in c# (pure dll)

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

Overriding php methods in c# (pure dll)

Postby strfrank » May 31st, 2012, 9:07 am

Hi,
I have a php pure dll that declares a class like this:

Code: Select all
class Test
{
    public function TestMehod()
    {
    }
}


Now I need to create a subclass of this in c# and override that method, so I did:

Code: Select all
public class TestSharp : Test
{
    public override object TestMethod()
    {
        return null;
    }
}


when TestMethod is called from the php side I get this exception:

Unable to cast object of type 'PHP.Core.Reflection.ClrMethod' to type 'PHP.Core.Reflection.PhpRoutine'

I tried some of the attributes on the PHP.Core namespace with no luck, many thanks for the help.
strfrank
 
Posts: 20
Joined: May 30th, 2012, 5:05 pm

Re: Overriding php methods in c# (pure dll)

Postby strfrank » June 8th, 2012, 8:24 am

Hi,
I investigated better, the problem lies when I call the overriden method from another method in php, for example I have this php class:

Code: Select all
[\Export]
class Test
{
   function __construct()
   {
   }

    public function TestMethod()
    {
        return 5;
    }

    public function CallTestMethod()
    {
        $aa = $this->TestMethod();
        $aa = $aa + 2;
        return $aa;
    }
}


and I override the TestMethod() method in c# like this:

Code: Select all
class TestOverrideSharpClass : Test
{
    public override object TestMethod()
    {
        return 7;
    }
}


Then I use the TestOverrideSharpClass class inside a c# application like this:

Code: Select all
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        string s;
        TestOverrideSharpClass c;

        c = new TestOverrideSharpClass();
        s = c.CallTestMethod().ToString();
        MessageBox.Show(s);
    }
}


When I execute the application I get an exception on the line:

Code: Select all
 $aa = $this->TestMethod();


the error message is:

Unable to cast object of type 'PHP.Core.Reflection.ClrMethod' to type 'PHP.Core.Reflection.PhpRoutine'.

Many thanks for any help, I'm a bit stuck in this project...
Frank
strfrank
 
Posts: 20
Joined: May 30th, 2012, 5:05 pm

Re: Overriding php methods in c# (pure dll)

Postby Jakub Misek » June 8th, 2012, 12:07 pm

Hi,
thank you for the test case. I'll take a look, and hopefully submit a fix.
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: Overriding php methods in c# (pure dll)

Postby Jakub Misek » June 8th, 2012, 12:45 pm

I've fixed calling of CLR overriden method, feel free to try it again. Current sources are at github (https://github.com/DEVSENSE/Phalanger). Installer at CodePlex will be updated within a month.
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: Overriding php methods in c# (pure dll)

Postby strfrank » June 8th, 2012, 1:45 pm

It works perfectly now, 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 32 guests

cron

User Control Panel

Login

Who is online

In total there are 32 users online :: 0 registered, 0 hidden and 32 guests (based on users active over the past 5 minutes)
Most users ever online was 341 on April 19th, 2024, 6:45 pm

Users browsing this forum: No registered users and 32 guests