returning a reference in an eval




For some XML parsing purposes, I need a reference to somewhere in an associative array. I have created this method:

function &pathMapping() {
	if ($this->path > "/") {
		echo "returning...<br />";
		eval('return $this->parsedData{"' . implode('"}{"', preg_split("!/!", $this->path, -1, PREG_SPLIT_NO_EMPTY)) . '"};');
		echo "?<br />";
	return $this->parsedData;
(ofcourse the echoing here is only for debugging purposes)

I want to call it using:

$hashMap =& pathMapping("/somekey/more/and/finally/");

Which should return a refference to:


Apparently, eval("return $something;"); doesn't actually return the $something as result of the function. I can see the "?" being echoed which it shouldn't if the value was returned (return exists the function).

I've tried this format too: return eval("return $something;"); but since I want to return a reference, I get the "Only variable references should be returned by reference" error.

Apart from itterations (which are slower), is there a way to return the result of an eval as reference?

Try assigning the eval to a variable and print it to see if it's in the format you want.
Also try: return eval('whatever'); wihtout the 'return' which is inside the eval.
The problem that return eval() is not allowed when the function is supposed to return a reference to a variable.

I have tested that the format is correct, it's just returning that reference that's not working...