php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #42536 Dynamic and multiple object inheritance (and no, this isn't heresy)
Submitted: 2007-09-03 23:33 UTC Modified: 2007-09-03 23:49 UTC
Votes:8
Avg. Score:5.0 ± 0.0
Reproduced:8 of 8 (100.0%)
Same Version:6 (75.0%)
Same OS:6 (75.0%)
From: kenaniah at gmail dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.4 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kenaniah at gmail dot com
New email:
PHP Version: OS:

 

 [2007-09-03 23:33 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-03 23:49 UTC] johannes@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 17:01:30 2024 UTC