PHP Tips

From KaminskiWiki
Jump to: navigation, search

Adding a Property to an Object

# Returns a clone of the original object, with the added property
function add_a_property($object, $property_name, $property_value)
{
  $temporary_array = (array) $object;
  $temporary_array[$property_name] = $property_value;
  return (object) $temporary_array;
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox