SimpleXmlElement Issue

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

SimpleXmlElement Issue

Postby dp22193 » March 30th, 2013, 4:08 am

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.
dp22193
 
Posts: 7
Joined: March 26th, 2013, 5:02 pm

Re: SimpleXmlElement Issue

Postby Jakub Misek » March 30th, 2013, 9:32 am

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!
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: SimpleXmlElement Issue

Postby dp22193 » March 30th, 2013, 3:25 pm

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
dp22193
 
Posts: 7
Joined: March 26th, 2013, 5:02 pm

Re: SimpleXmlElement Issue

Postby Jakub Misek » March 30th, 2013, 5:02 pm

That would be a bug in SimpleXmlElement. Do you have a sample code+xml file which can be used to replicate the issue?

Thanks,
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: SimpleXmlElement Issue

Postby dp22193 » March 30th, 2013, 8:22 pm

Yes. I have attached a zip containing my test page and xml document. Let me know if you have any questions.

Thanks.
You do not have the required permissions to view the files attached to this post.
dp22193
 
Posts: 7
Joined: March 26th, 2013, 5:02 pm

Re: SimpleXmlElement Issue

Postby Jakub Misek » March 31st, 2013, 10:32 am

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.
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: SimpleXmlElement Issue

Postby dp22193 » March 31st, 2013, 2:52 pm

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!
dp22193
 
Posts: 7
Joined: March 26th, 2013, 5:02 pm

Re: SimpleXmlElement Issue

Postby Jakub Misek » March 31st, 2013, 3:18 pm

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,
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: SimpleXmlElement Issue

Postby Jakub Misek » March 31st, 2013, 3:37 pm

Ad to previous post, XDebug is PHP extension, it can't be used with .NET/Phalanger.

Thanks,
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: SimpleXmlElement Issue

Postby dp22193 » April 1st, 2013, 2:03 pm

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.
dp22193
 
Posts: 7
Joined: March 26th, 2013, 5:02 pm

Next

Return to Phalanger project

Who is online

Users browsing this forum: No registered users and 8 guests

cron

User Control Panel

Login

Who is online

In total there are 8 users online :: 0 registered, 0 hidden and 8 guests (based on users active over the past 5 minutes)
Most users ever online was 151 on December 6th, 2020, 7:46 am

Users browsing this forum: No registered users and 8 guests