#42536 [Opn->Bgs]: Dynamic and multiple object inheritance (and no, this isn't heresy)

From: Date: Mon, 03 Sep 2007 23:49:03 +0000
Subject: #42536 [Opn->Bgs]: Dynamic and multiple object inheritance (and no, this isn't heresy)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-117068@lists.php.net to get a copy of this message
ID: 42536 Updated by: johannes@php.net Reported By: kenaniah at gmail dot com -Status: Open +Status: Bogus Bug Type: Feature/Change Request PHP Version: 5.2.4 New Comment: An object either is of a given kind or not, it won't change it's type, if you want to build broken software design use runkit/classkit but PHP won't support such stuff natively. Previous Comments: ------------------------------------------------------------------------ [2007-09-03 23:33:28] kenaniah at gmail dot com Description: ------------ To implement this would require a definite change in the way PHP handles objects, but it would be an excellent addition to the language if we were able to modify the inheritances of an object after its initialization. For example: In an MVC framework, an object named 'User' is manipulated in the Model, and needs to be saved to the database. Instead of extending 'User' from an Active Record Database Object class, one could extend the instantiated 'User' object to include the Active Record Class, perform the database queries, and then "disinherit" the class before passing control on to the View, eliminating the ability to make use of the Active Record class' features from within the View. Proposed functions: extend ( object $object, string $class ) -- dynamically extends $object from $class unextend ( object $object, string $class ) -- removes $class from object (no longer a parent to $object) adopt ( object $object, string $class ) -- $class is added to $object as an extension unadopt ( object $object, string $class ) -- removes $class from $object (no longer a child within $object) Reproduce code: --------------- class User{ ... } class ActiveRecord{ ... } $user = new User; $user->name = "New Name"; extend($user, "ActiveRecord"); //$user is now extended from ActiveRecord $user->save(); //a function from ActiveRecord class unextend($user, "ActiveRecord"); //ActiveRecord is completely removed from $user ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42536&edit=1

« previous php.bugs (#117068) next »