Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Alexey Zakhlestin
On Thu, Feb 24, 2011 at 5:00 AM, Stas Malyshev wrote: > Hi! > >> You can do it like this. When an enum is defined: > > I'm not talking about implementation in the code of PHP engine. I'm talking > about writing code with these things that wouldn't produce fatal errors in > random places without yo

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Stas Malyshev
Hi! Don't your arguments work equally well against type hinting for objects? You have the same problems: if you screw something up in user code and pass the wrong type, it fails at runtime. You also get 'random' failures It is true, however possibility of you having entirely different typo of

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Ben Schmidt
Don't your arguments work equally well against type hinting for objects? You have the same problems: if you screw something up in user code and pass the wrong type, it fails at runtime. You also get 'random' failures if you deserialise/read from config an object whose internal type changed since i

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Stas Malyshev
Hi! You can do it like this. When an enum is defined: I'm not talking about implementation in the code of PHP engine. I'm talking about writing code with these things that wouldn't produce fatal errors in random places without you being able to prevent it and without checking before each fu

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Ben Schmidt
I also suggest when type-hinting, if the type is integer or string where an enum is expected, PHP attempts a cast before failing, to make this more convenient. O, and if this cast (or any cast to enum) fails, IMHO, it should replace it with null. When type-hinting, this means that if null is an

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Ben Schmidt
On 24/02/11 8:33 AM, Stas Malyshev wrote: Hi! use the function: you would usually be expected to pass in a true enum constant of the MyEnum type. That works wonders in dynamic languages, without any means of really ensuring it. No, I believe you can ensure it, and you can even ensure it eff

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Ben Schmidt
probably stay in line with what happens when a type hint for a class is broken. -Original Message- From: Ben Schmidt [mailto:mail_ben_schm...@yahoo.com.au] Sent: Wednesday, February 23, 2011 9:01 AM To: Martin Scotta Cc: Alexey Zakhlestin; Stas Malyshev; Jarrod Nettles; internals@lists

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Stas Malyshev
Hi! use the function: you would usually be expected to pass in a true enum constant of the MyEnum type. That works wonders in dynamic languages, without any means of really ensuring it. No, I believe you can ensure it, and you can even ensure it efficiently. I don't see how you can do it w

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Stas Malyshev
Hi! You'd rather correct it to the closest value in the Enum, just like casting typehints? ;-) I'd rather not do it. Like, if you method can handle only a subset of integer type, handle it in the method and handle it in a meaningful, specific way. PHP is not really built for static type cont

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Derick Rethans
On Wed, 23 Feb 2011, Stas Malyshev wrote: > > > > public function Killjoy(MyEnum $x) > > > > > > What would be the purpose of such code? What would it do if 5 is > > > passed as $x? > > > > IMHO, it should fail (unless 5 is the value explicitly mentioned in > > MyEnum definition) > > So befor

RE: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Jarrod Nettles
type hint for a class is broken. -Original Message- From: Ben Schmidt [mailto:mail_ben_schm...@yahoo.com.au] Sent: Wednesday, February 23, 2011 9:01 AM To: Martin Scotta Cc: Alexey Zakhlestin; Stas Malyshev; Jarrod Nettles; internals@lists.php.net Subject: Re: [PHP-DEV] Re: Clarification on

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Hannes Landeholm
Lemme jump in here... An enum declaration is just a list of unique PHP constants.. not mathematical sets. You could argue the same thing for constants (that they can only contain scalars and not any values -> therefore not useful). If developers need to model the period table they'd define the data

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Ben Schmidt
why not supporting methods for enum values? developers will need that, and by providing type hinting, they will just create the logic somewhere else... why would developers need this? can you elaborate with some real-life scenario? I thought enums are just strong-typed constants I think this w

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Martin Scotta
Think on any finite set of elements that cannot be represented with integers because they don't hold enough data... or because the repeated values. An extremely example could be the "Periodic Table", finite set of elements, where each element holds a lot of information. function print_element(Ele

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Alexey Zakhlestin
On Wed, Feb 23, 2011 at 4:35 PM, Martin Scotta wrote: >  Martin Scotta > > > On Wed, Feb 23, 2011 at 7:12 AM, Ben Schmidt > wrote: > >> Are you suggesting this as an enum member function, or just a regular function in any old class? >>> >>> "Enum member funcion"? How much it should be li

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Martin Scotta
Martin Scotta On Wed, Feb 23, 2011 at 7:12 AM, Ben Schmidt wrote: > Are you suggesting this as an enum member function, or just a regular >>> function in any old class? >>> >> >> "Enum member funcion"? How much it should be like a class before you >> call it a class? >> > > Exactly. It's crazy.

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Ben Schmidt
Are you suggesting this as an enum member function, or just a regular function in any old class? "Enum member funcion"? How much it should be like a class before you call it a class? Exactly. It's crazy. If you want a 'member function' use a class, not an enum. use the function: you would us

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Stas Malyshev
Hi! Are you suggesting this as an enum member function, or just a regular function in any old class? "Enum member funcion"? How much it should be like a class before you call it a class? use the function: you would usually be expected to pass in a true enum constant of the MyEnum type. T

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Ben Schmidt
public function Killjoy(MyEnum $x) What would be the purpose of such code? What would it do if 5 is passed as $x? Are you suggesting this as an enum member function, or just a regular function in any old class? If 'in an enum', I think by analogy with the stuff somebody linked to on the MS si

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-23 Thread Stas Malyshev
Hi! public function Killjoy(MyEnum $x) What would be the purpose of such code? What would it do if 5 is passed as $x? IMHO, it should fail (unless 5 is the value explicitly mentioned in MyEnum definition) So before calling this method you better check it's argument against all possible en

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-22 Thread Alexey Zakhlestin
On Wed, Feb 23, 2011 at 4:29 AM, Stas Malyshev wrote: > Hi! > >> public function Killjoy(MyEnum $x) > > What would be the purpose of such code? What would it do if 5 is passed as > $x? IMHO, it should fail (unless 5 is the value explicitly mentioned in MyEnum definition) -- Alexey Zakhlestin, h

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-22 Thread Stas Malyshev
Hi! public function Killjoy(MyEnum $x) What would be the purpose of such code? What would it do if 5 is passed as $x? -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, v

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-22 Thread Ben Schmidt
tin Scotta [mailto:martinsco...@gmail.com] Sent: Tuesday, February 22, 2011 10:25 AM To: Ben Schmidt Cc: Jarrod Nettles; Thomas Gutbier; internals@lists.php.net; Stas Malyshev Subject: Re: [PHP-DEV] Re: Clarification on the Enum language structure I just don't get why no type hinting, I thought

RE: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-22 Thread Jarrod Nettles
: Tuesday, February 22, 2011 10:25 AM To: Ben Schmidt Cc: Jarrod Nettles; Thomas Gutbier; internals@lists.php.net; Stas Malyshev Subject: Re: [PHP-DEV] Re: Clarification on the Enum language structure I just don't get why no type hinting, I thought that was one of the big points so what ar

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-22 Thread Martin Scotta
joy(MyEnum $x) >> >> -Original Message- >> From: Ben Schmidt [mailto:mail_ben_schm...@yahoo.com.au] >> Sent: Friday, February 18, 2011 10:28 PM >> To: Jarrod Nettles >> Cc: Martin Scotta; Thomas Gutbier; internals@lists.php.net; Stas Malyshev >> Subject:

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-22 Thread Ben Schmidt
com.au] Sent: Friday, February 18, 2011 10:28 PM To: Jarrod Nettles Cc: Martin Scotta; Thomas Gutbier; internals@lists.php.net; Stas Malyshev Subject: Re: [PHP-DEV] Re: Clarification on the Enum language structure I did some research on methods in enums and discovered that there is some useful

RE: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-22 Thread Jarrod Nettles
(MyEnum $x) -Original Message- From: Ben Schmidt [mailto:mail_ben_schm...@yahoo.com.au] Sent: Friday, February 18, 2011 10:28 PM To: Jarrod Nettles Cc: Martin Scotta; Thomas Gutbier; internals@lists.php.net; Stas Malyshev Subject: Re: [PHP-DEV] Re: Clarification on the Enum language structure &g

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-18 Thread Ben Schmidt
class Grade { enum { A_PLUS, A, B_PLUS, B, ..., FAIL, NOT_AVAILABLE, } public static function passing($grade) { return $grade>=self::D; } } $grade=Grade::B; echo Grade::passing($grade)?"passing":"not passing"; Shouldn't that be: public static function passing($grade) { -return $grade>=self::D;

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-18 Thread Ben Schmidt
't so important, it’s the consistency of the value that's important. It’s the fact that I've chosen gopher wood and I know that even though Wood::GOPHER really means "3", I don't have to remember what "3" represents because I can specifically type that I want g

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-18 Thread Rick Widmer
On 2/18/2011 9:28 PM, Ben Schmidt wrote: I did some research on methods in enums and discovered that there is some usefulness to the idea - I wouldn't go so far as to say that they would be needed, but C#, for example, allows you to create extension methods for enums and MSDN has a decent real-wo

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-18 Thread Ben Schmidt
I did some research on methods in enums and discovered that there is some usefulness to the idea - I wouldn't go so far as to say that they would be needed, but C#, for example, allows you to create extension methods for enums and MSDN has a decent real-world example of its use. http://msdn.micro

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-18 Thread Stas Malyshev
Hi! I should comment on why people want strings as enum values - just look at ENUM type in MySQL. People use it, and if you take a look from that perspective - it makes sense. Enum type in the database is totally different because it's a constraint, not an alias to some underlying piece of da

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-18 Thread Martin Scotta
WILLOW, > >>GOPHER > >> } > >> > >> There's nothing in there that would necessitate needing a string value > and really, if you need a string value, pass in a string as your parameter! > Enumerations should be used to represent a set of data wher

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-18 Thread Hannes Landeholm
string as your parameter! >> Enumerations should be used to represent a set of data where the value >> itself isn't so important, it’s the consistency of the value that's >> important. It’s the fact that I've chosen gopher wood and I know that even >> though

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-18 Thread Arvids Godjuks
-Original Message- > From: Ben Schmidt [mailto:mail_ben_schm...@yahoo.com.au] > Sent: Thursday, February 17, 2011 4:52 PM > To: Martin Scotta > Cc: Jarrod Nettles; Thomas Gutbier; internals@lists.php.net > Subject: Re: [PHP-DEV] Re: Clarification on the Enum language structu

RE: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-18 Thread Jarrod Nettles
hat I want gopher. -Original Message- From: Ben Schmidt [mailto:mail_ben_schm...@yahoo.com.au] Sent: Thursday, February 17, 2011 4:52 PM To: Martin Scotta Cc: Jarrod Nettles; Thomas Gutbier; internals@lists.php.net Subject: Re: [PHP-DEV] Re: Clarification on the Enum language structure &g

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-17 Thread Ben Schmidt
Also, I feel like it should be restricted to integral types only, and defaults to a zero-based incrementing integer. This is more in line with other programming languages that already implement enums and will present "expected behavior" for people moving over to PHP. for me that's a plain old in

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-17 Thread Stas Malyshev
Hi! I think the proposal in the Wiki is just fine - enums should be simple, restricted to enumeration and be just a syntax sugar for the series of constants/defines. public function setLogLevel (Levels $logLevel) { $this->logLevel = $logLevel; } This I think is an overkill. Think about

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-17 Thread Richard Quadling
On 17 February 2011 19:32, Martin Scotta wrote: > On Thu, Feb 17, 2011 at 3:01 PM, Jarrod Nettles wrote: > >> An enum is not a class. > > totally agree. an enum is a family of related constant values. > > >> It has no methods or properties and is not something that you instantiate. >> > partially

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-17 Thread Martin Scotta
tinsco...@gmail.com] > Sent: Monday, February 14, 2011 11:27 AM > To: Thomas Gutbier > Cc: internals@lists.php.net > Subject: Re: [PHP-DEV] Re: Clarification on the Enum language structure > > On Mon, Feb 14, 2011 at 12:45 PM, Thomas Gutbier < > thomas.gutb...@anthrotec.de&

RE: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-17 Thread Jarrod Nettles
e registered autoloaders. /Framework/Web/Mvc/HttpVerbsEnum -Original Message- From: Martin Scotta [mailto:martinsco...@gmail.com] Sent: Monday, February 14, 2011 11:27 AM To: Thomas Gutbier Cc: internals@lists.php.net Subject: Re: [PHP-DEV] Re: Clarification on the Enum language structure On Mon,

Re: [PHP-DEV] Re: Clarification on the Enum language structure

2011-02-14 Thread Martin Scotta
On Mon, Feb 14, 2011 at 12:45 PM, Thomas Gutbier < thomas.gutb...@anthrotec.de> wrote: > Jarrod Nettles wrote: > >> So, my proposed syntax would look something more like this. >> > > I think also and was wondering about the current rfc for a few weeks. > Im not a core developer but I want to outli