<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>Comments on: PHP: Don&#8217;t Call the Destructor Explicitly</title>
	<atom:link href="/2011/11/14/php-dont-call-the-destructor-explicitly/feed/" rel="self" type="application/rss+xml" />
	<link>/2011/11/14/php-dont-call-the-destructor-explicitly/</link>
	<description>on web development</description>
	<lastBuildDate>Fri, 26 Oct 2018 21:40:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>By: Oliver Leitner</title>
		<link>/2011/11/14/php-dont-call-the-destructor-explicitly/comment-page-1/#comment-481912</link>
		<dc:creator><![CDATA[Oliver Leitner]]></dc:creator>
		<pubDate>Fri, 23 Feb 2018 10:20:49 +0000</pubDate>
		<guid isPermaLink="false">/?p=2461#comment-481912</guid>
		<description><![CDATA[heh, thanks for the bit of heads up... ive noticed something funny though...

lets say i have the following:

class myclass {
  public $output = &#039;&#039;;
   function __construct(){
         $this-&#062;output = &quot;hello world&quot;;
   }
   function __destruct(){
        echo &quot;lord of destruction\n&quot;;
        unset($this-&#062;output);
   }
   protected function Main(){ return null; }
}

$mycall = new myClass();
var_dump($mycall);
$mycall = null;

i would expect something like this:

mycall
hello world

what i  get instead is:

hello world
mycall

it has probably something to do with what christian datculescu pointed out... though i at this point cannot quite wrap my had around the results...]]></description>
		<content:encoded><![CDATA[<p>heh, thanks for the bit of heads up&#8230; ive noticed something funny though&#8230;</p>
<p>lets say i have the following:</p>
<p>class myclass {<br />
  public $output = &#8221;;<br />
   function __construct(){<br />
         $this-&gt;output = &#8220;hello world&#8221;;<br />
   }<br />
   function __destruct(){<br />
        echo &#8220;lord of destruction\n&#8221;;<br />
        unset($this-&gt;output);<br />
   }<br />
   protected function Main(){ return null; }<br />
}</p>
<p>$mycall = new myClass();<br />
var_dump($mycall);<br />
$mycall = null;</p>
<p>i would expect something like this:</p>
<p>mycall<br />
hello world</p>
<p>what i  get instead is:</p>
<p>hello world<br />
mycall</p>
<p>it has probably something to do with what christian datculescu pointed out&#8230; though i at this point cannot quite wrap my had around the results&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: awful article</title>
		<link>/2011/11/14/php-dont-call-the-destructor-explicitly/comment-page-1/#comment-463020</link>
		<dc:creator><![CDATA[awful article]]></dc:creator>
		<pubDate>Thu, 24 Aug 2017 05:49:20 +0000</pubDate>
		<guid isPermaLink="false">/?p=2461#comment-463020</guid>
		<description><![CDATA[This is complete bullcrap of a piece of writing and a conceptual error upon a conceptual error.

The author&#039;s premise is that destructors should not be called explicitly because &#039;they don&#039;t actively unset the object&#039;. Mentioning this makes absolutely zero sense. The language specifies clearly enough that destructors are what they are (and only that): methods automatically called upon an object&#039;s actual internal destruction. The author justifies his recommendation not to call destructors based on a purported semantic incongruence (&#039;they seem to actively destroy the object, but they do not&#039;), except that incongruence exists only in his own mind. The parenthetical part (what they &#039;seem&#039; to do) has zero basis in the actual language, and therefore, any prescription following from it is baseless as well.

And then, he contributes to a baseless AND harmful a priori notion that there never exists reason to execute whatever a destructor does before the object&#039;s actual destruction. In fact, no doubt unwittingly, but he as good as proven himself wrong by the very examples he provided. It is perfectly reasonable to imagine a case where, for instance, a string message has to be signalled at destruction, but optionally, at the writer&#039;s discretion, at n instances before that. This misconception may result from assuming that a destructor has to contribute to resource cleanup; but in reality, it very well can be used to communication (any action, in fact, that MAY be performed more than once but MUST be performed once).

The author&#039;s authoritative tone while violating all the above points is particularly egregious.

FAILED.]]></description>
		<content:encoded><![CDATA[<p>This is complete bullcrap of a piece of writing and a conceptual error upon a conceptual error.</p>
<p>The author&#8217;s premise is that destructors should not be called explicitly because &#8216;they don&#8217;t actively unset the object&#8217;. Mentioning this makes absolutely zero sense. The language specifies clearly enough that destructors are what they are (and only that): methods automatically called upon an object&#8217;s actual internal destruction. The author justifies his recommendation not to call destructors based on a purported semantic incongruence (&#8216;they seem to actively destroy the object, but they do not&#8217;), except that incongruence exists only in his own mind. The parenthetical part (what they &#8216;seem&#8217; to do) has zero basis in the actual language, and therefore, any prescription following from it is baseless as well.</p>
<p>And then, he contributes to a baseless AND harmful a priori notion that there never exists reason to execute whatever a destructor does before the object&#8217;s actual destruction. In fact, no doubt unwittingly, but he as good as proven himself wrong by the very examples he provided. It is perfectly reasonable to imagine a case where, for instance, a string message has to be signalled at destruction, but optionally, at the writer&#8217;s discretion, at n instances before that. This misconception may result from assuming that a destructor has to contribute to resource cleanup; but in reality, it very well can be used to communication (any action, in fact, that MAY be performed more than once but MUST be performed once).</p>
<p>The author&#8217;s authoritative tone while violating all the above points is particularly egregious.</p>
<p>FAILED.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rafark</title>
		<link>/2011/11/14/php-dont-call-the-destructor-explicitly/comment-page-1/#comment-431043</link>
		<dc:creator><![CDATA[Rafark]]></dc:creator>
		<pubDate>Tue, 22 Nov 2016 23:35:41 +0000</pubDate>
		<guid isPermaLink="false">/?p=2461#comment-431043</guid>
		<description><![CDATA[It is indeed a hook, and nothing else. How is this useful in unit tests anyway?

Btw: interestingly enough, all comments in this post were made in November, the last two from different  years.]]></description>
		<content:encoded><![CDATA[<p>It is indeed a hook, and nothing else. How is this useful in unit tests anyway?</p>
<p>Btw: interestingly enough, all comments in this post were made in November, the last two from different  years.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Malte Riesch</title>
		<link>/2011/11/14/php-dont-call-the-destructor-explicitly/comment-page-1/#comment-19674</link>
		<dc:creator><![CDATA[Malte Riesch]]></dc:creator>
		<pubDate>Thu, 07 Nov 2013 10:15:04 +0000</pubDate>
		<guid isPermaLink="false">/?p=2461#comment-19674</guid>
		<description><![CDATA[I can see one scenario where calling __destruct directly is useful, or required, and that is in unit testing.... just a thought..]]></description>
		<content:encoded><![CDATA[<p>I can see one scenario where calling __destruct directly is useful, or required, and that is in unit testing&#8230;. just a thought..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pahnin</title>
		<link>/2011/11/14/php-dont-call-the-destructor-explicitly/comment-page-1/#comment-14703</link>
		<dc:creator><![CDATA[pahnin]]></dc:creator>
		<pubDate>Mon, 28 Nov 2011 19:00:11 +0000</pubDate>
		<guid isPermaLink="false">/?p=2461#comment-14703</guid>
		<description><![CDATA[I havnt understood the last example
How this 
 &lt;blockquote&gt;
$b = new A();
$d = $c = $b;
 &lt;/blockquote&gt;
is different from 
&lt;blockquote&gt;
$obj = new A();
$newObj = $obj;
&lt;/blockquote&gt;]]></description>
		<content:encoded><![CDATA[<p>I havnt understood the last example<br />
How this </p>
<blockquote><p>
$b = new A();<br />
$d = $c = $b;
 </p></blockquote>
<p>is different from </p>
<blockquote><p>
$obj = new A();<br />
$newObj = $obj;
</p></blockquote>
]]></content:encoded>
	</item>
	<item>
		<title>By: cristian datculescu</title>
		<link>/2011/11/14/php-dont-call-the-destructor-explicitly/comment-page-1/#comment-14702</link>
		<dc:creator><![CDATA[cristian datculescu]]></dc:creator>
		<pubDate>Mon, 28 Nov 2011 10:51:35 +0000</pubDate>
		<guid isPermaLink="false">/?p=2461#comment-14702</guid>
		<description><![CDATA[Just saw that you have a article about passing by reference, so the entire $x = NULL discussion is [i think] on a no-subject. As long as you still have a reference to your object, the object cannot be destroied :)]]></description>
		<content:encoded><![CDATA[<p>Just saw that you have a article about passing by reference, so the entire $x = NULL discussion is [i think] on a no-subject. As long as you still have a reference to your object, the object cannot be destroied 🙂</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cristian datculescu</title>
		<link>/2011/11/14/php-dont-call-the-destructor-explicitly/comment-page-1/#comment-14701</link>
		<dc:creator><![CDATA[cristian datculescu]]></dc:creator>
		<pubDate>Mon, 28 Nov 2011 10:47:31 +0000</pubDate>
		<guid isPermaLink="false">/?p=2461#comment-14701</guid>
		<description><![CDATA[Yes. But you missed a small thing in PHP 5 [actually a big one]. All object assignments ARE DONE by reference. So $tsttsts = $obj means that $tsttsts is a reference to the same memory block. :) i am sorry if i was unclear [i assumed this was already pointed out]. In PHP5 there is the cloning for getting a clone of the object.

I am sorry and i hope i haven&#039;t offended you with this response.

Thanks for the response, Cristian.]]></description>
		<content:encoded><![CDATA[<p>Yes. But you missed a small thing in PHP 5 [actually a big one]. All object assignments ARE DONE by reference. So $tsttsts = $obj means that $tsttsts is a reference to the same memory block. 🙂 i am sorry if i was unclear [i assumed this was already pointed out]. In PHP5 there is the cloning for getting a clone of the object.</p>
<p>I am sorry and i hope i haven&#8217;t offended you with this response.</p>
<p>Thanks for the response, Cristian.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stoimen</title>
		<link>/2011/11/14/php-dont-call-the-destructor-explicitly/comment-page-1/#comment-14700</link>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
		<pubDate>Mon, 28 Nov 2011 08:42:55 +0000</pubDate>
		<guid isPermaLink="false">/?p=2461#comment-14700</guid>
		<description><![CDATA[Hi Cristian,

it seems like you haven&#039;t read the post. An excerpt from one of the examples clearly explains yours &lt;em&gt;&quot;... if $x is a object, $a = $x, $x = NULL, will only eliminate the variable $x, because $a still holds a valid reference to the initial object.&quot;&lt;/em&gt;
&lt;pre lang=&quot;PHP&quot;&gt;
$obj = new A();
 
// $newObj is pointing to $obj
$newObj = $obj;
 
// this doesn&#039;t destroy $newObj
// as it appears both $obj and $newObj point to the same memory
// so PHP doesn&#039;t free this memory
$obj = null;
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Hi Cristian,</p>
<p>it seems like you haven&#8217;t read the post. An excerpt from one of the examples clearly explains yours <em>&#8220;&#8230; if $x is a object, $a = $x, $x = NULL, will only eliminate the variable $x, because $a still holds a valid reference to the initial object.&#8221;</em></p>
<pre lang="PHP">
$obj = new A();
 
// $newObj is pointing to $obj
$newObj = $obj;
 
// this doesn't destroy $newObj
// as it appears both $obj and $newObj point to the same memory
// so PHP doesn't free this memory
$obj = null;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: cristian datculescu</title>
		<link>/2011/11/14/php-dont-call-the-destructor-explicitly/comment-page-1/#comment-14699</link>
		<dc:creator><![CDATA[cristian datculescu]]></dc:creator>
		<pubDate>Mon, 28 Nov 2011 07:38:57 +0000</pubDate>
		<guid isPermaLink="false">/?p=2461#comment-14699</guid>
		<description><![CDATA[For the destructor not &quot;killing&quot; a object, you and most others got it wrong. It is normal, and it is the way it should behave. A destructor is what you would normally call a hook, that gets called before the object is actually destroyed, allowing you to do additional operations either before nulling a object or the script shutting down. 

Also please beware that destroying a object will not actually destroy the object because an object can be destroyed only when there are no references to it anymore. Since in php5 all assignments of objects are done by reference, if $x is a object, $a = $x, $x = NULL, will only eliminate the variable $x, because $a still holds a valid reference to the initial object.]]></description>
		<content:encoded><![CDATA[<p>For the destructor not &#8220;killing&#8221; a object, you and most others got it wrong. It is normal, and it is the way it should behave. A destructor is what you would normally call a hook, that gets called before the object is actually destroyed, allowing you to do additional operations either before nulling a object or the script shutting down. </p>
<p>Also please beware that destroying a object will not actually destroy the object because an object can be destroyed only when there are no references to it anymore. Since in php5 all assignments of objects are done by reference, if $x is a object, $a = $x, $x = NULL, will only eliminate the variable $x, because $a still holds a valid reference to the initial object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stoimen</title>
		<link>/2011/11/14/php-dont-call-the-destructor-explicitly/comment-page-1/#comment-14595</link>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
		<pubDate>Tue, 15 Nov 2011 07:26:17 +0000</pubDate>
		<guid isPermaLink="false">/?p=2461#comment-14595</guid>
		<description><![CDATA[@Tobias - thanks!]]></description>
		<content:encoded><![CDATA[<p>@Tobias &#8211; thanks!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
