Req #53957 [NEW]: Unloading Extentions OR Overriding Native Functions OR Importing Functions

From: Date: Tue, 08 Feb 2011 10:27:17 +0000
Subject: Req #53957 [NEW]: Unloading Extentions OR Overriding Native Functions OR Importing Functions
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-158583@lists.php.net to get a copy of this message
From: Operating system: Irrelevant PHP version: 5.3.5 Package: Scripting Engine problem Bug Type: Feature/Change Request Bug description:Unloading Extentions OR Overriding Native Functions OR Importing Functions Description: ------------ I'm building a framework which has a custom gettext implementation since the gettext extension of PHP is poorly designed for my needs and it's not installed in all environments so relying on it reduces compatibility. The problem however is that it's installed in some environments and since it claims the global "_" function which is pretty much a gettext standard alias (and other gettext functions), it's preventing me from implementing the gettext standard. There are no possible way for me to solve this problem nicely today because PHP does not have the ability to either: A. Override/undeclare/rename native functions. (Okay, I can do it via APD but that makes extension dependability even WORSE.) B. Unloading extensions at runtime. (Most preferable... I don't want it at all) C. Importing functions. (My framework uses namespaces. The fact that functions cannot be imported by the "use" keyword really spoils this feature. Otherwise it could actually have fix this problem.) Note that this problem assumes a context where you can't control the environment in which you install your application in. This is a very real scenario for a lot of people including me. This is a practical problem, not a theoretical one. Also note that declaring the "_" function in a namespace would be pointless: 1. it would no longer be compatible with the gettext standard 2. it would require refactoring of all existing string wrapped code 3. it would no longer be compatible with existing string wrapped code 4. a longer name like \foo\translate_lib\_() defeats the point of having a short function name Another workaround is to declare a _ forwarding function in every possible namespace, but that solution is dumb and ugly. As a temporary workaround I might declare something like t\s() but I don't like that solution and it doesn't solve 1, 2 and 3 above. Test script: --------------- /** EITHER A: */ undeclare_function("_"); /** OR B: */ unload_extension("gettext"); /** OR C: */ namespace foo; use foo\translate_lib; /** Test: */ // My gettext implementation. function _($msgid) { return translate($msgid); } echo _("hello"); Expected result: ---------------- bonjour Actual result: -------------- Fatal error: Cannot redeclare _() -- Edit bug report at http://bugs.php.net/bug.php?id=53957&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53957&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53957&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53957&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=53957&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53957&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=53957&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=53957&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=53957&r=needscript Try newer version: http://bugs.php.net/fix.php?id=53957&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=53957&r=support Expected behavior: http://bugs.php.net/fix.php?id=53957&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=53957&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=53957&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=53957&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53957&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=53957&r=dst IIS Stability: http://bugs.php.net/fix.php?id=53957&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=53957&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=53957&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=53957&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=53957&r=mysqlcfg

« previous php.bugs (#158583) next »