In the code of the online store there is a fragment:

if (!file_exists($xml_file) || !$xml = @simplexml_load_file($xml_file)) { $this->errors[] = "cannot load"; return false; } if (!$xml['version'] || !$xml['name']) { $this->errors[] = "version and name required"; return false; } 

Example of XML being processed:

 <?xml version="1.0" encoding="UTF-8" ?> <theme> <version value="1.4"> <ccc available="true" /> <guest_checkout available="true" /> <one_page_checkout available="true" /> <store_locator available="true" /> </version> <name value="Sound Theme" /> </theme> 

The problem is that the condition (!$xml['version'] || !$xml['name']) returns false, despite the fact that there are version and name elements in xml. I tried to contact them in the style of $xml->{'version'} - everything works. It can not be that in such a large product incorrectly written code to work with XML. Maybe access to elements through the syntax [] works with a certain version of PHP? I have version 5.3.13. I ask you to suggest what the problem may be and how to fix it without changing the source code of the online store.

  • $xml['version'] is working with an array, and your $xml is an object . Do you understand the difference between them? - u_mulder
  • This is a code from a large project ( github.com/PrestaShop/themeinstallator/blob/master/… line 386). I think the authors of the project know the difference between the array and the object, besides everything works for other people, otherwise the code would be fixed. - DarkGenius

2 answers 2

To begin with, the syntax $xml['version'] means that the value of the attribute is taken from the $xml object. In your $xml

 <theme> <version value="1.4"> <ccc available="true" /> <guest_checkout available="true" /> <one_page_checkout available="true" /> <store_locator available="true" /> </version> <name value="Sound Theme" /> </theme> 

The theme root element does not have these attributes. Because it does not pass the test

 !$xml['version'] || !$xml['name'] 

In order to understand, I downloaded a free template for prestashop (I don’t know why at all). And in it I saw something like the following:

 <theme version="1.0" name="dixio" directory="dixio"> <author name="Presta Theme Maker" email="presta.theme.maker@gmail.com" url="http://presta-theme-maker.com/"/> 

See you Here, the theme tag has both verifiable attributes.

Thus, the output - the xml file you provided has an unsupported import / export script format.

  • Thank you for your help. Apparently I came across curved patterns that confused me. - DarkGenius

Try it like this. I hope that helped

 $xml->version[0]['value']; 
  • Thank you, but I do not need to edit the project code. I need to understand why he does not work for me. - DarkGenius