too long

Possible Duplicate:
In PHP how can I access a “:private” array in an object?

I am not sure if there is a right way to do this or if this is completely unacceptable technique.

I am using PHP and I am in a situation where a script is given an object, it does not have access to the objects Class and many of the properties are protected (see below).

Is it possible to "hack" (bad choice of words) the object manually to amend property values on the fly?
Not sure of a way to do this or if there is a way by converting one way and then back again.

object(__PHP_Incomplete_Class)#3 (16) {


["__PHP_Incomplete_Class_Name"]=>
  string(28) "Zend_Controller_Request_Http"
  ["_paramSources":protected]=>
  array(2) {
    [0]=>
    string(4) "_GET"
    [1]=>
    string(5) "_POST"
  }
  ["_requestUri":protected]=>
  string(13) "/?mod=mainnav"
  ["_baseUrl":protected]=>
  NULL
  ["_basePath":protected]=>
  NULL
  ["_pathInfo":protected]=>
  string(0) ""
  ["_params":protected]=>
  array(0) {
  }
  ["_rawBody":protected]=>
  NULL
  ["_aliases":protected]=>
  array(0) {
  }
  ["_dispatched":protected]=>
  bool(false)
  ["_module":protected]=>
  NULL
  ["_moduleKey":protected]=>
  string(6) "module"
  ["_controller":protected]=>
  NULL
  ["_controllerKey":protected]=>
  string(10) "controller"
  ["_action":protected]=>
  NULL
  ["_actionKey":protected]=>
  string(6) "action"
}

Ended up using a more simple technique to do this.
I have the Object serialized into a string. So I simply replaced the current value (which I always have) with the new value using preg_replace.

There is some regex which will find the variable name and then I could change its value (so doesn't require knowing the value) but I hadn't been able to complete that yet (and I do have the current value).

$objectA = serialize($request);
$current_url = '\?mod=mainnav';
$new_url = 'newpage';
$objectB = preg_replace('/'.$current_url.'/', $new_url, $objectA);

//check the new object
var_dump('<pre>');
var_dump(unserialize($objectB));
var_dump('</pre>');

Using Reflections is probably the better technique most of the time, but for what I needed here I felt this was an simple and fast way to do it plus keeps all other object properties.

If properties are protected you can create a class that extends from this one and modify any properties. If they are private look at Reflection:

$reflecRequest = new ReflectionObject($request);
$reflecRequestProp = $reflecRequest->getProperty('_requestUri');
$reflecRequestProp->setAccessible(true);
$reflecRequestProp->setValue($request, 'newUri');