Re: [PHP-DEV] Multiple class inheritance
Whether it's implemented or not, I'm going to write a patch for multiple class inheritance. Does anyone here whos knows about the Zend Engine willing to help me out just a little bit, to get me started? I'm stuck at the syntax interpretation right now. On Mon, 2007-11-19 at 02:07 -0500, Edward Z. Yang wrote: Larry Garfield wrote: $myfield = new InputField(new DBField(new AbstractField(...))); [snip] Nah, what you're talking about now is a chain of responsibility, where events are in the form of method calls. :-) -- Edward Z. YangGnuPG: 0x869C48DA HTML Purifier http://htmlpurifier.org Anti-XSS Filter [[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Multiple class inheritance
Sam Barrow schrieb: What is the general opinion on multiple class inheritance. It is a concept that only works correctly in CLOS? -- Sebastian Bergmann http://sebastian-bergmann.de/ GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Multiple class inheritance
I doubt it will be implemented, but for my application it would be incredibly helpful and worth it to me to write a patch even if I am the only one to use it. On Mon, 2007-11-19 at 17:53 -0300, Cristian Rodriguez wrote: 2007/11/19, Sam Barrow [EMAIL PROTECTED]: Whether it's implemented or not, I'm going to write a patch for multiple class inheritance. I have the feeling that you are trying to use the wrong language. Hopefully people on this lists still preserves their sanity and will not be wiliing to implement a concept that is know to work correclty only in very few implementations, if any, that causes ambiguity and opens the door for all sorts of unneeded complexity. -- http://www.kissofjudas.net/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Multiple class inheritance
It would probably better to implement something like prototyping, where there is only 1 parent, but there can be muliple prototype classes from which methods are inherited. On Nov 19, 2007, at 10:49 PM, Sam Barrow [EMAIL PROTECTED] wrote: I doubt it will be implemented, but for my application it would be incredibly helpful and worth it to me to write a patch even if I am the only one to use it. On Mon, 2007-11-19 at 17:53 -0300, Cristian Rodriguez wrote: 2007/11/19, Sam Barrow [EMAIL PROTECTED]: Whether it's implemented or not, I'm going to write a patch for multiple class inheritance. I have the feeling that you are trying to use the wrong language. Hopefully people on this lists still preserves their sanity and will not be wiliing to implement a concept that is know to work correclty only in very few implementations, if any, that causes ambiguity and opens the door for all sorts of unneeded complexity. -- http://www.kissofjudas.net/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Multiple class inheritance
That would serve my purpose, as long as i can inherit methods and properties from multiple parents. On Mon, 2007-11-19 at 23:09 +0100, Arnold Daniels wrote: It would probably better to implement something like prototyping, where there is only 1 parent, but there can be muliple prototype classes from which methods are inherited. On Nov 19, 2007, at 10:49 PM, Sam Barrow [EMAIL PROTECTED] wrote: I doubt it will be implemented, but for my application it would be incredibly helpful and worth it to me to write a patch even if I am the only one to use it. On Mon, 2007-11-19 at 17:53 -0300, Cristian Rodriguez wrote: 2007/11/19, Sam Barrow [EMAIL PROTECTED]: Whether it's implemented or not, I'm going to write a patch for multiple class inheritance. I have the feeling that you are trying to use the wrong language. Hopefully people on this lists still preserves their sanity and will not be wiliing to implement a concept that is know to work correclty only in very few implementations, if any, that causes ambiguity and opens the door for all sorts of unneeded complexity. -- http://www.kissofjudas.net/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Multiple class inheritance
That would serve my purpose, as long as i can inherit methods and properties from multiple parents. Sorry if it is off to this list. Sam maybe you should check some PHP mixins implementation: http://www.symfony-project.org/book/1_0/17-Extending-Symfony#Mixins http://www.achievo.org/blog/archives/46-Mixins-in-PHP.html Best Regards, Felhő -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DEV] Multiple class inheritance
What is the general opinion on multiple class inheritance. I have a need for it. I have objects for all user input fields. $username = new field ; $username - name = 'username' ; $username - maxLen = 32 ; I have three types of fields. Fields that are automatically put in the database, such as timestamps, fields that are inputted but not stored, such as confirm password, and fields that are inputted by the user AND stored in the database, such as username and password. Now i have 3 classes: - abstractField (has methods and properties that apply to all fields). - inputField, extends abstractField (has methods and properties for display of input form elements and labels). - dbField, extends abstractField (has methods for storing and retrieving in db, etc.). However for fields that are inputted AND stored in the db, i need to extend both inputField and dbField. - inputDbField extends inputField, dbField. Sure, there may be quick hacks to do this, but the only proper way seems to be to extend both classes, and I don't want to duplicate any code (dbField and inputField are both pretty big, and any modifications will also have to be replicated). And no, I don't want to use interfaces. Interfaces will barely do anything for me, I'll still have to duplicate my method bodies, and properties. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Multiple class inheritance
It sounds like you want to be using decorators instead. http://en.wikipedia.org/wiki/Decorator_pattern On Sunday 18 November 2007, Sam Barrow wrote: What is the general opinion on multiple class inheritance. I have a need for it. I have objects for all user input fields. $username = new field ; $username - name = 'username' ; $username - maxLen = 32 ; I have three types of fields. Fields that are automatically put in the database, such as timestamps, fields that are inputted but not stored, such as confirm password, and fields that are inputted by the user AND stored in the database, such as username and password. Now i have 3 classes: - abstractField (has methods and properties that apply to all fields). - inputField, extends abstractField (has methods and properties for display of input form elements and labels). - dbField, extends abstractField (has methods for storing and retrieving in db, etc.). However for fields that are inputted AND stored in the db, i need to extend both inputField and dbField. - inputDbField extends inputField, dbField. Sure, there may be quick hacks to do this, but the only proper way seems to be to extend both classes, and I don't want to duplicate any code (dbField and inputField are both pretty big, and any modifications will also have to be replicated). And no, I don't want to use interfaces. Interfaces will barely do anything for me, I'll still have to duplicate my method bodies, and properties. -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it. -- Thomas Jefferson -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Multiple class inheritance
Larry Garfield wrote: It sounds like you want to be using decorators instead. The decorator pattern is inappropriate for this case, because Sam wants to extend the interface, not change the behavior of an existing one. -- Edward Z. YangGnuPG: 0x869C48DA HTML Purifier http://htmlpurifier.org Anti-XSS Filter [[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Multiple class inheritance
(Sorry, hit reply too soon.) Or, alternatively, you can mostly implement friend functions of a sort: http://www.garfieldtech.com/blog/php-magic-call but they have a performance penalty: http://www.garfieldtech.com/blog/magic-benchmarks On Sunday 18 November 2007, Sam Barrow wrote: What is the general opinion on multiple class inheritance. I have a need for it. I have objects for all user input fields. $username = new field ; $username - name = 'username' ; $username - maxLen = 32 ; I have three types of fields. Fields that are automatically put in the database, such as timestamps, fields that are inputted but not stored, such as confirm password, and fields that are inputted by the user AND stored in the database, such as username and password. Now i have 3 classes: - abstractField (has methods and properties that apply to all fields). - inputField, extends abstractField (has methods and properties for display of input form elements and labels). - dbField, extends abstractField (has methods for storing and retrieving in db, etc.). However for fields that are inputted AND stored in the db, i need to extend both inputField and dbField. - inputDbField extends inputField, dbField. Sure, there may be quick hacks to do this, but the only proper way seems to be to extend both classes, and I don't want to duplicate any code (dbField and inputField are both pretty big, and any modifications will also have to be replicated). And no, I don't want to use interfaces. Interfaces will barely do anything for me, I'll still have to duplicate my method bodies, and properties. -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it. -- Thomas Jefferson -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Multiple class inheritance
On Monday 19 November 2007, Edward Z. Yang wrote: Larry Garfield wrote: It sounds like you want to be using decorators instead. The decorator pattern is inappropriate for this case, because Sam wants to extend the interface, not change the behavior of an existing one. class AbstractField { // ... } class InputField { protected $field; function __construct($field) { $this-$field = $field; } function __call($method, $args) { return call_user_func_array(array($this-field, $method), $args); } // Other methods. } class DBField { protected $field; function __construct($field) { $this-$field = $field; } function __call($method, $args) { return call_user_func_array(array($this-field, $method), $args); } // Other methods. } $myfield = new InputField(new DBField(new AbstractField(...))); This is a case where you don't want type-hinting, actually. :-) You could do the same thing with an AbstractField interface that DBField and InputField also implement and pass through, which might be faster because you eliminate the _call()/call_user_func_array() choke point, but it's more code to write. Pick your poison. -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it. -- Thomas Jefferson -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Multiple class inheritance
Larry Garfield wrote: $myfield = new InputField(new DBField(new AbstractField(...))); [snip] Nah, what you're talking about now is a chain of responsibility, where events are in the form of method calls. :-) -- Edward Z. YangGnuPG: 0x869C48DA HTML Purifier http://htmlpurifier.org Anti-XSS Filter [[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php