Re: [PHP-DEV] DateTime improvement

2012-12-25 Thread Stas Malyshev
Hi!

> Sebastian had responded off-list that he'd rather have DateTime inherit 
> from DateTimeImmutable, instead of the current variant where 
> DateTimeImmutable inherits DateTime. While this OO-design principle wise 
> makes perfect sense, practically it is not as handy. I've played with a 

Actually, I would claim it doesn't make "perfect sense", since it would
mean DateTime would violate DateTimeImmutable's contract of being, well,
immutable. Strictly speaking, they can not either extend from other one,
since they have APIs which are not subset of each other. However, doing
it strictly OO would mean getting into Java-esque web of interfaces,
abstract classes and implementation classes, which would suck.
As for established practice, everybody expects DateTime, so IMHO we
should leave DateTime as base class even though it's not strictly OO-pure.

Speaking of derived classes, though, I wonder how hard it would be to
make DateTime factory methods - such as createFromFormat - to be able to
produce instance of child class? Now if you want to extend DateTime and
use those, you need to implement some weird things like:

$dt = DateTime::createFromFormat($format, $time);
$mydt = new MyDateTime("@".$dt->getTimestamp());

Maybe there's a better way but I'm not sure what it is.

-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Adding Generator::throw()

2012-12-25 Thread Stas Malyshev
Hi!

> I've been hearing this argument from time to time and I don't understand
> it; aren't exceptions created with the sole purpose of (error) flow control?

No. Exceptions are meant for something that "should never happen". I.e.,
if your application reads its config files and they are not there, or
connects to the database and database is not there - that's an
exception. If you just have something like "user clicked this button and
not that button" - it should not be an exception. Thus, exceptions
should be used to handle cases which are not part of the normal program
flow control.

That said, it does not look like in this case (generators) it is being
used wrongly, my initial impression was based on the lack of
information, and turns out to be wrong.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php