I was looking at other languages that are loosely typed like PHP to see how they implemented their classes. A good example that is known by a lot of people is Javascript. Here are some things I gathered:
Class-based object-oriented languages, such as Java and C++, are founded on the concept of two distinct entities: classes and instances. A prototype-based language, such as JavaScript, does not make this distinction: it simply has objects. A prototype-based language has the notion of a prototypical object, an object used as a template from which to get the initial properties for a new object. Any object can specify its own properties, either when you create it or at run time. In addition, any object can be associated as the prototype for another object, allowing the second object to share the first object's properties. JavaScript implements inheritance by allowing you to associate a prototypical object with any constructor function. So, you can create exactly the Employee-Manager example, but you use slightly different terminology. First you define the Employee constructor function, specifying the name and dept properties. Next, you define the Manager constructor function, specifying the reports property. Finally, you assign a new Employee object as the prototype for the Manager constructor function. Then, when you create a new Manager, it inherits the name and dept properties from the Employee object. function Employee () { this.name = ""; this.dept = "general";} function Manager () { this.reports = [];}Manager.prototype = new Employee;function WorkerBee () { this.projects = [];}WorkerBee.prototype = new Employee; In JavaScript, at run time you can add or remove properties from any object. If you add a property to an object that is used as the prototype for a set of objects, the objects for which it is the prototype also get the new property. So I was wondering if we could use that type of stuff for php, not using functions to define "classes" though. I got the info from http://developer.netscape.com/docs/manuals/js/core/jsguide/obj2.htm#1008342 where it goes in more details. Fab. ----- Original Message ----- From: "Lauri Liinat" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Wednesday, April 10, 2002 6:15 PM Subject: Re: [PHP-DEV] Proposal for aggregation vs. MI > > i'll try to answer both Marcus and Wez here: > > > Where is the big difference (first is postfix syntax, second is prefix syntax). > > the difference is between whether you have to change *lots* of existing code > or do exactly *one* cast in new code while you write it: > > $timer = (Timer) $MI_obj; > > library_call_1 ($timer); > library_call_2 ($timer); > library_call_3 ($timer); > > etc... > > what i am proposing here is that the cast would "stick" when object > references are passed around or assigned to. the reference $var would > implicitly "remember" the class it has been cast up to. reasonable enough? > > > And as we have no typesystem we cannot use typecasting but another solution. > > no typesystem huh? we do have classes, right? so we do have a > typesystem, and just because a variable's type is hidden from the > programmer most of the time doesn't mean it isn't there. btw, PHP > already has the (new_type)$var cast syntax - you can do $var = (int)$var > for example. so we wouldn't really be adding a new construct, but rather > extending an existing one. > > so, Wez - why would you want to introduce yet another > cast operator - the "as" keyword? while PHP already has > adopted the C-style (new_type)... operator? > > lauri > > > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php