From: Operating system: independent PHP version: 5.4.0 Package: SPL related Bug Type: Feature/Change Request Bug description:need a function class_rename
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. -- Edit bug report at https://bugs.php.net/bug.php?id=61382&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=61382&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=61382&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=61382&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=61382&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=61382&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=61382&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=61382&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=61382&r=needscript Try newer version: https://bugs.php.net/fix.php?id=61382&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=61382&r=support Expected behavior: https://bugs.php.net/fix.php?id=61382&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=61382&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=61382&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=61382&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=61382&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=61382&r=dst IIS Stability: https://bugs.php.net/fix.php?id=61382&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=61382&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=61382&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=61382&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=61382&r=mysqlcfg