1

I know there are a lot of answers out there for this exact question, but none of them seem to help me solve my problem.

I have an xml file on my server, i need to use PHP SimpleXML to remove an element from the document. After some googling i found a number of answers saying to use unset() and then save the xml.

so i came up with this:

function deleteCourse($course){
    $xml = self::getxml(); # get the XML file
    unset($xml->xpath('course[name = "'.$course.'"]'));
    $xml->asXml("data.xml");
}

now whenever i run this i get this error: PHP Fatal error: Can't use method return value in write context in blahblahLink on line 92

line 92 is unset($xml->xpath('course[name = "'.$course.'"]'));

I really hope somebody can help me out with this

Jamie McAllister
  • 729
  • 2
  • 11
  • 33

1 Answers1

1

unset won't work if you pass method return, pass variable content / array instead

Ayyanar G
  • 1,545
  • 1
  • 11
  • 24
  • Show what he should write instead. What variable should he pass instead? How will that change the contents of the part of `$xml`? – Barmar Apr 09 '15 at 09:35
  • @Barmar i can't guide him since i don't know much abount xml ,xpath and all but i know can't use method return in unset so i posted the answer...sorry – Ayyanar G Apr 09 '15 at 09:37
  • You're just telling him what the error message already says. Unless you can show him how to fix the problem, you're not helping. – Barmar Apr 09 '15 at 09:40
  • This should just be a comment since it doesn't try to solve the problem. – Barmar Apr 09 '15 at 09:40
  • actually, now i understand what the error means, i can't use the method itself in `unset`, i need to do the xpath outside the method and use a variable name in the `unset()` method? – Jamie McAllister Apr 09 '15 at 09:43