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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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.
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
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
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
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
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
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
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
: 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
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:
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
(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
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;
'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
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
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
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
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
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
-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
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
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
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
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
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&
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,
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
42 matches
Mail list logo