1

What I require

I want to add a new property into an object.

var_dump gives the following result

 array (size=1)
0 => 
object(Item)[430]
  protected '_node' => null
  protected '_id' => 
    array (size=1)
      'ItemId' => string '4596' (length=4)
  protected '_data' => 
    array (size=8)
      'ItemId' => string '4596' (length=4)
      'Id' => string '1055' (length=4)
      'employee' => string '40' (length=2)
      'project' => string '73' (length=2)
      'activity' => string '473' (length=3)
      'date' => string '2015-09-28' (length=10)
      'duration' => string '28800' (length=5)
      'comment' => null
  protected '_values' => 
    .
    .
    .

I want to add another property customer into the object so that the object will look like this

 array (size=1)
0 => 
object(Item)[430]
  protected '_node' => null
  protected '_id' => 
    array (size=1)
      'ItemId' => string '4596' (length=4)
  protected '_data' => 
    array (size=8)
      'ItemId' => string '4596' (length=4)
      'Id' => string '1055' (length=4)
      'employee' => string '40' (length=2)
      'project' => string '73' (length=2)
      'activity' => string '473' (length=3)
      'date' => string '2015-09-28' (length=10)
      'duration' => string '28800' (length=5)
      'comment' => null
      'customer' => string '20' (length=2)
  protected '_values' => 
    .
    .
    .

How can I do this?

Edit

print_r() returns

  Array
    (
   [0] => Item Object
      (
        [_node:protected] => 
        [_id:protected] => Array
            (
                [ItemId] => 4596
            )

        [_data:protected] => Array
            (
                [ItemId] => 4596
                [Id] => 1055
                [employee] => 40
                [project] => 73
                [activity] => 473
                [date] => 2015-09-28
                [duration] => 28800
                [comment] => 
            )

        [_values:protected] => Array
Avinash
  • 1,935
  • 7
  • 29
  • 55

1 Answers1

0

As I see it, customer is not a property, but a key to the hash in the $_data property. So what about

$object->_data['customer'] = '20';

Since the $_data property is protected, you will have to do this inside the class or derivatives.

syck
  • 2,984
  • 1
  • 13
  • 23