PHP

Dynamically Delete an Object’s Property in PHP

TAGs: 0 Comment

Posted By: eligeske on in PHP

You can delete an object’s property using unset.

  1. unset($object->property_name);

But if you want to access it using a string you need to be a little more creative.  Why? Because if you enter this:

WRONG WAY:

  1. unset($object["property_name"]);

You will end up with: “Fatal error: Cannot use object of type … as array”

CORRECT WAY:

  1. unset($object->{"property_name"});

And that’s how you make an ice cream sunday…. Wait….. wrong post….

 

0 Responses to "Dynamically Delete an Object’s Property in PHP"

"SHARING IS CARING"

Comments are closed.

Learning DHTMLX Suite UI

Learn the foundation of the DHTMLX Suite quickly while building a single page application with multiple components in harmony.

Popular post