about final methods and attributes

php.internals

Cristiano Duarte

23 years ago
Ok, final methods and attributes are cool, but what about final classes ? Is it hard to implement ? Or all classes must be able to be extended by children ? Cristiano Duarte.

(Marcus Börger)

23 years ago
Hello Cristiano, Friday, June 20, 2003, 9:03:33 PM, you wrote: CD> Ok, final methods and attributes are cool, but what about final classes ? CD> Is it hard to implement ? Or all classes must be able to be extended by CD> children ? It would be easy to implement and i made a running patch some time back. But we were uncertain about the result, whether or not it is really helpfull and needed in a loose typed language as PHP. But if you come up with a very good scenario were final classes are really needed chances are good they make it into PHP 5, if not chances are not so good.
-- Best regards, Marcus mailto:helly@php.net

Alan Knowles

23 years ago
As far as I could see you only have final for methods, and not attributes. http://ny1.php.net/talks/show.php/php5intro/19 Regards Alan Marcus Börger wrote:

Cristiano Duarte

23 years ago
You´re right, sorry about the final attributes. I´m developing an IDL2PHP5 mapping specification and a compiler. To be full CORBA 2.3 aligned, I´m using Java IDL mapping specification as a base for the PHP IDL specification. CORBA Enums can be mapped as constants (like Universe extension) or classes (like Java specification). Since PHP5 offers type hinting, type safe will be done at engine level with classes. So the mapping would be something like this: // generated PHP final class <enum_name> implements org__omg__CORBA__portable__IDLEntity { // one pair for each label in the enum const mapping = array ( "<label>"=><value>, ... "<label>"=><value>); // one static declaration for each label in the enum static public $<label> = null; private $value; static public function initialize() { foreach (<enum_name>::mapping as $name=>$value) { eval("<enum_name>::\$$name = new <enum_name>(\$value);"); } } private function __construct($value) { $this->value = $value; } // get the enum value public function value() { return $this->value; } // get enum with specified value static public function from_int($value) {...} static public function readResolve() {...} } <enum_name>::initialize(); The org__omg__CORBA__* stuff is needed because namespaces are now R.I.P. and my first implementation was done with namespaces (god damn! I had to write all the specification again!). In fact, the "static public $<label> = null;" should be "const public $<label> = new Car(<value>);" but PHP5 doesn't support constant objects, so I need a mapping array and I have to initialize the static attributes at "<enum_name>::initialize();". :-( This implementation is not safe because the static objects can be modified (They should be constants or read-only). The class should be final since it must not be extended by children, assuring that its behaviour would not be modified. This is necessary since this class is in fact a list of predefined constants (in the IDL agreement) and if it gets modified at runtime this could lead to undesired results. Cristiano Duarte. "Alan Knowles" <alan@akbkhome.com> escreveu na mensagem news:3EF3A72E.8040906@akbkhome.com...

Cristiano Duarte

23 years ago
Hi Timm, My project for the Specialization Degree in Computer Network Design and Application includes the specification, the compiler and the library too. But I'm afraid I will not have enough time to develop all the library. In fact, I haven´t started it yet. I´m still working on the specification and the compiler. I will share some of my ideas about the library(rpc extension): -Use RPC/COM as a start point -Use MICO(www.mico.org) ORB -All low-level operations will be left to MICO ORB -A generic CORBA client connection method thru DII. Something like: $obj = new Corba("corbaname::nameservice:2000/NameService#MyComponent"); -A generic CORBA server connection method thru DSI. Something like: $obj = new ServerExample(); // PHP Object $ref = new Corba($obj); // CORBA Object -Since PHP is loosely typed, the serialization and deserialization processes is heavy. One PHP type can be mapped to many IDL types, so the IDL type needs to be known at runtime since the ORB is strict typed. The IDL to PHP type conversion is not that hard. -The code generated by the compiler will use the extension as a gateway between PHP and the MICO ORB. It will call some CORBA objects in the extension to do some low-level operations (like Request object). Any comments ? Cristiano Duarte. ----- Original Message ----- From: "Timm Friebe" <thekid@thekid.de> To: "Cristiano Duarte" <cunha17@uol.com.br> Sent: Saturday, June 21, 2003 10:33 AM Subject: Re: [PHP-DEV] about final methods and attributes On Sat, 2003-06-21 at 15:21, Cristiano Duarte wrote:
> You´re right, sorry about the final attributes. I´m developing an IDL2PHP5 > mapping specification and a compiler. To be full CORBA 2.3 aligned, I´m > using Java IDL mapping specification as a base for the PHP IDL > specification.
Just out of curiousity: Are you simply developing an IDL2PHP "compiler" or are you creating a PHP Corba library, too? I was thinking about writing one myself (ext/satellite is dead AFAIK), but if you're already doing that, there's no point:) - Timm

(Marcus Börger)

23 years ago
Hello Cristiano, Saturday, June 21, 2003, 2:07:09 AM, you wrote: MB> Hello Cristiano, MB> Friday, June 20, 2003, 9:03:33 PM, you wrote: CD>> Ok, final methods and attributes are cool, but what about final classes ? CD>> Is it hard to implement ? Or all classes must be able to be extended by CD>> children ? MB> It would be easy to implement and i made a running patch some time back. But MB> we were uncertain about the result, whether or not it is really helpfull and MB> needed in a loose typed language as PHP. But if you come up with a very good MB> scenario were final classes are really needed chances are good they make it MB> into PHP 5, if not chances are not so good. Attached is a patch that allows final classes.
-- Best regards, Marcus mailto:helly@php.net

Cristiano Duarte

23 years ago
Thanx Marcus, it works great ! Cristiano Duarte "Marcus BöRger" <marcus.boerger@t-online.de> escreveu na mensagem news:173915641.20030621210803@post.rwth-aachen.de...
> Hello Cristiano, > > Saturday, June 21, 2003, 2:07:09 AM, you wrote: > > MB> Hello Cristiano, > > MB> Friday, June 20, 2003, 9:03:33 PM, you wrote: > > CD>> Ok, final methods and attributes are cool, but what about final
classes ?
> CD>> Is it hard to implement ? Or all classes must be able to be extended
by
> CD>> children ? > > MB> It would be easy to implement and i made a running patch some time
back. But
> MB> we were uncertain about the result, whether or not it is really
helpfull and
> MB> needed in a loose typed language as PHP. But if you come up with a
very good
> MB> scenario were final classes are really needed chances are good they
make it

Andi Gutmans

23 years ago
To be quite honest, I don't see a need for final classes. Talking from my experience, classes which are designed to be final, often end up being inherited from at some point or another. This happened to me quite often in C++ when taking other people's/company's code and required fixing their source code. However, if you guys think it will help you I don't really mind adding it. At least for consistency sake even though I think it's useless :) So as far as I'm concerned you can go ahead and commit it. But I still think it's better not to use it in the long run :P Andi At 09:08 PM 6/21/2003 +0200, Marcus Börger wrote:

Cristiano Duarte

23 years ago
Thanx Andi, it would help me with the consistency of the CORBA mapping. Cristiano Duarte "Andi Gutmans" <andi@zend.com> escreveu na mensagem news:5.1.0.14.2.20030622001741.02ba0180@127.0.0.1... To be quite honest, I don't see a need for final classes. Talking from my experience, classes which are designed to be final, often end up being inherited from at some point or another. This happened to me quite often in C++ when taking other people's/company's code and required fixing their source code. However, if you guys think it will help you I don't really mind adding it. At least for consistency sake even though I think it's useless :) So as far as I'm concerned you can go ahead and commit it. But I still think it's better not to use it in the long run :P Andi At 09:08 PM 6/21/2003 +0200, Marcus Börger wrote:
>Hello Cristiano, > >Saturday, June 21, 2003, 2:07:09 AM, you wrote: > >MB> Hello Cristiano, > >MB> Friday, June 20, 2003, 9:03:33 PM, you wrote: > >CD>> Ok, final methods and attributes are cool, but what about final
classes ?
>CD>> Is it hard to implement ? Or all classes must be able to be extended
by

Sebastian Bergmann

23 years ago
Andi Gutmans wrote:
> At least for consistency sake even though I think it's useless :)
Consistency is the key issue here, IMHO. A typical use case for final classes and PHP might be, at some point, that a software vendor distributed his PHP application in encoded bytecode format and wants to ensure that (security) critical classes cannot change their behaviour through overriding, etc.
-- Sebastian Bergmann http://sebastian-bergmann.de/ http://phpOpenTracker.de/ http://www.professionelle-softwareentwicklung-mit-php5.de/

Andi Gutmans

23 years ago
At 11:27 AM 6/22/2003 +0200, Sebastian Bergmann wrote:
>Andi Gutmans wrote: > > At least for consistency sake even though I think it's useless :) > > Consistency is the key issue here, IMHO. > > A typical use case for final classes and PHP might be, at some point, > that a software vendor distributed his PHP application in encoded > bytecode format and wants to ensure that (security) critical classes > cannot change their behaviour through overriding, etc.
Yeah but you can just create a remove_final($class_name) function :) Anyway, I think the real reason for final is that it allows the Java compiler to do good optimizations (i.e. get rid of virtual calls in many cases). Andi