Re: parent_ctor()

From: Date: Tue, 18 Jul 2000 18:26:57 +0000
Subject: Re: parent_ctor()
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-25006@lists.php.net to get a copy of this message
KK>> change the class of an object as a standard method. It is needed KK>> in few, very special circumstances. No, there are no such circumstances. KK>> this is valid C++ because B is a subclass of A. But as a is of KK>> type (A *), I can only use instance variables and methods of A KK>> on a, despite the fact that a is actually a B (which happens to KK>> be an A as well). This is, because C++ tries to determine the KK>> validity of all method calls at compile time and not at run-time KK>> and so it cannot look at the object in question and determine KK>> its real capabilities. No, that's because C++ has no objects. It has typed pointers to memory areas. It tries to guess what object sits in that memory area by checking type of the pointer. You can easily fool it by giving pointer of different type. PHP, however, _has_ objects. KK>> Because of this, you will see much less casts and dynamic casts KK>> (downcasts? the <>-thingie in C++) in dynamically typed KK>> languages. The objects just know what they are and you do not Much less. Zero of them. You don't need typecasts in runtime-bound environment. Typecasts are to fool compiler, and to allow to assign pointer of one type to pointer of another type. KK>> In dynamically types languages it can be useful to look at KK>> objects from a different, more "democratic" angle: It is not KK>> important who your parents were, but what you can do, that is, KK>> which instance variables and methods you implement. That is, I KK>> do not really care what the class of an object is as long as the KK>> methods I want to call are present. Very american. This is very nice idea, COM and CORBA work on that. Only problem that it has no slightest relation to PHP. Interface contracts are great, but PHP doesn't work this way. Deal. PHP is no good language to implement ORB. You better use C++ or Java. -- Stanislav Malyshev stas@zend.com +972-3-6139665

« previous php.dev (#25006) next »