ID:          42536
 Updated by:  [EMAIL PROTECTED]
 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

Reply via email to