0

I am working on an inherited website and just switched everything to php7. I have been finding lots of errors due to this switch. One error is that the function simplexml_load_file() is not returning anything. I pass it a variable that has been set to a file path on our server (i.e. /dir/dir/dir/template.xml). But when this function gets called it doesn't return any value, neither the object we want nor a 0 to indicate it failed.

I am not experienced in php so I am having a hard time figuring out what has gone wrong. I checked the file template.xml for errors in an online checker and none were found. I checked that the file path is correct but I'm wondering if the format of /dir/dir/dir/template.xml is wrong. All of the examples of this problem I have seen deal with a url rather than a local file.

The exact line of code is:

 $xml = simplexml_load_file($TempleteXml) or die("Unable to load configuration data!");

And I have already tried breaking it down to be sure die() is not the problem.

Edit: I have found another place in the code where this problem occurs. It is another file where the same type of file is called in the exact same way.

Edit: I finally was able to get an error that tells me what is happening. The problem is: "Uncaught Error: Call to undefined function simplexml_load_file()..." So for some reason it doesn't know where to find that file even though on NetBeans I am able to see exactly where it is declared. I will look into this line of inquiry next.

Edit: So it turned out that this is a common problem. For some reason when updating to php7.0 SimpleXML is not installed (which is the extension where this function lies). I found that out here: PHP 7 simpleXML But when I do this initially "php -m" shows SimpleXML is listed as enabled, however when I restart apache2 SimpleXML then disappears. Does anyone know why a php module would disappear on restart?

Community
  • 1
  • 1
khm
  • 466
  • 2
  • 4
  • 17
  • I used that exact function today with an absolute file path on the server, under PHP 7 and it worked as expected, so that shouldn't be the issue. Check with `is_file($TemplateXml)` if you're script can find the file? – M. Eriksson Sep 14 '16 at 13:20
  • That returns 1. So it can find that file. That is a good start. – khm Sep 14 '16 at 13:30
  • Do you have error reporting and display errors on? Checked the log file for any clues? – M. Eriksson Sep 14 '16 at 13:32
  • I do have that on. I checked the error log but all the errors seem to deal with another issue in a different part of the site. – khm Sep 14 '16 at 13:58

1 Answers1

0

So I figured it out! simplexml_load_file() wouldn't load because SimpleXML wasn't installed. To install it I had to do "apt-get install php7.0-xml". I checked that it was now installed by doing "php -m". The reason it kept disappearing was that I wasn't restarting the apache2 server correctly. It only worked when I did "/etc/init.d/apache2 restart" and then "poweroff". That way when I restarted my VirtualBox machine it would still show SimpleXML as being installed.

khm
  • 466
  • 2
  • 4
  • 17