Re: [RFC] Enum proposal (yet another)

From: Date: Thu, 23 Feb 2012 19:01:29 +0000
Subject: Re: [RFC] Enum proposal (yet another)
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-57979@lists.php.net to get a copy of this message
On 23/02/12 00:09, Stas Malyshev wrote: > Hi! > >>> Sidenote, according your examples above on how you want call >>> functions: Considered using normal constants? >> How can I do type hinting with them? > > You should not. PHP is not a strictly typed language, so if you want > strictly typed function you'll get in trouble, for the same reasons > why strict scalar typing wasn't a good idea - you may want to re-read > these discussions. I disagree. It is arguable whether having > enum Databases { MySQL, Postgres, Oracle } > enum Colors { Red, Green, Blue } > > database_select(Colors::Red, $sql); should give an error for a Databases type hint on the first parameter, as it can be converted (that's a soft vs strict typing issue). However, such typehint should avoid a call like: > database_select(1024, $sql); with which the function can't do anything sensible with (other than returning an error if it does its own checking). Best regards

« previous php.internals (#57979) next »