Hi Devs,
what would probably be a nice addition:
- static classes:
static classes can only contain static methods and attributes
<?php
static class foo {
public static function bar() {}
}
?>
- final classes:
final classes can't be extended
final class foo {
public function bar() {}
}
- final static classes
final static classes can only contain static methods and attributes and
can't be extended.
final static class foo {
public static function bar() {}
}
What do you think about it?
Michael Virnstein wrote:
What do you think about it?
PINJ (PHP Is Not Java) ;-)
Let's keep the language simple, too much was added already IMHO (-:C
- Chris
i don't any experience with java, but i ran into a case, where this
would have been useful. And i disagree with the "too much was added
already". I think that php, dispite all the added stuff, is still easy
to learn, easy to read and easy to work with. PHP simply got more
powerful and i hope it'll grow further. Adding the things i mentioned
would simply mean more control on the implementation of a class. It
wouldn't get more complicated in any way and there'd be noone forcing
you to use those things. You would simply have tools to enforce some
rules, which is not a bad thing.
Michael
Christian Schneider wrote:
Michael Virnstein wrote:
What do you think about it?
PINJ (PHP Is Not Java) ;-)
Let's keep the language simple, too much was added already IMHO (-:C
- Chris
things i'd like to add:
- abstract classes can be defined static also
<?php
abstract static class foo {
abstract public static function bar();
}
this means that all subclasses of foo must also be static and can only
contain static methods and attributes
- abstract classes can't be defined final
Regards, Michael
Michael Virnstein wrote:
Hi Devs,
what would probably be a nice addition:
- static classes:
static classes can only contain static methods and attributes<?php
static class foo {
public static function bar() {}
}
?>
- final classes:
final classes can't be extendedfinal class foo {
public function bar() {}
}
- final static classes
final static classes can only contain static methods and attributes and
can't be extended.final static class foo {
public static function bar() {}
}What do you think about it?
Hello Michael,
Tuesday, September 28, 2004, 3:44:48 PM, you wrote:
things i'd like to add:
- final classes:
final classes can't be extended
already supported
- abstract classes can be defined static also
makes no sense (duplicate): both mean you cannot instantiate the class.
<?php
abstract static class foo {
abstract public static function bar();
}
abstract static methods are already supported
this means that all subclasses of foo must also be static and can only
contain static methods and attributes
- abstract classes can't be defined final
already supported
static classes would be implementable at the cost of increasing compiler time.
To decide whether to think more about it we'd to know a case where you need
such syntax, what you win by having it and what you loose if you don't have
it.
regards
marcus
p.s.: as a hint, next time read the docs before requesting syntax we support
already.
- final classes:
final classes can't be extendedalready supported
Cannot find it in the docs.
http://www.php.net/manual/en/language.oop5.final.php doesn't seem to have
any comments on that.
I'm not at home at the moment, so i couldn't try, but are you really sure
that final CLASSES are supported?
You're not confusing it with final METHODS, right?
abstract static methods are already supported
never said php doesn't support it, i just wanted to give some more input on
the rules that would fit for my suggestions.
- abstract classes can't be defined final
already supported
same as above
static classes would be implementable at the cost of increasing compiler
time.
To decide whether to think more about it we'd to know a case where you
need
such syntax, what you win by having it and what you loose if you don't
have
it.
A good example for a static class imo, would be e.g. PEAR's DB Class. The
DB-Class itself doesn't need to be instantiate,
it simply works as factory and has some functions to check stuff. that'd be
a class that i would define as
"final static class DB {}". The class should not be extended and should not
containt non static methods or attributes. Sure it isn't
a big deal, if ppl are instantiating the DB Class, but it only has static
methods and instantiating it wouldn't make any sense.
Regards, Michael
Michael Virnstein wrote:
- final classes:
final classes can't be extendedalready supported
Cannot find it in the docs.
http://www.php.net/manual/en/language.oop5.final.php doesn't seem to have
any comments on that.
I'm not at home at the moment, so i couldn't try, but are you really sure
that final CLASSES are supported?
You're not confusing it with final METHODS, right?abstract static methods are already supported
never said php doesn't support it, i just wanted to give some more input on
the rules that would fit for my suggestions.
- abstract classes can't be defined final
already supported
same as above
static classes would be implementable at the cost of increasing compiler
time.
To decide whether to think more about it we'd to know a case where you
need
such syntax, what you win by having it and what you loose if you don't
have
it.
A good example for a static class imo, would be e.g. PEAR's DB Class. The
DB-Class itself doesn't need to be instantiate,
it simply works as factory and has some functions to check stuff. that'd be
a class that i would define as
"final static class DB {}". The class should not be extended and should not
containt non static methods or attributes. Sure it isn't
a big deal, if ppl are instantiating the DB Class, but it only has static
methods and instantiating it wouldn't make any sense.Regards, Michael
Please see: http://www.php.net/zend-engine-2.php
This will explain all the new OOP features in PHP5
Regards,
Jason
it seems to me that the documentation pointed to is a little out of
date, at least the part about reflection is using 'old' (read:
notStudlyCapsCS) class names - might be worth fixing that to avoid a
hundred-thousand emails along the lines of 'reflection is broken'.
kind regards,
Jochem
ps - I just discovered the profiling possibilities of XDEBUG, nice one
Derick (& co?)!
Jason Farrell wrote:
Please see: http://www.php.net/zend-engine-2.php
This will explain all the new OOP features in PHP5Regards,
Jason
Hello Michael,
Wednesday, September 29, 2004, 11:44:04 AM, you wrote:
- final classes:
final classes can't be extendedalready supported
Cannot find it in the docs.
http://www.php.net/manual/en/language.oop5.final.php doesn't seem to have
any comments on that.
I'm not at home at the moment, so i couldn't try, but are you really sure
that final CLASSES are supported?
You're not confusing it with final METHODS, right?
Nope, i invented both final and abstract for both classes and methods :-)
A good example for a static class imo, would be e.g. PEAR's DB Class. The
DB-Class itself doesn't need to be instantiate,
it simply works as factory and has some functions to check stuff. that'd be
a class that i would define as
"final static class DB {}". The class should not be extended and should not
containt non static methods or attributes. Sure it isn't
a big deal, if ppl are instantiating the DB Class, but it only has static
methods and instantiating it wouldn't make any sense.
Ah so it is just a little bit more enforcement then the following:
final class DB
{
// prevent instantiation
private function __construct() { exit(0); }
// The following is not needed because the constructor cannot be called
// private function __clone() { exit(0); }
}
--
Best regards,
Marcus mailto:helly@php.net