0

I have a dynamic class referenced by $row->attributes(), that has some overloaded (dynamic) properties, e.g. $row->attributes()->property1.

I want to unset property1. I've tried $row->attributes()->__unset("property1") and unset($row->attributes()->property1). No joy.

Anyone know how to do this?

4
  • I'm not sure how well calling an unset on an object property would go (or even if it's possible). Why not just set the value to null? What's the reason the property must be full extinguished? Commented Dec 30, 2010 at 6:50
  • Writing a function that converts the attributes of an XML tag into an associative array. Giving the user the option to set a key for that array (from an attribute value), and want to remove the attribute from that array. Commented Dec 30, 2010 at 7:07
  • Are you using (or extending?) SimpleXMLElement? Commented Dec 30, 2010 at 11:45
  • Hi salathe, yes I am using SimpleXMLElement Commented Feb 13, 2011 at 3:17

1 Answer 1

2

It's unclear from the question whether you have used this approach, if you have, I'll remove this answer.

Take a look at __unset, simple example is:

class Foo
{
    public function __unset($property)
    {
        unset($this->__my_property_holder[$property]);
    }
}

You simply need to do unset($row->attributes()->property1), and it will actually invoke Foo->__unset('property1').

Sign up to request clarification or add additional context in comments.

1 Comment

While your answer is correct, in this case the class is built into the PHP source code (SimpleXMLElement) so I can't modify it. Perhaps it is an implementation error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.