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

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

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.

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

Re: [PHP-DEV] Extensions to traits

2011-02-23 Thread Ben Schmidt
On 13/02/11 9:15 PM, André Rømcke wrote: On Thu, Feb 10, 2011 at 6:25 PM, Ben Schmidt mail_ben_schm...@yahoo.com.auwrote: On 11/02/11 3:37 AM, Philip Olson wrote: You now have rights to the wiki rfc namespace. Thanks a lot, Philip. I have now made an RFC based on the most recent

Re: [PHP-DEV] Extensions to traits

2011-02-23 Thread Ben Schmidt
That might seem odd but it's not inheritance. Yeah. And that's my main concern with it. It seems like inheritance (and is described like inheritance in the RFC at present--which is a documentation issue that will need to be addressed in the manual eventually), but it isn't. I feel it should be

Re: [PHP-DEV] Extensions to traits

2011-02-23 Thread Ben Schmidt
http://wiki.php.net/rfc/traitsmodifications Some thoughts: a) Class method conflict with trait Class implementation always wins I feel is the right way to think about traits. But 'abstract' already has special meaning, so maybe a keyword like 'final' could also do something special. André

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 mail_ben_schm...@yahoo.com.auwrote: 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.

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 martinsco...@gmail.com wrote:  Martin Scotta On Wed, Feb 23, 2011 at 7:12 AM, Ben Schmidt mail_ben_schm...@yahoo.com.auwrote: Are you suggesting this as an enum member function, or just a regular function in any old class? Enum member

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

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

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 Jarrod Nettles
I don't think that your implementation will work as it would require an entire re-imagining of type hinting and/or of classes. In your example, any method that type hinted against Element would be expecting an instance of the abstract class, Element. There's no way to differentiate between the

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 before calling this

Re: [PHP-DEV] get_class inconsistency

2011-02-23 Thread Benjamin Eberlei
No, this wouldnt be backwards compatible to the PHP 5.2 behavior, hence inconsistent. The convention is class names in strings are ALWAYS fully qualified, therefore the prefix backslash is not necessary. On Wed, 23 Feb 2011 15:14:45 -0300 Martin Scotta martinsco...@gmail.com wrote: Hi all,

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

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

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

2011-02-23 Thread Ben Schmidt
You're right, my example was broken with regard to type hinting. Should have been more like: abstract class Element { enum Type { Hydrogen, Argon, Iron } public static function weight(Element::Type $e) { ... } ... } function

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

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 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

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

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 Alexey Zakhlestin
On Thu, Feb 24, 2011 at 5:00 AM, Stas Malyshev smalys...@sugarcrm.com 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