|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2012-03-14 06:40 UTC] todesw1nd at hotmail dot com
[2012-03-14 15:29 UTC] anon at anon dot anon
[2012-03-14 17:49 UTC] todesw1nd at hotmail dot com
[2012-03-15 11:01 UTC] todesw1nd at hotmail dot com
-Status: Open
+Status: Closed
[2012-03-15 11:01 UTC] todesw1nd at hotmail dot com
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 20:00:01 2025 UTC |
Description: ------------ this is OOP related and maybe targets to AOP. Since i found a quick & dirty solution for myself using eval() in my framework it is not urgent, but would be nice to have to no longer need it as it is not used on any other parts currently. The problem itself: Lets say we have two cars and don't care about which one we drive, we just want to use one of it and a friend should decide which one by selecting it. In PHP i now have to use a wrapper class for each of the two cars with the same name, e.g. Wrapper_Car and a base class that is extended with their functionality, e.g. Base_Car. I do have a mess now as different cars can't have the same file name due to the default autoloader. Test script: --------------- file base_car.php: abstract class Base_Car { abstract public function drive(); } file wrapper_car1.php: class Wrapper_Car { public function drive { // Lets drive it ^^ } } file wrapper_car2.php: same content as wrapper_car1.php but slightly other implementation inside the methods of the class Expected result: ---------------- I would like to have a function like this: class_rename($class_name, $class_newname); So i can autoload the car class i want to use, e.g. wrapper_car1.php and have the class called Wrapper_Car1 and then rename it to Wrapper_Car as it is the selected car i want to drive with. Important: It would be ok if the autoloader tries to load the first param $class_name if it does not exist, but it should never ever do it for the second parameter as e.g. class_alias does it currently and is therefore useless for this case. Actual result: -------------- As said before i currently use a one liner eval that sets the namespaces and creates the renamed class based on the earlier loaded one to emulate this behavior and i think that is little dirty :] Thanks for reading this and it would be awesome to have such a functionality in a later PHP version. If you see it from another point of view it would be nice to see why.