|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-09-03 23:49 UTC] johannes@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 20:00:01 2025 UTC |
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