Timm Friebe wrote: [...] > In comparison to the proposed "delete", unset() only decreases the > refcount. > > Have a look at the following examples: > > $ php-dev -r 'class Object { function __destruct() { echo > "Destroyed\n"; }} $o= new Object(); unset($o); echo "Shutting > down\n";' > Destroyed > Shutting down > > $ php-dev -r 'class Object { function __destruct() { echo > "Destroyed\n"; }} $o= new Object(); $o2= $o; unset($o); echo > "Shutting down\n";' Shutting down > Destroyed > > In the second example, the destructor is not called until *after* > shutdown. This is the small but noticeable difference between what > Florian wants and what we currently provide. > > While I agree this could be interesting, I'm opposed to a keyword > named "delete". Keywords may not be used as regular method names and > a new keyword "delete" would add more BC breaks for people using > methods called delete(). This: > > class DBConnection { > function insert() { } > function update() { } > function select() { } > function delete() { } > } > > is an example which can be seen in numerous applications. >
I really dont't want to warm up an discussion that has already been dealt with, but from my pov. - while I agree one should keep them to a minimum - minor changes are to be excpected in a major jump in version numbers and I'm sure this is not unprecedented. Then again I don't get the eMails from the developers going on about their broken code and I wouldn't want to volunteer for that. For completeness: Proposed behaviour of delete as opposed to unset: $ php-dev -r 'class Object { function __destruct() { echo "Destroyed\n"; }} $o= new Object(); $o2= &$o; delete $o; var_export( $o ); var_export( $o2 ); echo "Shutting down\n";' Destroyed NULL NULL Shutting down > Then again, why doesn't unset() do this? That seems kind of > inconsistent with the object-handle-pass-by-value semantics we have > in PHP5. > > For the time being, using reference operators and setting the instance > to NULL gives you a workaround: > > $ php-dev -r 'class Object { function __destruct() { echo > "Destroyed\n"; }} $o= new Object(); $o2= &$o; $o= NULL; echo > "Shutting down\n";' Destroyed > Shutting down > > Interesting enough (from a user's pov, not the Engine's), unset() will > not do the job: > > $ php-dev -r 'class Object { function __destruct() { echo > "Destroyed\n"; }} $o= new Object(); $o2= &$o; unset($o); echo > "Shutting down\n";' Shutting down > Destroyed I for one could manage without a delete keyword with unset destroying the object referenced - which looks for me a more consistent behaviour as Timm pointed out. ./regards Florian -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php