getting response string/object from php classes
14 posts
• Page 1 of 2 • 1, 2
getting response string/object from php classes
There are 2 main ways to get data out from your php classes shown in the downloaded example http://www.php-compiler.net/blog/2012/net-interoperability-overview-of-phalanger-3-0. To call the variable directly or creating a callback. I have tried both methods but neither work for me.
directly accessing variable:
gives error:
Object reference not set to an instance of an object.
And when I use the call back method I get the same error.
Why is this not working?
Why cant you just do
Could this tie into the other post http://support.devsense.com/viewtopic.php?f=3&t=840
Because Im having to do that
Take note that calling functions and using the php classes works fine. I just cannot read the results returned by the methods Im calling.
directly accessing variable:
- Code: Select all
public function hi()
{
$string = "Hi";
$this->hi = $string;
}
- Code: Select all
protected void hi_Clicked(object sender, EventArgs e)
{
phpObj.hi();
output.WriteLine("{0}<br/>", phpObj.hi);
}
gives error:
Object reference not set to an instance of an object.
And when I use the call back method I get the same error.
Why is this not working?
Why cant you just do
- Code: Select all
output.WriteLine("{0}<br/>", phpObj.Sum(x, y);)
Could this tie into the other post http://support.devsense.com/viewtopic.php?f=3&t=840
Because Im having to do that
- Code: Select all
using
Take note that calling functions and using the php classes works fine. I just cannot read the results returned by the methods Im calling.
- owengerig
- Posts: 10
- Joined: October 16th, 2012, 2:50 pm
Re: getting response string/object from php classes
Both should work. How do you initialize 'phpObj' ?
Thanks
Thanks
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
Re: getting response string/object from php classes
- Code: Select all
if (IsPostBack)
{
phpObj = (dynamic)HttpContext.Current.Session["phpObj"];
}
else
{
using (var request_context = RequestContext.Initialize(ApplicationContext.Default, HttpContext.Current))
{
context = request_context.ScriptContext;
context.Include("Client.php", false);
context.Include("Crypt.php", false);
context.Include("Exception.php", false);
// now the declarations declared by default.php are available in context.
// do anything with PHP objects here
//part 1
//Gets PHP output stream
output = ScriptContext.CurrentContext.Output;
//Gets GlobalScope object
global = ScriptContext.CurrentContext.Globals;
phpObj = global.@class.Fuze_Client("https://partnerdev.fuzemeeting.com/", "83666136", "Q5iI4bcoADj9QGrMC6Ss5V34VK1FxKNZ");
}
HttpContext.Current.Session["phpObj"] = phpObj;
}
- owengerig
- Posts: 10
- Joined: October 16th, 2012, 2:50 pm
Re: getting response string/object from php classes
I guess phpObj != null.
If you'll try to get a property or call a method right after phpObj = ..., does it work? If it throws, could you please attach whole StackTrace?
Thanks.
If you'll try to get a property or call a method right after phpObj = ..., does it work? If it throws, could you please attach whole StackTrace?
Thanks.
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
Re: getting response string/object from php classes
it does work if I place it right after the setting the phpObj
But that doesnt make sense to me. Because lets say I change the hi method to include an echo
then do phpObj.hi()
it will show the echo string on the screen but then give me the error returned above. So how can that be?
So this would show the "Hi from echo"
but if I uncomment the next line I get my error
But that doesnt make sense to me. Because lets say I change the hi method to include an echo
- Code: Select all
public function hi()
{
$string = "Hi";
echo $string." from echo";
$this->hi = $string." from string";
return $this->hi ;
}
then do phpObj.hi()
it will show the echo string on the screen but then give me the error returned above. So how can that be?
- Code: Select all
protected void hi_Clicked(object sender, EventArgs e)
{
phpObj.hi();
//output.WriteLine("write line1: {0}<br/>", phpObj.hi);
}
So this would show the "Hi from echo"
but if I uncomment the next line I get my error
- owengerig
- Posts: 10
- Joined: October 16th, 2012, 2:50 pm
Re: getting response string/object from php classes
output != null // ?
dynamic hi = phpObj.hi; // does this work?
string hiStr = phpObj.hi.ToString(); // and this ?
I can guess more with StackTrace provided by the Exception message.
dynamic hi = phpObj.hi; // does this work?
string hiStr = phpObj.hi.ToString(); // and this ?
I can guess more with StackTrace provided by the Exception message.
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
Re: getting response string/object from php classes
- Code: Select all
dynamic hi = phpObj.hi;
string hiStr = phpObj.hi.ToString();
output.WriteLine("write line: {0}", hiStr);
Not sure what I should try to do with the dynamic object hi. However the code below that yields
Cannot perform runtime binding on a null reference
for the code:
- Code: Select all
output.WriteLine("write line2: {0}<br/>", phpObj.hi());
the stack trace is:
at CallSite.Target(Closure , CallSite , TextWriter , String , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid3[T0,T1,T2](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at HeloWorld.Default.hi_Clicked(Object sender, EventArgs e) in c:\Users\dever\Desktop\web code\HeloWorld\HeloWorld\Default.aspx.cs:line 147
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
- owengerig
- Posts: 10
- Joined: October 16th, 2012, 2:50 pm
Re: getting response string/object from php classes
It seams like 'hi' property is null. By checking 'dynamic hi = phpObj.hi;' value, I would see where the cause of your issue is.
Thanks
Thanks
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
Re: getting response string/object from php classes
- Code: Select all
public function hi()
{
$string = "Hi";
//echo $string." from echo";
$this->hi = $string." from string";
return $this->hi ;
//$this->CallMeBack($string);
}
since this i have added
- Code: Select all
public $hi = "init";
and now
phpObj->hi = "hi from string"
and
hiStr = "init"
But I still get the same error (Object reference not set to an instance of an object.) and stack trace as above, with this line:
- Code: Select all
output.WriteLine("write line: {0}", hiStr);
- Code: Select all
output.WriteLine("write line: {0}", phpObj.hi);
- Code: Select all
output.WriteLine("write line: {0}", phpObj.hi());
- owengerig
- Posts: 10
- Joined: October 16th, 2012, 2:50 pm
Re: getting response string/object from php classes
- Code: Select all
output.WriteLine("write line: {0}", hiStr);
Can I ask for small test case project? I see 'hi' and 'hiStr' are both null?
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
14 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 17 guests