HELP!!! I have hit a brick wall in figuring out something with passing objects by reference in PHP5. Is what I want to do possible???
I have a situation where I want to:
1) pass an object into a function
2) have that object unset in the function
3) have this unset which occurs inside the function propogate up one level of scope to where the function call was made.
I am guessing when I unset($obj) inside the function that I am only unsetting the reference to $obj whose scope is limited to the life of that function call...
In the example code shown below, I would like the following function call:
[code=php]unsetObj($test);[/code]
actually unset the object "$test". In my test code shown below, "$test" does not get unset in the scope of main.:mad:
Background: I have a mapper class which acts as the interface between the PHP program and the database, one of the methods inside this mapper is delete. Upon a successful delete from the database, I would also like the object which we just deleted from the database to be unset by the delete method and have this unset propagate to the calling PHP code so the PHP code and database stay in synch.
Thanks in advance for any help anyone may be able to provide!!!
-james
Example output of test code shown below if viewed in a browser:
unsetting object inside unsetObj
succeeded in unseting object in scope of unsetObj
failed to unset object in scope of main
test code for viewing in a browser (for viewing from command line, replace <br> with \n in the echos)
class test {
}
function unsetObj($obj){
echo "unsetting object inside unsetObj<br>";
unset($obj);
if (isset($obj)){
echo "failed to unset object in scope of unsetObj<br>";
} else {
echo "succeeded in unseting object in scope of unsetObj<br>";
}
}
// make a new test object
$test = new test();
// attempt to unset our test object
unsetObj($test);
// check to set if it was really unset
if (isset($test)){
echo "failed to unset object in scope of main<br>";
} else {
echo "succeeded in unseting object in scope of main<br>";
}