Overriding php methods in c# (pure dll)
5 posts
• Page 1 of 1
Overriding php methods in c# (pure dll)
Hi,
I have a php pure dll that declares a class like this:
Now I need to create a subclass of this in c# and override that method, so I did:
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.
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)
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:
and I override the TestMethod() method in c# like this:
Then I use the TestOverrideSharpClass class inside a c# application like this:
When I execute the application I get an exception on the line:
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
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)
Hi,
thank you for the test case. I'll take a look, and hopefully submit a fix.
thank you for the test case. I'll take a look, and hopefully submit a fix.
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
Re: Overriding php methods in c# (pure dll)
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. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
Re: Overriding php methods in c# (pure dll)
It works perfectly now, thanks!
- strfrank
- Posts: 20
- Joined: May 30th, 2012, 5:05 pm
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 40 guests