Re: Are PHP5 features worth it?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Roman Neuhauser wrote:
> # zorglub_olsen@xxxxxxxxxxx / 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.

> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux