Page 1 of 2

SimpleXmlElement Issue

PostPosted: March 30th, 2013, 4:08 am
by dp22193
I am new to implementing Phalanger and I am trying to use it with WordPress. My client wants to use the Gantry framework/theme plugin and an exception is thrown when the theme is activated. The exception is a null reference exception when the code tries to perform an xpath query on the xml document. The xml document is loaded using the following constructor:

new GantrySimpleXMLElement($gantry->templatePath . '/templateDetails.xml', null, true);

GantrySimpleXMLElement extends SimpleXml. I have verified that the xml document it is trying to load exists and is valid. I am loading the following extensions:

php_xml.mng
php_domxml.mng

It seems, according to the PHP documentation, that this is implemented in PHP. Is there something that I need to do to make this work?

Thanks for your help.

Re: SimpleXmlElement Issue

PostPosted: March 30th, 2013, 9:32 am
by Jakub Misek
Hi,

Great you are trying Phalanger!

Use of php_*.dll extensions is little bit hack; these are legacy php4 extensions, and Phalanger/.NET is loading them in very unusual way.

Anyway for most of legacy php extensions there is their managed reimplementation. XML stuff is implemented in following
Code: Select all
<add assembly="PhpNetXmlDom, Version=3.0.0.0, Culture=neutral, PublicKeyToken=2771987119c16a03" section="xmldom"/>
<add assembly="PhpNetXml, Version=3.0.0.0, Culture=neutral, PublicKeyToken=2771987119c16a03" section="xml" />

Just remove use of php_xml and php_domxml and use the configuration above instead.

Thanks!

Re: SimpleXmlElement Issue

PostPosted: March 30th, 2013, 3:25 pm
by dp22193
Hi Jakub. Thanks for the quick reply. I made the changes you suggested but I'm still getting a null reference exception. I created a test page that instantiates a SimpleXMLElement using a file path and I get the same exception. The stack trace is included below.

I downloaded the latest source code and included the Extension.XmlDom project in my solution (I commented out the add assembly line in my web.config) but my breakpoints don't get hit. Mousing over the breakpoint indicates that no symbols are loaded. Is there a way to get this to work?

On a side note, I am able to set breakpoints in php code and step through php code which is great but I cannot view variable values. When I try to print them in the immediate window, I get a variable not found in context error. I read through the Wiki and it looks like I need XDEBUG but I'm not sure how to install this in my environment. I do not have PHP installed and XDEBUG seems to need that. Is there a way to install XDEBUG with installing PHP?

Thanks again for your help.

Stack Trace:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 1: <?
Line 2: $xml = new SimpleXMLElement('C:\Projects\Polestar\OrangeHat\JunkKing\wpblog\xmltest\templateDetails.xml', null, true);
Line 3: $xml_positions = $xml->xpath('//positions/position');
Line 4: print_r($xml_positions);
Line 5: ?>

Source File: C:\Projects\Polestar\OrangeHat\JunkKing\wpblog\xmltest\test.php Line: 3

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
PHP.Library.Xml.SimpleXMLElement.xpath(String path) +69
PHP.Library.Xml.SimpleXMLElement.xpath(ScriptContext __context, Object path) +54
xpath_(SimpleXMLElement , ScriptContext , Object ) +44
CallSite.Target(Closure , CallSite , Object , ScriptContext , Object , DTypeDesc ) +320
System.Dynamic.UpdateDelegates.UpdateAndExecute4(CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3) +738
<xmltest/test.php>.<Script>.<Main>(ScriptContext <context>, Dictionary`2 <locals>, DObject <self>, DTypeDesc <includer>, Boolean <request>) in C:\Projects\Polestar\OrangeHat\JunkKing\wpblog\xmltest\test.php:3
PHP.Core.ScriptInfo.<get_Main>b__0(ScriptContext context, Dictionary`2 variables, DObject self, DTypeDesc includer, Boolean isMain) +54
PHP.Core.ScriptContext.<IncludeScript>b__1(ScriptInfo scriptInfo) +56
PHP.Core.ScriptContext.GuardedCall(Converter`2 routine, TData data, Boolean allowUserExceptions) +58

[PhpNetInternalException: Guarded call
InnerException: Object reference not set to an instance of an object.
at at PHP.Library.Xml.SimpleXMLElement.xpath(String path)
at PHP.Library.Xml.SimpleXMLElement.xpath(ScriptContext __context, Object path)
at xpath_(SimpleXMLElement , ScriptContext , Object )
at CallSite.Target(Closure , CallSite , Object , ScriptContext , Object , DTypeDesc )
at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at <xmltest/test.php>.<Script>.<Main>(ScriptContext <context>, Dictionary`2 <locals>, DObject <self>, DTypeDesc <includer>, Boolean <request>) in C:\Projects\Polestar\OrangeHat\JunkKing\wpblog\xmltest\test.php:line 3
at PHP.Core.ScriptInfo.<get_Main>b__0(ScriptContext context, Dictionary`2 variables, DObject self, DTypeDesc includer, Boolean isMain)
at PHP.Core.ScriptContext.<IncludeScript>b__1(ScriptInfo scriptInfo)
at PHP.Core.ScriptContext.GuardedCall[TData,TResult](Converter`2 routine, TData data, Boolean allowUserExceptions)
]
PHP.Core.ScriptContext.GuardedCall(Converter`2 routine, TData data, Boolean allowUserExceptions) +356
PHP.Core.ScriptContext.IncludeScript(String relativeSourcePath, ScriptInfo script) +192
PHP.Core.RequestContext.IncludeScript(String relativeSourcePath, ScriptInfo script) +24
PHP.Core.RequestHandler.ProcessRequest(HttpContext context) +249
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69



--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18034

Re: SimpleXmlElement Issue

PostPosted: March 30th, 2013, 5:02 pm
by Jakub Misek
That would be a bug in SimpleXmlElement. Do you have a sample code+xml file which can be used to replicate the issue?

Thanks,

Re: SimpleXmlElement Issue

PostPosted: March 30th, 2013, 8:22 pm
by dp22193
Yes. I have attached a zip containing my test page and xml document. Let me know if you have any questions.

Thanks.

Re: SimpleXmlElement Issue

PostPosted: March 31st, 2013, 10:32 am
by Jakub Misek
Thanks!

The second parameter of
Code: Select all
new SimpleXMLElement('templateDetails.xml', 0, true)
must be integer, not NULL. Because of this, a warning is raised; and __constructor does not proceed. SimpleXMLElement is not initialized then, and xpath crashes.

Re: SimpleXmlElement Issue

PostPosted: March 31st, 2013, 2:52 pm
by dp22193
Thanks Jakub! That solved my problem!

After getting an unrelated error when testing the site, I decided to precompile to see if there were any other issues. There were a few other issues that I corrected but I think three of the errors reported might be a compiler issue.

The following line of code reports error PHP1001: Only variables can be passed by reference:

$result-> $tmp = GantryJSON::_decode($encode, ++$pos, $slen, $class);

If I change the code to increment $pos outside of the method call, the compiler reports no error. Shouldn't incrementing a variable using the ++ operator be valid in a method call?

Also, did you have any guidance on:
forcing my project to load my version of one of the managed extension?
getting XDEBUG to work without installing PHP?

Thanks again!

Re: SimpleXmlElement Issue

PostPosted: March 31st, 2013, 3:18 pm
by Jakub Misek
Hi,

I guess GantryJSON::_decode() takes a reference as the second argument, not a value, and ++$pos cannot be passed as a ref.

If you installed Phalanger using setup, you have release extensions installed in GAC, and .NET loads assemblies from GAC in prior. If you compile your version of managed extension, it is installed into GAC automatically in post build process. So everything should work as expected. Otherwise you can specify path to the extension instead of its full assembly name (<add url='bin/myass.dll' /> instead of <add assembly='...' />).

Also you may need to restart IIS (just your application pool), because once it loads assembly from GAC, any changes won't take effect.

Thanks,

Re: SimpleXmlElement Issue

PostPosted: March 31st, 2013, 3:37 pm
by Jakub Misek
Ad to previous post, XDebug is PHP extension, it can't be used with .NET/Phalanger.

Thanks,

Re: SimpleXmlElement Issue

PostPosted: April 1st, 2013, 2:03 pm
by dp22193
Thanks for all the info Jakub! I just want to get clarification on XDEBUG.

I have the PHP tools for VS installed and the overview for this states that you can inspect variables and add watches in PHP. Installation documentation seems to indicate that this feature requires XDEBUG which seems to be dependent on an actual PHP installation. Unless I install PHP on my machine, I won't be able to inspect variables at breakpoints. Is this understanding correct?

Thanks.