Re: Are PHP5 features worth it?
| From: | Jochem Maas | Date: | Wed, 20 Dec 2006 10:49:25 +0000 |
| Subject: | Re: Are PHP5 features worth it? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-246066@lists.php.net to get a copy of this message | ||
Roman Neuhauser wrote:
> # zorglub_olsen@hotmail.com / 2006-12-19 19:05:23 +0100:
...
...
>> What major compelling reasons do I have to start using exceptions and OOP-5?
>
> All the things you mentioned, and then some.
>
> Someone else mentioned that PHP 5 is much less inclined to copy objects.
it's not inclined to copy at all - you always get a reference to the existing
object.
> You still don't get the convenience of a private copy constructor, but
> hey.
maybe I misunderstand you but isn't this what you mean by 'private copy ctor'?:
http://php.net/manual/en/language.oop5.cloning.php
>
> Another thing is destructors, so you're able to mimic C++'s powerful
>
> // unlocked
> {
> mylock_t lock;
> // locked
> }
> // unlocked
>
> (not so powerful in PHP without anonymous scopes).
>
> For example, a unit-testing library for PHP 5 called Testilence provides two
> utility classes, a temporary dir and a temporary file (see mkdtemp(3),
> mkstemp(3)). Both classes remove the underlying filesystem objects in their
> destructors, so you can conveniently skip doing the cleanup yourself:
>
> function test_O_EXCL_ThrowsOnExistingPath()
> {
> $file = $this->mkstemp();
> $this->willThrow('RuntimeException');
> new SplFileObject($file->path(), 'x+');
> }
>
> Also, notice how the code can omit checking for errors in mkstemp().
> The return value is guarranteed to be the right thing, since any errors would
> be signalled by throwing an exception, and that is handled By the caller of
> this method.
>
> How about iterators? You can have objects that look like arrays yet they take
> much less memory:
>
> $rs = $db->query($select); # query the db
> foreach ($rs as $row) { # fetch the row
> whatever($row);
> }
ah yes - good catch, I do like iterators for keeping code nice and tight.
>