Hello,
pretend some noob has (in a fake-static class) provided the following method
public static kill_object($obj)
{
if (!is_object($obj))
return false;
$obj = null;
return true;
}
Obviously noob is heading at destroying an object!
Does he succeed?
Let's see:
<code>
$blubber = new crazy_object...;
... some schnickschnack...
if (!static_class::kill_object($blubber))
exit(0);
print_r($blubber);
if (isset($blubber))
print "I'm Blubber\n";
else
print "I'm Blubber no more\n";
</code>
noob would expect to see no print_r-output and the message should be
"I'm Blubber no more"
Actually, things are quite different:
1st: Object is printed per print_r
2nd: Message is "I'm Blubber"
Haven't I just killed the object...? Objects, when supplied as parameter,
are passed by reference in php5, aren't they?
OK, that obviously did not work (somehow... - remember, I'm a noob).
I reformulate the static kill_object-method:
public static kill_object(&$obj)
{
if (!is_object($obj))
return false;
$obj = null;
return true;
}
Note, that there comes the old (deprecated) reference-operator '&' (that -
for objects - is no longer needed in php5, right?)
This time, however, the result is:
1st: Object is no longer printed (per print_r)
2nd: Message is "I'm Blubber no more"
Please assist!
cheers
juergen